include cdist-type-emulator into path again

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-09-08 15:35:29 +02:00
parent d6db6d0c7e
commit 9ce26e5817
1 changed files with 21 additions and 0 deletions

View File

@ -34,6 +34,7 @@ CONF_DIR = os.path.join(BASE_DIR, "conf")
GLOBAL_EXPLORER_DIR = os.path.join(CONF_DIR, "explorer")
LIB_DIR = os.path.join(BASE_DIR, "lib")
MANIFEST_DIR = os.path.join(CONF_DIR, "manifest")
TYPE_DIR = os.path.join(CONF_DIR, "type")
REMOTE_BASE_DIR = "/var/lib/cdist"
REMOTE_CONF_DIR = os.path.join(REMOTE_BASE_DIR, "conf")
@ -64,6 +65,10 @@ VERSION = "2.0.0"
logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(message)s')
log = logging.getLogger()
# List types
def list_types():
return os.listdir(TYPE_DIR)
class Cdist:
"""Cdist main class to hold arbitrary data"""
@ -74,11 +79,18 @@ class Cdist:
# Setup directory paths
self.temp_dir = tempfile.mkdtemp()
self.out_dir = os.path.join(self.temp_dir, "out")
os.mkdir(self.out_dir)
self.global_explorer_out_dir = os.path.join(self.out_dir, "explorer")
os.mkdir(self.global_explorer_out_dir)
# Setup binary directory + contents
self.bin_dir = os.path.join(self.out_dir, "bin")
os.mkdir(self.bin_dir)
self.link_type_to_emulator()
# Mostly static, but can be overwritten on user demand
if initial_manifest:
self.initial_manifest = initial_manifest
@ -149,6 +161,14 @@ class Cdist:
def transfer_global_explorers(self):
self.transfer_dir(GLOBAL_EXPLORER_DIR, REMOTE_GLOBAL_EXPLORER_DIR)
def link_type_to_emulator(self):
"""Link type names to cdist-type-emulator"""
for type in list_types():
source = os.path.join(LIB_DIR, "cdist-type-emulator")
destination = os.path.join(self.bin_dir, type)
log.debug("Linking %s to %s", source, destination)
os.symlink(source, destination)
def global_explore(self):
"""Run global explorers"""
explorers = self.list_global_explorers()
@ -184,6 +204,7 @@ class Cdist:
log.info("Running the initial manifest")
env = os.environ.copy()
env['__target_host'] = self.target_host
env['PATH'] = self.bin_dir + ":" + env['PATH']
self.shell_run_or_debug_fail(self.initial_manifest,
[self.initial_manifest],