forked from ungleich-public/cdist
Compare commits
3 commits
master
...
random_dot
Author | SHA1 | Date | |
---|---|---|---|
|
8cf14ebfc5 | ||
|
ccc3c02466 | ||
|
49040c8044 |
6 changed files with 45 additions and 18 deletions
|
@ -41,7 +41,8 @@ BANNER = """
|
|||
"P' "" ""
|
||||
"""
|
||||
|
||||
DOT_CDIST = ".cdist"
|
||||
# File that contains the name of the object marker
|
||||
OBJECT_MARKER_NAME = '.object_marker'
|
||||
|
||||
REMOTE_COPY = "scp -o User=root -q"
|
||||
REMOTE_EXEC = "ssh -o User=root -q"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# 2010-2013 Nico Schottelius (nico-cdist at schottelius.org)
|
||||
# 2010-2015 Nico Schottelius (nico-cdist at schottelius.org)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
|
@ -161,8 +161,9 @@ 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):
|
||||
for cdist_object in core.CdistObject.list_objects(object_base_path=self.local.object_path,
|
||||
type_base_path=self.local.type_path,
|
||||
object_marker_name=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:
|
||||
|
|
|
@ -23,7 +23,7 @@ from cdist.core.cdist_type import CdistType
|
|||
from cdist.core.cdist_type import NoSuchTypeError
|
||||
from cdist.core.cdist_object import CdistObject
|
||||
from cdist.core.cdist_object import IllegalObjectIdError
|
||||
from cdist.core.cdist_object import OBJECT_MARKER
|
||||
#from cdist.core.cdist_object import OBJECT_MARKER
|
||||
from cdist.core.explorer import Explorer
|
||||
from cdist.core.manifest import Manifest
|
||||
from cdist.core.code import Code
|
||||
|
|
|
@ -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.
|
||||
|
@ -32,9 +32,6 @@ from cdist.util import fsproperty
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
OBJECT_MARKER = '.cdist'
|
||||
|
||||
|
||||
class IllegalObjectIdError(cdist.Error):
|
||||
def __init__(self, object_id, message=None):
|
||||
self.object_id = object_id
|
||||
|
@ -71,20 +68,39 @@ class CdistObject(object):
|
|||
self.base_path = base_path
|
||||
self.object_id = object_id
|
||||
|
||||
self._init_object_marker_name()
|
||||
|
||||
self.validate_object_id()
|
||||
self.sanitise_object_id()
|
||||
|
||||
self.name = self.join_name(self.cdist_type.name, self.object_id)
|
||||
self.path = os.path.join(self.cdist_type.path, self.object_id, OBJECT_MARKER)
|
||||
|
||||
self._init_paths()
|
||||
|
||||
def _init_object_marker_name(self):
|
||||
self.object_marker_path = os.path.join(self.base_path, cdist.OBJECT_MARKER_NAME)
|
||||
|
||||
with open(self.object_marker_path, 'r') as fd:
|
||||
object_marker_name = fd.readlines()
|
||||
self.object_marker_name = object_marker_name[0].rstrip()
|
||||
|
||||
|
||||
def _init_paths(self):
|
||||
|
||||
self.path = os.path.join(self.cdist_type.path, self.object_id, self.object_marker_name)
|
||||
|
||||
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_name):
|
||||
"""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_name):
|
||||
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)
|
||||
|
||||
|
@ -94,10 +110,10 @@ class CdistObject(object):
|
|||
return os.listdir(object_base_path)
|
||||
|
||||
@classmethod
|
||||
def list_object_names(cls, object_base_path):
|
||||
def list_object_names(cls, object_base_path, object_marker_name):
|
||||
"""Return a list of object names"""
|
||||
for path, dirs, files in os.walk(object_base_path):
|
||||
if OBJECT_MARKER in dirs:
|
||||
if object_marker_name in dirs:
|
||||
yield os.path.relpath(path, object_base_path)
|
||||
|
||||
@staticmethod
|
||||
|
@ -127,7 +143,7 @@ class CdistObject(object):
|
|||
"""Validate the given object_id and raise IllegalObjectIdError if it's not valid.
|
||||
"""
|
||||
if self.object_id:
|
||||
if OBJECT_MARKER in self.object_id.split(os.sep):
|
||||
if self.object_marker_name in self.object_id.split(os.sep):
|
||||
raise IllegalObjectIdError(self.object_id, 'object_id may not contain \'%s\'' % OBJECT_MARKER)
|
||||
if '//' in self.object_id:
|
||||
raise IllegalObjectIdError(self.object_id, 'object_id may not contain //')
|
||||
|
|
|
@ -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)
|
||||
#
|
||||
|
|
|
@ -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):
|
||||
# Does not need to be secure - just randomly different from .cdist
|
||||
self.object_marker_file = os.path.join(self.object_path, cdist.OBJECT_MARKER_NAME)
|
||||
|
||||
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):
|
||||
|
@ -133,6 +140,8 @@ class Local(object):
|
|||
self._create_messages()
|
||||
self._link_types_for_emulator()
|
||||
|
||||
with open(self.object_marker_file, 'w') as fd:
|
||||
fd.write("%s\n" % self.object_marker_name)
|
||||
|
||||
def _init_cache_dir(self, cache_dir):
|
||||
if cache_dir:
|
||||
|
|
Loading…
Reference in a new issue