From 8ee426bdd9f75fc977cb40281f95c6eebc6c44c9 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Wed, 4 Nov 2015 17:41:56 +0100 Subject: [PATCH] register_resource accepts a keyword argument, so that subsequent calls to ec.set can be done in a single call illustrated on one example - linux/hello_word.py --- examples/linux/hello_world.py | 21 +++++++++++---------- src/nepi/execution/ec.py | 14 +++++++++++++- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/examples/linux/hello_world.py b/examples/linux/hello_world.py index 2e026b5b..edb195d8 100644 --- a/examples/linux/hello_world.py +++ b/examples/linux/hello_world.py @@ -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() diff --git a/src/nepi/execution/ec.py b/src/nepi/execution/ec.py index f282ac6f..5f34f826 100644 --- a/src/nepi/execution/ec.py +++ b/src/nepi/execution/ec.py @@ -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): -- 2.43.0