From ceb72a6a73c6bdcf7bcaaf3ae71f294e1250dd48 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Wed, 9 Mar 2016 14:06:21 +0100 Subject: [PATCH] register_resource now also recognizes the connectedTo keyword wich avoids a call to register_connection --- nepi/execution/ec.py | 51 ++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/nepi/execution/ec.py b/nepi/execution/ec.py index e91836d7..f60f96ce 100644 --- a/nepi/execution/ec.py +++ b/nepi/execution/ec.py @@ -603,6 +603,26 @@ class ExperimentController(object): :return: Guid of the RM :rtype: int + Specifying additional keywords results in the following actions + * autoDeploy: + boolean: if set, causes the created object to be `deploy`ed + before returning from register_resource + * connectedTo: + resourceObject: if set, causes the `register_connection` method + to be called before returning and after auto-deployment if relevant + * other keywords are used to call `set` to set attributes + + Example: + app = ec.register_resource("linux::Application", + command = "systemctl start httpd", + autoDeploy = True, + connectedTo = node) + ### instead of + app = ec.register_resource("linux::Application", + ec.set(app, "command", "systemctl start httpd") + ec.deploy(app) + ec.register_connection(app, node) + """ # Get next available guid # xxx_next_hiccup @@ -614,27 +634,30 @@ class ExperimentController(object): # Store RM self._resources[guid] = rm - ### so we can do something like - # node = ec.register_resource("linux::Node", - # username = user, - # hostname = host, - # autoDeploy = True) - ### instead of - # node = ec.register_resource("linux::Node") - # ec.set(node, "username", user) - # ec.set(node, "hostname", host) - # ec.deploy(node) + ### special keywords + specials = [] + + # is there a need to call deploy + special = 'autoDeploy' + specials.append(special) + auto_deploy = special in keywords and keywords[special] - auto_deploy = 'autoDeploy' in keywords and keywords['autoDeploy'] + # is there a need to call register_connection, and if so to what + special = 'connectedTo' + specials.append(special) + connected_to = special in keywords and keywords[special] - # now we can do all the calls to 'set' + ### now we can do all the calls to 'set' for name, value in keywords.items(): - # autoDeploy is handled locally and not propagated to 'set' - if name != 'autoDeploy': + # specials are handled locally and not propagated to 'set' + if name not in specials: self.set(guid, name, value) + ### deal with specials if auto_deploy: self.deploy(guid) + if connected_to: + self.register_connection(guid, connected_to) return guid -- 2.43.0