register_resource accepts a keyword argument, so that subsequent calls to ec.set...
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 4 Nov 2015 16:41:56 +0000 (17:41 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 4 Nov 2015 16:41:56 +0000 (17:41 +0100)
illustrated on one example - linux/hello_word.py

examples/linux/hello_world.py
src/nepi/execution/ec.py

index 2e026b5..edb195d 100644 (file)
@@ -47,21 +47,22 @@ ssh_key = options.ssh_key
 
 ec = ExperimentController(exp_id = "src-up-exp")
         
-node = ec.register_resource("linux::Node")
-ec.set(node, "hostname", hostname)
-ec.set(node, "username", username)
-ec.set(node, "identity", ssh_key)
-ec.set(node, "cleanExperiment", True)
-ec.set(node, "cleanProcesses", True)
+node = ec.register_resource("linux::Node",
+                            hostname = hostname,
+                            username =username,
+                            identity = ssh_key,
+                            cleanExperiment = True,
+                            cleanProcesses = True)
 
 path_to_sources = os.path.join(
         os.path.dirname(os.path.realpath(__file__)),
         "hello.c")
 
-app = ec.register_resource("linux::Application")
-ec.set(app, "sources", path_to_sources)
-ec.set(app, "build", "gcc ${SRC}/hello.c -o ${BIN}/hello")
-ec.set(app, "command", "${BIN}/hello")
+app = ec.register_resource("linux::Application",
+                           sources = path_to_sources,
+                           build = "gcc ${SRC}/hello.c -o ${BIN}/hello",
+                           command = "${BIN}/hello")
+
 ec.register_connection(node, app)
 
 ec.deploy()
index f282ac6..5f34f82 100644 (file)
@@ -591,7 +591,7 @@ class ExperimentController(object):
                 rms.append(rm.guid)
         return rms
 
-    def register_resource(self, rtype, guid = None):
+    def register_resource(self, rtype, guid = None, **keywords):
         """ Registers a new ResourceManager of type 'rtype' in the experiment
         
         This method will assign a new 'guid' for the RM, if no guid
@@ -614,6 +614,18 @@ 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)
+        ### instead of
+        # node = ec.register_resource("linux::Node")
+        # ec.set(node, "username", user)
+        # ec.set(node, "hostname", host)
+
+        for name, value in keywords.items():
+            self.set(guid, name, value)
+
         return guid
 
     def get_attributes(self, guid):