|
|
@ -5,30 +5,93 @@ from employ.execptions import ExecutionError |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Manager(object): |
|
|
class Manager(object): |
|
|
|
|
|
""" |
|
|
|
|
|
Base Manager class that all Manager plugins must inherit from. |
|
|
|
|
|
""" |
|
|
name = "manager" |
|
|
name = "manager" |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
|
def from_config(cls, config): |
|
|
def from_config(cls, config): |
|
|
|
|
|
""" |
|
|
|
|
|
Helper classmethod used to create an instance of :class:``employ.managers.Manager`` |
|
|
|
|
|
from the provided `config` |
|
|
|
|
|
|
|
|
|
|
|
:param config: the config to get the settings from |
|
|
|
|
|
:type config: :class:``ConfigParser.RawConfigParser`` |
|
|
|
|
|
:returns: :class:``employ.managers.Manager`` |
|
|
|
|
|
""" |
|
|
settings = {} |
|
|
settings = {} |
|
|
if config.has_section(cls.name): |
|
|
if config.has_section(cls.name): |
|
|
settings = dict(config.items(cls.name)) |
|
|
settings = dict(config.items(cls.name)) |
|
|
return cls(**settings) |
|
|
return cls(**settings) |
|
|
|
|
|
|
|
|
def setup_instances(self): |
|
|
def setup_instances(self): |
|
|
|
|
|
""" |
|
|
|
|
|
Method called to setup the required instances. |
|
|
|
|
|
|
|
|
|
|
|
All children must implement this method. |
|
|
|
|
|
|
|
|
|
|
|
The result of this method should be that all the required |
|
|
|
|
|
instances are created/connected to. |
|
|
|
|
|
""" |
|
|
raise NotImplementedError() |
|
|
raise NotImplementedError() |
|
|
|
|
|
|
|
|
__enter__ = setup_instances |
|
|
|
|
|
|
|
|
def __enter__(self): |
|
|
|
|
|
""" |
|
|
|
|
|
Used to call :func:``setup_instances`` when using in a context manager |
|
|
|
|
|
|
|
|
|
|
|
with manager: |
|
|
|
|
|
# instances are connected to |
|
|
|
|
|
""" |
|
|
|
|
|
self.setup_instances() |
|
|
|
|
|
|
|
|
def cleanup_instances(self): |
|
|
def cleanup_instances(self): |
|
|
|
|
|
""" |
|
|
|
|
|
Method called to destroy/disconnect from instances. |
|
|
|
|
|
|
|
|
|
|
|
All children must implement this method. |
|
|
|
|
|
|
|
|
|
|
|
The result of this method should be that all instances are |
|
|
|
|
|
disconnected or destroy. |
|
|
|
|
|
""" |
|
|
raise NotImplementedError() |
|
|
raise NotImplementedError() |
|
|
|
|
|
|
|
|
def __exit__(self, type, value, traceback): |
|
|
def __exit__(self, type, value, traceback): |
|
|
|
|
|
""" |
|
|
|
|
|
Used to call :func:``cleanup_instances`` when using in a context manager |
|
|
|
|
|
|
|
|
|
|
|
with manager: |
|
|
|
|
|
# instances are available |
|
|
|
|
|
# instances are destroyed |
|
|
|
|
|
""" |
|
|
self.cleanup_instances() |
|
|
self.cleanup_instances() |
|
|
|
|
|
|
|
|
def setup(self, script): |
|
|
def setup(self, script): |
|
|
|
|
|
""" |
|
|
|
|
|
Execute `script` on all instances. |
|
|
|
|
|
|
|
|
|
|
|
All children must implement this method. |
|
|
|
|
|
|
|
|
|
|
|
:param script: filename of a local script to run on each instance |
|
|
|
|
|
:type script: str |
|
|
|
|
|
""" |
|
|
raise NotImplementedError() |
|
|
raise NotImplementedError() |
|
|
|
|
|
|
|
|
def run(self, command): |
|
|
def run(self, command): |
|
|
|
|
|
""" |
|
|
|
|
|
Execute `command` on all instances. |
|
|
|
|
|
|
|
|
|
|
|
All children must implement this method. |
|
|
|
|
|
|
|
|
|
|
|
This method should execute `command.commad()` on all instances |
|
|
|
|
|
as well as sending the results of all instances to `command.aggregate` |
|
|
|
|
|
|
|
|
|
|
|
The results will be in the following format: |
|
|
|
|
|
[(status, stdout, stderr), ...] |
|
|
|
|
|
|
|
|
|
|
|
:param command: the command to run on the instances |
|
|
|
|
|
:type command: :class:``employ.commands.Command` |
|
|
|
|
|
""" |
|
|
raise NotImplementedError() |
|
|
raise NotImplementedError() |
|
|
|
|
|
|
|
|
def validate_results(self, results, command): |
|
|
def validate_results(self, results, command): |
|
|
|