: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
# 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