register_resource now also recognizes the connectedTo keyword
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 9 Mar 2016 13:06:21 +0000 (14:06 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 9 Mar 2016 13:13:00 +0000 (14:13 +0100)
wich avoids a call to register_connection

nepi/execution/ec.py

index e91836d..f60f96c 100644 (file)
@@ -603,6 +603,26 @@ class ExperimentController(object):
             :return: Guid of the RM
             :rtype: int
             
             :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
         """
         # Get next available guid
         # xxx_next_hiccup
@@ -614,27 +634,30 @@ class ExperimentController(object):
         # Store RM
         self._resources[guid] = rm
 
         # 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():
         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)
 
                 self.set(guid, name, value)
 
+        ### deal with specials
         if auto_deploy:
             self.deploy(guid)
         if auto_deploy:
             self.deploy(guid)
+        if connected_to:
+            self.register_connection(guid, connected_to)
 
         return guid
 
 
         return guid