X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=doc%2Ftemplates%2Ftemplate_rm.py;fp=doc%2Ftemplates%2Ftemplate_rm.py;h=6eb02229e821f4b6783400b5c82d0f57c00efe99;hb=0f3a2841944186b6076a8c230b98eb8b20d7ae45;hp=8a95124b645e2313989f5e26f211989339b4dc73;hpb=23d041fe2f0d9badf6d637009e2d42a4794325c1;p=nepi.git diff --git a/doc/templates/template_rm.py b/doc/templates/template_rm.py index 8a95124b..6eb02229 100644 --- a/doc/templates/template_rm.py +++ b/doc/templates/template_rm.py @@ -19,111 +19,158 @@ # Julien Tribino - from nepi.execution.attribute import Attribute, Flags, Types from nepi.execution.resource import ResourceManager, clsinit_copy, \ - ResourceState, reschedule_delay - -#import time -#import threading + ResourceState -#clsinit_copy is used to copy the attirbute from parent class +#clsinit_copy is used to inherit attributes from the parent class @clsinit_copy -class RMName(ResourceManager): - - _rtype = "RMName" # Name that will be used in the Experiment Description Script - _help = "Help that describe the RM" - _backend_type = "backend" # Name of the platform this RM is attached. - _authorized_connections = ["RMName1" , "RMName2"] # list of valid connection for this RM - +class RMClass(ResourceManager): + # Name that will be used in the NEPI script to identify the resource type + _rtype = "platform::RMType" + # User friendly description of the RM + _help = "Describes what this RM does" + # Name of the platform this RM belongs to + _platform = "platform" + # list of valid connection for this RM + _authorized_connections = ["platform::AnotherRMType1" , "platform::AnotherRMType2"] @classmethod def _register_attributes(cls): - ''' + """ This method is used to register all the attribute of this RM. Check the file src/execution/attribute.py to see all the fields of this class - ''' + """ - attribute1 = Attribute("nameOfAttribute1", "Description of the Attribute 1", + attribute1 = Attribute("nameOfAttribute1", "Description of Attribute 1", flags = Flags.Design) - attribute2 = Attribute("nameOfAttribute2", "Description of the Attribute 2", + attribute2 = Attribute("nameOfAttribute2", "Description of Attribute 2", flags = Flags.Design) cls._register_attribute(attribute1) cls._register_attribute(attribute2) def __init__(self, ec, guid): - ''' - In the init, we usually intialize the variable of the RM that are not attribute - ''' - - super(RMName, self).__init__(ec, guid) - - self.var1 = None - + """ + Declares and initializes variables of the RM that are not Attributes. + Attributes represent resource configuration exposed to the user, + other class variables can declared here for RM internal use. + """ + + super(RMClass, self).__init__(ec, guid) def log_message(self, msg): - ''' - In some particular cases, it is required to redefined the log of the RM. - The default log require the name of the node, but sometimes, - it does not mean something. - ''' - return " guid %d - host %s - %s " % (self.guid, - self.get("hostname"), msg) + """ + Prints a log message adding a identification prefix. + The log message for the RMClass can be redefined here. + It can be used to add information about related resources such as + the hostname of the node RM associated to an application RM. + """ + + return " %s guid %d - %s " % (self._rtype, self.guid, msg) def valid_connection(self, guid): - ''' - Check if the connection is valide or not, depending on the list povided in the parameter - _authorized_connection described above - ''' + """ + Checks whether the RMClass instance can be connected to the + other RM corresponding to the given guid. + """ + + rm = self.ec.get_resource(guid) + + if rm.get_rtype() not in self._authorized_connections: + msg = ("Connection between %s %s and %s %s refused: " + "An Application can be connected only to a Node" ) % \ + (self.get_rtype(), self._guid, rm.get_rtype(), guid) + + return False + + elif len(self.connections) != 0 : + msg = ("Connection between %s %s and %s %s refused: " + "This Application is already connected" ) % \ + (self.get_rtype(), self._guid, rm.get_rtype(), guid) + self.debug(msg) + + return False + return True - # This one is not mandatory def do_discover(self): - ''' - Do anything required to discover the resource.The meaning of discover - is different for each RM - ''' - super(RMName, self).do_discover() + """ + Perform actions required to discover resources matching some criteria + specified by the user through the configuration of Attributes. + """ + + super(RMClass, self).do_discover() + + def do_reserve(self): + """ + Perform actions required to reserve resources matching some criteria + specified by the user through the configuration of Attributes. + """ + + super(RMClass, self).do_reserve() - # This one is not mandatory def do_provision(self): - ''' - Do anything required to provision the resource.The meaning of provision - is different for each RM - ''' - super(RMName, self).do_provision() + """ + Perform actions required to provision a resource in the platform, + matching the criteria specified by the user. + """ + + super(RMClass, self).do_provision() def do_deploy(self): - ''' - Do anything required to deploy the resource.The meaning of deploy - is different for each RM - ''' - super(RMName, self).do_deploy() + """ + Perform actions required to deploy a resource in the platform. + + Deploying a resource most frequently involves invoking the + do_discover and do_provision methods. In order to deploy a + resource it might be necessary wait until other associated + resource is in a given state, as in the following example: + + other_rm_list = self.get_connected(OtherRMClass.get_rtype()) + other_rm = other_rm_list[0] + if other_rm.state < ResourceState.READY: + self.ec.schedule(self.reschedule_delay, self.deploy) + else: + self.do_discover() + self.do_provision() + + super(RMClass, self).do_deploy() + + """ + + super(RMClass, self).do_deploy() def do_start(self): - ''' - Do anything required to start the resource.The meaning of start - is different for each RM - ''' - super(RMName, self).do_release() + """ + Perform actions required to start a resource in the platform. + """ + super(RMClass, self).do_start() def do_stop(self): - ''' - Do anything required to stop the resource.The meaning of stop - is different for each RM - ''' - super(RMName, self).do_release() + """ + Perform actions required to stop a resource in the platform. + """ + + super(RMClass, self).do_stop() def do_release(self): - ''' - Do anything required to release the resource.The meaning of release - is different for each RM - ''' - super(RMName, self).do_release() + """ + Perform actions required to release a resource in the platform. + """ + + super(RMClass, self).do_release() + + @property + def state(self): + """ + Returns the state of the RM. + """ + + return super(RMClass, self).state