2011-10-12 15:20:47 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
|
2012-11-06 20:32:37 +00:00
|
|
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
2011-10-12 15:20:47 +00:00
|
|
|
#
|
|
|
|
# This file is part of cdist.
|
|
|
|
#
|
|
|
|
# cdist is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# cdist is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
import cdist
|
|
|
|
|
|
|
|
'''
|
|
|
|
common:
|
|
|
|
runs only locally, does not need remote
|
|
|
|
|
|
|
|
env:
|
|
|
|
PATH: prepend directory with type emulator symlinks == local.bin_path
|
|
|
|
__target_host: the target host we are working on
|
|
|
|
__global: full qualified path to the global output dir == local.out_path
|
|
|
|
__cdist_manifest: full qualified path of the manifest == script
|
|
|
|
__cdist_type_base_path: full qualified path to the directory where types are defined for use in type emulator
|
2011-10-12 22:35:14 +00:00
|
|
|
== local.type_path
|
2011-10-12 15:20:47 +00:00
|
|
|
|
|
|
|
initial manifest is:
|
|
|
|
script: full qualified path to the initial manifest
|
|
|
|
|
|
|
|
env:
|
|
|
|
__manifest: path to .../conf/manifest/ == local.manifest_path
|
|
|
|
|
|
|
|
creates: new objects through type emulator
|
|
|
|
|
|
|
|
type manifeste is:
|
|
|
|
script: full qualified path to the type manifest
|
|
|
|
|
|
|
|
env:
|
|
|
|
__object: full qualified path to the object's dir
|
|
|
|
__object_id: the objects id
|
|
|
|
__object_fq: full qualified object id, iow: $type.name + / + object_id
|
|
|
|
__type: full qualified path to the type's dir
|
|
|
|
|
|
|
|
creates: new objects through type emulator
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
class Manifest(object):
|
2011-10-13 09:05:39 +00:00
|
|
|
"""Executes cdist manifests.
|
2011-10-12 15:20:47 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
def __init__(self, target_host, local):
|
|
|
|
self.target_host = target_host
|
|
|
|
self.local = local
|
2011-10-18 11:32:36 +00:00
|
|
|
|
2011-10-14 23:38:22 +00:00
|
|
|
self.log = logging.getLogger(self.target_host)
|
|
|
|
|
2011-10-12 15:20:47 +00:00
|
|
|
self.env = {
|
|
|
|
'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']),
|
|
|
|
'__target_host': self.target_host,
|
|
|
|
'__global': self.local.out_path,
|
2011-10-12 22:35:14 +00:00
|
|
|
'__cdist_type_base_path': self.local.type_path, # for use in type emulator
|
2011-10-12 15:20:47 +00:00
|
|
|
}
|
2011-10-14 23:38:22 +00:00
|
|
|
if self.log.getEffectiveLevel() == logging.DEBUG:
|
2011-10-19 13:03:47 +00:00
|
|
|
self.env.update({'__cdist_debug': "yes" })
|
2011-10-14 21:21:22 +00:00
|
|
|
|
2011-10-12 15:20:47 +00:00
|
|
|
|
|
|
|
def run_initial_manifest(self, script):
|
|
|
|
env = os.environ.copy()
|
|
|
|
env.update(self.env)
|
|
|
|
env['__manifest'] = self.local.manifest_path
|
2011-10-13 14:41:54 +00:00
|
|
|
env['__cdist_manifest'] = script
|
2011-10-14 23:38:22 +00:00
|
|
|
self.log.info("Running initial manifest " + self.local.manifest_path)
|
2012-11-06 20:32:37 +00:00
|
|
|
|
|
|
|
if not os.path.isfile(self.local.manifest_path):
|
2012-11-06 20:46:02 +00:00
|
|
|
raise cdist.Error("Initial manifest is missing")
|
2012-11-06 20:32:37 +00:00
|
|
|
|
2011-10-14 14:14:39 +00:00
|
|
|
self.local.run_script(script, env=env)
|
2011-10-12 15:20:47 +00:00
|
|
|
|
|
|
|
def run_type_manifest(self, cdist_object):
|
2012-02-13 07:55:42 +00:00
|
|
|
script = os.path.join(self.local.type_path, cdist_object.cdist_type.manifest_path)
|
2011-10-13 14:53:07 +00:00
|
|
|
if os.path.isfile(script):
|
|
|
|
env = os.environ.copy()
|
|
|
|
env.update(self.env)
|
|
|
|
env.update({
|
2012-04-04 15:21:54 +00:00
|
|
|
'__manifest': self.local.manifest_path,
|
2011-10-13 14:53:07 +00:00
|
|
|
'__object': cdist_object.absolute_path,
|
|
|
|
'__object_id': cdist_object.object_id,
|
2011-10-19 13:17:45 +00:00
|
|
|
'__object_name': cdist_object.name,
|
2012-02-13 07:55:42 +00:00
|
|
|
'__type': cdist_object.cdist_type.absolute_path,
|
2011-10-13 14:53:07 +00:00
|
|
|
'__cdist_manifest': script,
|
|
|
|
})
|
2011-10-14 14:14:39 +00:00
|
|
|
self.local.run_script(script, env=env)
|