Let core use random .cdist directory for objects

Signed-off-by: Nico Schottelius <nico@freiheit.schottelius.org>
This commit is contained in:
Nico Schottelius 2015-03-05 15:02:26 +01:00
parent ff00df72ad
commit 73c77dd2d3
8 changed files with 79 additions and 26 deletions

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# 2010-2012 Nico Schottelius (nico-cdist at schottelius.org)
# 2010-2015 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@ -41,8 +41,6 @@ BANNER = """
"P' "" ""
"""
DOT_CDIST = ".cdist"
REMOTE_COPY = "scp -o User=root -q"
REMOTE_EXEC = "ssh -o User=root -q"

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 2010-2014 Nico Schottelius (nico-cdist at schottelius.org)
# 2010-2015 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@ -162,7 +162,8 @@ class Config(object):
def object_list(self):
"""Short name for object list retrieval"""
for cdist_object in core.CdistObject.list_objects(self.local.object_path,
self.local.type_path):
self.local.type_path,
self.local.object_marker_name):
if cdist_object.cdist_type.is_install:
self.log.debug("Running in config mode, ignoring install object: {0}".format(cdist_object))
else:

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2014 Nico Schottelius (nico-cdist at schottelius.org)
# 2014-2015 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2011-2015 Nico Schottelius (nico-cdist at schottelius.org)
# 2014 Daniel Heule (hda at sfs.biz)
#
# This file is part of cdist.
@ -63,7 +63,7 @@ class CdistObject(object):
STATE_RUNNING = "running"
STATE_DONE = "done"
def __init__(self, cdist_type, base_path, object_marker=".cdist", object_id=''):
def __init__(self, cdist_type, base_path, object_marker, object_id):
self.cdist_type = cdist_type # instance of Type
self.base_path = base_path
self.object_id = object_id
@ -75,30 +75,34 @@ class CdistObject(object):
self.name = self.join_name(self.cdist_type.name, self.object_id)
self.path = os.path.join(self.cdist_type.path, self.object_id, self.object_marker)
self.absolute_path = os.path.join(self.base_path, self.path)
self.code_local_path = os.path.join(self.path, "code-local")
self.code_remote_path = os.path.join(self.path, "code-remote")
self.parameter_path = os.path.join(self.path, "parameter")
@classmethod
def list_objects(cls, object_base_path, type_base_path):
def list_objects(cls, object_base_path, type_base_path, object_marker):
"""Return a list of object instances"""
for object_name in cls.list_object_names(object_base_path):
for object_name in cls.list_object_names(object_base_path, object_marker):
type_name, object_id = cls.split_name(object_name)
yield cls(cdist.core.CdistType(type_base_path, type_name), object_base_path, object_id=object_id)
yield cls(cdist.core.CdistType(type_base_path, type_name),
base_path=object_base_path,
object_marker=object_marker,
object_id=object_id)
@classmethod
def list_object_names(cls, object_base_path, object_marker):
"""Return a list of object names"""
for path, dirs, files in os.walk(object_base_path):
if object_marker in dirs:
yield os.path.relpath(path, object_base_path)
@classmethod
def list_type_names(cls, object_base_path):
"""Return a list of type names"""
return os.listdir(object_base_path)
@classmethod
def list_object_names(cls, object_base_path):
"""Return a list of object names"""
for path, dirs, files in os.walk(object_base_path):
if self.object_marker in dirs:
yield os.path.relpath(path, object_base_path)
@staticmethod
def split_name(object_name):
"""split_name('__type_name/the/object_id') -> ('__type_name', 'the/object_id')

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2011-2015 Nico Schottelius (nico-cdist at schottelius.org)
# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
# 2014 Daniel Heule (hda at sfs.biz)
#
@ -64,9 +64,10 @@ class Emulator(object):
self.global_path = self.env['__global']
self.target_host = self.env['__target_host']
# Internally only
# Internal variables
self.object_source = self.env['__cdist_manifest']
self.type_base_path = self.env['__cdist_type_base_path']
self.object_marker = self.env['__cdist_object_marker']
except KeyError as e:
raise MissingRequiredEnvironmentVariableError(e.args[0])
@ -131,13 +132,16 @@ class Emulator(object):
self.log.debug('Args: %s' % self.args)
def setup_object(self):
# Setup object_id - FIXME: unset / do not setup anymore!
if not self.cdist_type.is_singleton:
# Setup object - and ensure it is not in args
if self.cdist_type.is_singleton:
self.object_id = False
else:
self.object_id = self.args.object_id[0]
del self.args.object_id
# Instantiate the cdist object we are defining
self.cdist_object = core.CdistObject(self.cdist_type, self.object_base_path, self.object_id)
self.cdist_object = core.CdistObject(self.cdist_type,
self.object_base_path, self.object_marker, self.object_id)
# Create object with given parameters
self.parameters = {}

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
# 2011-2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2011-2015 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
@ -66,9 +66,9 @@ class Local(object):
self._init_log()
self._init_permissions()
self._init_paths()
self._init_object_marker()
self._init_conf_dirs()
@property
def dist_conf_dir(self):
return os.path.abspath(os.path.join(os.path.dirname(cdist.__file__), "conf"))
@ -103,6 +103,12 @@ class Local(object):
self.type_path = os.path.join(self.conf_path, "type")
def _init_object_marker(self):
self.object_marker_file = os.path.join(self.base_path, "object_marker")
# Does not need to be secure - just randomly different from .cdist
self.object_marker_name = tempfile.mktemp(prefix='.cdist-', dir='')
def _init_conf_dirs(self):
self.conf_dirs = []
@ -125,6 +131,7 @@ class Local(object):
def _init_directories(self):
self.mkdir(self.conf_path)
self.mkdir(self.global_explorer_out_path)
self.mkdir(self.object_path)
self.mkdir(self.bin_path)
def create_files_dirs(self):
@ -132,6 +139,13 @@ class Local(object):
self._create_conf_path_and_link_conf_dirs()
self._create_messages()
self._link_types_for_emulator()
self._setup_object_marker_file()
def _setup_object_marker_file(self):
with open(self.object_marker_file, 'w') as fd:
fd.write("%s\n" % self.object_marker_name)
self.log.debug("Object marker %s saved in %s" % (self.object_marker_name, self.object_marker_file))
def _init_cache_dir(self, cache_dir):
@ -166,6 +180,9 @@ class Local(object):
# Export __target_host for use in __remote_{copy,exec} scripts
env['__target_host'] = self.target_host
# Export for emulator
env['__cdist_object_marker'] = self.object_marker_name
if message_prefix:
message = cdist.message.Message(message_prefix, self.messages_path)
env.update(message.env)

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# 2013 Nico Schottelius (nico-cdist at schottelius.org)
# 2013-2015 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#

View file

@ -0,0 +1,29 @@
- locate code that references .cdist
- cdist_object.py
- need to change code that handles objects?
- setup object marker
exec/local.py
- cdist/emulator.py
- need to know the marker name
- shell.py
- test/manifest/__init__.py
- core/code.py:
- core/manifest.py:
- core/manifest.py:
- list_object_names() needs to know the marker -- used BY:
- list_objects
- cdist/test/cdist_object/__init__.py
- cdist/config.py
- cdist/test/cdist_object/__init__.py
- list_object_names
- needs to have object_marker
- or modify object code to load name
- setup a per-run random name
- local.py
- use the per-run random name
- create test
def __init__(self, cdist_type, base_path, object_marker=".cdist", object_id=''):