shepherd.common package¶
Submodules¶
shepherd.common.exceptions module¶
-
exception
shepherd.common.exceptions.LoggingException(message, logger)[source]¶ Bases:
exceptions.Exception
shepherd.common.plugins module¶
Uses abstract base classes and IPlugin to create base plugin classes. Each defines a particular interface For example all resources should have a create, destroy and exists methods.
This combined with the PluginManager in shepherd.manager helps to creates a common method of building the modular architecture. Since, the built in resources, parsers, etc all use the same abstract classes, adding new features should be seemless.
-
class
shepherd.common.plugins.Action[source]¶ Bases:
yapsy.IPlugin.IPluginDefines an action to run.
- WARNING: Actions may be depricated as objects in future versions
- if yapsy is removed as the plugin manager.
-
class
shepherd.common.plugins.Parser[source]¶ Bases:
yapsy.IPlugin.IPluginDuring parsing of manifests Parsers can be used to handles any modifications to the params subdict before merging the params into the resources.
This could be used for dynamic variables like getting the latest volume snapshots, external resources, etc.
NOTE: multiple parsers can be run on the paramsdict, so ensure that they are independent of each other. For example you may want a parser for modifying each dynamic variable.
-
run(paramsdict, config=None)[source]¶ Takes a dict of the parameters and returns the modified version. It optionally takes a config which could contain default input values to use.
- Args:
- paramsdict (dict): the current params dict. config (Config, optional): the config object if the Parser would like to
-
-
class
shepherd.common.plugins.Resource(provider)[source]¶ Bases:
yapsy.IPlugin.IPluginDefines a simple interface for interacting with resource objects.
-
available¶
-
deserialize(data)[source]¶ Deserializes the keys and values in a dictionary into attributes for self.
- Notes:
- The mapping of keys to attributes is done using
self._attributes_map. - Args:
- data (dict): a dictionary of the attributes to deserialize.
-
get_dependencies()[source]¶ Generates a list of dependencies for the resource.
- Returns:
- list: of other resource names this resource depends on.
-
global_name¶
-
local_name¶
-
provider¶
-
serialize()[source]¶ Serializes the attributes to a dict using
self._attributes_map.- Returns:
- dict: the serialized dictionary of the attributes.
-
stack¶
-
type¶
-
-
class
shepherd.common.plugins.Storage[source]¶ Bases:
yapsy.IPlugin.IPluginDefines an API for storage plugins.
WARNING: Storage plugins should be thread safe. For example, if your storage plugin writes to a file make sure you’re locking and unlocking the file accordingly.
FEATURE: should probably support some kind of archiving approach for old and unused stacks.
-
dump(stack)[source]¶ Takes a stack dict and stores it in the datastore of your choice.
- Args:
- stack (Stack): dumps the stack into the storage media
-
shepherd.common.utils module¶
Provides various utility functions for shepherd ranging from validating configs to mapping object attributes to and from dictionaries.
-
shepherd.common.utils.configure_logging(verbosity, logformat='[%(levelname)s %(asctime)s %(name)s] - "%(message)s"')[source]¶ Sets up logging for the framework.
All default logging uses logging.basicConfig with the format string ‘[%(levelname)s %(asctime)s %(name)s] - “%(message)s”’
- Args:
- verbosity (int): a verbosity level between 0 and 5.
- No Logging Configured
- Root & shepherd logger = WARNING
- Root logger = WARNING; shepherd logger = INFO
- Root logger = WARNING; shepherd logger = DEBUG
- Root logger = INFO; shepherd logger = DEBUG
- Root logger = DEBUG; shepherd logger = DEBUG
logformat (str, optional): an alternative format string.
-
shepherd.common.utils.dict_contains(superdict, subdict)[source]¶ Returns a boolean as to whether the superdict contains the same key value pairs of the subdict.
- Args:
- superdict (dict): dict with superset of keys in subdict subdict (dict): dict with subset of keys from superdict
- Returns:
- result (bool):
-
shepherd.common.utils.get_logger(obj)[source]¶ Provides an alternative method of getting a useful logger name for an object because yapsy tends to mess up how __name__ works.
- Args:
- obj (object): the object to build a custom logger name for.
- Returns:
- logger (Logger) - where the name is the __module__.__name__ of type(obj).
-
shepherd.common.utils.getattrs(obj, attrmap)[source]¶ Handles extracting object attributes into a dict.
Parameters: attrmap – Returns: the result dict. - Args:
obj (object): the object to extract the attributes from. attrmap (dict): a dict mapping dict keys to attribute names, where the
keys match the keys of the resulting dict and the values match their corresponding attributes.- Returns:
- result (dict): dictionary of the mapped attributes from obj
-
shepherd.common.utils.pascal_to_underscore(pascal_str)[source]¶ Converts pascal format strings to underscore format.
- Args:
- pascal_str (TYPE): the pascal case string we want to convert to underscore format.
-
shepherd.common.utils.run(action_name, config, **kwargs)[source]¶ Searches for the action plugin to run. Searches both the default paths as well as
- Args:
- action_name (TYPE): the name of the action you want to run. config (TYPE): the config object used for creating or location a stack to work on. **kwargs: a dictionary of parameters to be passed to the task.
- Returns:
- the action output
-
shepherd.common.utils.setattrs(obj, attrmap, values)[source]¶ Handles setting object attributes from dict.
- Args:
obj (object): the object with the attributes being set. attrmap (dict): a dict mapping dict keys to attribute names, where the
keys match the expected keys in values (underscore case) and the values are the attribute names.values (dict): the dict whose values are mapping to the object.
- Returns:
- obj (object): the updated object
-
shepherd.common.utils.tasks_passed(results, logger, msg=None, exception=None)[source]¶ Logs a warning msg and returns a bool if results contains any failures.
- Args:
- results (namedtuple): namedtuple containing the sets of failed
- and completed tasks returned by Arbiter
logger (Logger): The logger to log to if any tasks failed msg (str, optional): A msg to log if any tasks failed. exception (Exception, optional): An Exception object to throw if
supplied.- Returns:
- resp (bool): Whether all tasks in results completed.