Merge remote branch 'remotes/upstream/master'

This commit is contained in:
Jake Guffey 2012-06-14 10:47:15 -04:00
commit c1ca8f4932
6 changed files with 67 additions and 9 deletions

View file

@ -4,11 +4,12 @@ Changelog
* Changes are always commented with their author in (braces) * Changes are always commented with their author in (braces)
* Exception: No braces means author == Nico Schottelius * Exception: No braces means author == Nico Schottelius
2.0.13: 2.0.13: 2012-06-05
* Bugfix __ssh_authorized_key: Ensure it sets proper group (contradict) * Bugfix __ssh_authorized_key: Ensure it sets proper group (contradict)
* Bugfix __addifnosuchline: Fixed quotes/interpolation bug ("a b" became "a b") * Bugfix __addifnosuchline: Fixed quotes/interpolation bug ("a b" became "a b")
* New Explorer: interfaces (Sébastien Gross) * New Explorer: interfaces (Sébastien Gross)
* Feature core: Support reading from stdin in types (Steven Armstrong) * Feature core: Support reading from stdin in types (Steven Armstrong)
* Feature core: Support multiple parameters for types (Steven Armstrong)
* Feature __file: Support reading from stdin with - syntax (Steven Armstrong) * Feature __file: Support reading from stdin with - syntax (Steven Armstrong)
2.0.12: 2012-05-29 2.0.12: 2012-05-29

View file

@ -74,14 +74,19 @@ DEFINING PARAMETERS
------------------- -------------------
Every type consists of required, optional and boolean parameters, which must Every type consists of required, optional and boolean parameters, which must
be created in a newline seperated file in ***parameter/required***, be created in a newline seperated file in ***parameter/required***,
***parameter/optional*** and ***parameter/boolean***. If either is missing, ***parameter/required_multiple***, ***parameter/optional***,
the type will have no required, no optional, no boolean or no parameters at ***parameter/optional_multiple*** and ***parameter/boolean***.
all. Parameters which are allowed multiple times should be listed in
required_multiple or optional_multiple respectively. For all other parameters
the standard unix behaviour of the last given wins is applied.
If either is missing, the type will have no required, no optional, no boolean
or no parameters at all.
Example: Example:
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
echo servername >> conf/type/__nginx_vhost/parameter/required echo servername >> conf/type/__nginx_vhost/parameter/required
echo logdirectory >> conf/type/__nginx_vhost/parameter/optional echo logdirectory >> conf/type/__nginx_vhost/parameter/optional
echo server_alias >> conf/type/__nginx_vhost/parameter/optional_multiple
echo use_ssl >> conf/type/__nginx_vhost/parameter/boolean echo use_ssl >> conf/type/__nginx_vhost/parameter/boolean
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -108,6 +113,14 @@ if [ -f "$__object/parameter/use_ssl" ]; then
# file exists -> True # file exists -> True
# do some fancy ssl stuff # do some fancy ssl stuff
fi fi
# parameter with multiple values
if [ -f "$__object/parameter/server_alias" ]; then
for alias in $(cat "$__object/parameter/server_alias"); do
echo $alias > /some/where/usefull
done
fi
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View file

@ -29,7 +29,7 @@ try:
'cd "%s" && git describe' % here, 'cd "%s" && git describe' % here,
stderr=devnull, shell=True).decode('utf-8') stderr=devnull, shell=True).decode('utf-8')
except: except:
VERSION = "2.0.12" VERSION = "2.0.13"
BANNER = """ BANNER = """
.. . .x+=:. s .. . .x+=:. s

View file

@ -81,7 +81,9 @@ class CdistType(object):
self.__explorers = None self.__explorers = None
self.__required_parameters = None self.__required_parameters = None
self.__required_multiple_parameters = None
self.__optional_parameters = None self.__optional_parameters = None
self.__optional_multiple_parameters = None
self.__boolean_parameters = None self.__boolean_parameters = None
def __repr__(self): def __repr__(self):
@ -130,6 +132,22 @@ class CdistType(object):
self.__required_parameters = parameters self.__required_parameters = parameters
return self.__required_parameters return self.__required_parameters
@property
def required_multiple_parameters(self):
"""Return a list of required multiple parameters"""
if not self.__required_multiple_parameters:
parameters = []
try:
with open(os.path.join(self.absolute_path, "parameter", "required_multiple")) as fd:
for line in fd:
parameters.append(line.strip())
except EnvironmentError:
# error ignored
pass
finally:
self.__required_multiple_parameters = parameters
return self.__required_multiple_parameters
@property @property
def optional_parameters(self): def optional_parameters(self):
"""Return a list of optional parameters""" """Return a list of optional parameters"""
@ -146,6 +164,22 @@ class CdistType(object):
self.__optional_parameters = parameters self.__optional_parameters = parameters
return self.__optional_parameters return self.__optional_parameters
@property
def optional_multiple_parameters(self):
"""Return a list of optional multiple parameters"""
if not self.__optional_multiple_parameters:
parameters = []
try:
with open(os.path.join(self.absolute_path, "parameter", "optional_multiple")) as fd:
for line in fd:
parameters.append(line.strip())
except EnvironmentError:
# error ignored
pass
finally:
self.__optional_multiple_parameters = parameters
return self.__optional_multiple_parameters
@property @property
def boolean_parameters(self): def boolean_parameters(self):
"""Return a list of boolean parameters""" """Return a list of boolean parameters"""

View file

@ -92,12 +92,18 @@ class Emulator(object):
parser = argparse.ArgumentParser(add_help=False, argument_default=argparse.SUPPRESS) parser = argparse.ArgumentParser(add_help=False, argument_default=argparse.SUPPRESS)
for parameter in self.cdist_type.optional_parameters:
argument = "--" + parameter
parser.add_argument(argument, dest=parameter, action='store', required=False)
for parameter in self.cdist_type.required_parameters: for parameter in self.cdist_type.required_parameters:
argument = "--" + parameter argument = "--" + parameter
parser.add_argument(argument, dest=parameter, action='store', required=True) parser.add_argument(argument, dest=parameter, action='store', required=True)
for parameter in self.cdist_type.required_multiple_parameters:
argument = "--" + parameter
parser.add_argument(argument, dest=parameter, action='append', required=True)
for parameter in self.cdist_type.optional_parameters:
argument = "--" + parameter
parser.add_argument(argument, dest=parameter, action='store', required=False)
for parameter in self.cdist_type.optional_multiple_parameters:
argument = "--" + parameter
parser.add_argument(argument, dest=parameter, action='append', required=False)
for parameter in self.cdist_type.boolean_parameters: for parameter in self.cdist_type.boolean_parameters:
argument = "--" + parameter argument = "--" + parameter
parser.add_argument(argument, dest=parameter, action='store_const', const='') parser.add_argument(argument, dest=parameter, action='store_const', const='')

View file

@ -134,7 +134,11 @@ class DirectoryDict(collections.MutableMapping):
def __setitem__(self, key, value): def __setitem__(self, key, value):
try: try:
with open(os.path.join(self.path, key), "w") as fd: with open(os.path.join(self.path, key), "w") as fd:
fd.write(str(value)) if type(value) == type([]):
for v in value:
fd.write(str(v) + '\n')
else:
fd.write(str(value))
except EnvironmentError as e: except EnvironmentError as e:
raise cdist.Error(str(e)) raise cdist.Error(str(e))