src/nepi/execution/resource.py
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Fri, 6 Feb 2015 10:56:14 +0000 (11:56 +0100)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Fri, 6 Feb 2015 10:56:14 +0000 (11:56 +0100)
examples/omf/nitos_testbed_bootstrap.py
src/nepi/execution/resource.py
src/nepi/resources/linux/node.py
src/nepi/resources/ns3/ns3netdevice.py
src/nepi/resources/ns3/ns3node.py
src/nepi/resources/ns3/ns3wifinetdevice.py

index 452114f..771e188 100644 (file)
@@ -82,7 +82,7 @@ ec.set(reboot_app, "command", reboot_cmd)
 ec.register_connection(reboot_app, gw_node)\r
 \r
 ec.register_condition(reboot_app, ResourceAction.START, load_app, \r
 ec.register_connection(reboot_app, gw_node)\r
 \r
 ec.register_condition(reboot_app, ResourceAction.START, load_app, \r
-            ResourceState.STOPPED, time="300s") \r
+            ResourceState.STOPPED, time="60s") \r
 \r
 hosts = hosts.split(",")\r
 \r
 \r
 hosts = hosts.split(",")\r
 \r
@@ -98,11 +98,15 @@ for hostname in hosts:
     ec.register_condition(node, ResourceAction.DEPLOY, reboot_app, \r
             ResourceState.STOPPED, time="300s") \r
  \r
     ec.register_condition(node, ResourceAction.DEPLOY, reboot_app, \r
             ResourceState.STOPPED, time="300s") \r
  \r
-    app = ec.register_resource("linux::Application")\r
-    ec.set(app, "command", "modprobe ath5k && ip a | grep wlan0 && service omf_rc restart")\r
-    ec.register_connection(app, node)\r
-   \r
-    apps.append(app)\r
+    modprobe_app = ec.register_resource("linux::Application")\r
+    ec.set(modprobe_app, "command", "modprobe ath5k && ip a | grep wlan0")\r
+    ec.register_connection(modprobe_app, node)\r
+    apps.append(modprobe_app)\r
+\r
+    rc_app = ec.register_resource("linux::Application")\r
+    ec.set(rc_app, "command", "service omf_rc stop; service omf_rc start")\r
+    ec.register_connection(rc_app, node)\r
+    apps.append(rc_app)\r
 \r
 print "This might take time..."\r
 \r
 \r
 print "This might take time..."\r
 \r
index 16b434f..adcb438 100644 (file)
@@ -83,7 +83,7 @@ def clsinit(cls):
 
 def clsinit_copy(cls):
     """ Initializes template information (i.e. attributes and traces)
 
 def clsinit_copy(cls):
     """ Initializes template information (i.e. attributes and traces)
-    on classes direved from the ResourceManager class.
+    on classes derived from the ResourceManager class.
     It differs from the clsinit method in that it forces inheritance
     of attributes and traces from the parent class.
 
     It differs from the clsinit method in that it forces inheritance
     of attributes and traces from the parent class.
 
@@ -213,7 +213,7 @@ class ResourceManager(Logger):
         """ Resource subclasses will invoke this method to register
         resource traces
 
         """ Resource subclasses will invoke this method to register
         resource traces
 
-        This method should be overriden in the RMs that define traces.
+        This method should be overridden in the RMs that define traces.
         
         """
         
         
         """
         
@@ -401,7 +401,7 @@ class ResourceManager(Logger):
 
     @property
     def reserved_time(self):
 
     @property
     def reserved_time(self):
-        """ Returns the resreved time of the RM as a timestamp """
+        """ Returns the reserved time of the RM as a timestamp """
         return self._reserved_time
 
     @property
         return self._reserved_time
 
     @property
@@ -421,7 +421,7 @@ class ResourceManager(Logger):
 
     @property
     def failed_time(self):
 
     @property
     def failed_time(self):
-        """ Returns the time failure occured for the RM as a timestamp """
+        """ Returns the time failure occurred for the RM as a timestamp """
         return self._failed_time
 
     @property
         return self._failed_time
 
     @property
@@ -447,7 +447,7 @@ class ResourceManager(Logger):
     def register_connection(self, guid):
         """ Registers a connection to the RM identified by guid
 
     def register_connection(self, guid):
         """ Registers a connection to the RM identified by guid
 
-        This method should not be overriden. Specific functionality
+        This method should not be overridden. Specific functionality
         should be added in the do_connect method.
 
         :param guid: Global unique identified of the RM to connect to
         should be added in the do_connect method.
 
         :param guid: Global unique identified of the RM to connect to
@@ -461,7 +461,7 @@ class ResourceManager(Logger):
     def unregister_connection(self, guid):
         """ Removes a registered connection to the RM identified by guid
         
     def unregister_connection(self, guid):
         """ Removes a registered connection to the RM identified by guid
         
-        This method should not be overriden. Specific functionality
+        This method should not be overridden. Specific functionality
         should be added in the do_disconnect method.
 
         :param guid: Global unique identified of the RM to connect to
         should be added in the do_disconnect method.
 
         :param guid: Global unique identified of the RM to connect to
@@ -479,7 +479,7 @@ class ResourceManager(Logger):
         This  method is responsible for selecting an individual resource
         matching user requirements.
 
         This  method is responsible for selecting an individual resource
         matching user requirements.
 
-        This method should not be overriden directly. Specific functionality
+        This method should not be overridden directly. Specific functionality
         should be added in the do_discover method.
 
         """
         should be added in the do_discover method.
 
         """
@@ -494,7 +494,7 @@ class ResourceManager(Logger):
         This  method is responsible for reserving an individual resource
         matching user requirements.
 
         This  method is responsible for reserving an individual resource
         matching user requirements.
 
-        This method should not be overriden directly. Specific functionality
+        This method should not be overridden directly. Specific functionality
         should be added in the do_reserved method.
 
         """
         should be added in the do_reserved method.
 
         """
@@ -510,7 +510,7 @@ class ResourceManager(Logger):
         After this method has been successfully invoked, the resource
         should be accessible/controllable by the RM.
 
         After this method has been successfully invoked, the resource
         should be accessible/controllable by the RM.
 
-        This method should not be overriden directly. Specific functionality
+        This method should not be overridden directly. Specific functionality
         should be added in the do_provision method.
 
         """
         should be added in the do_provision method.
 
         """
@@ -518,6 +518,22 @@ class ResourceManager(Logger):
             if self._state != ResourceState.RELEASED:
                 self.do_provision()
 
             if self._state != ResourceState.RELEASED:
                 self.do_provision()
 
+    @failtrap
+    def configure(self):
+        """ Performs resource configuration.
+
+        This  method is responsible for configuring one resource.
+        After this method has been successfully invoked, the resource
+        should be set up to start the experimentation.
+
+        This method should not be overridden directly. Specific functionality
+        should be added in the do_configure method.
+
+        """
+        with self._release_lock:
+            if self._state != ResourceState.RELEASED:
+                self.do_configure()
+
     @failtrap
     def start(self):
         """ Starts the RM (e.g. launch remote process).
     @failtrap
     def start(self):
         """ Starts the RM (e.g. launch remote process).
@@ -525,7 +541,7 @@ class ResourceManager(Logger):
         There is no standard start behavior. Some RMs will not need to perform
         any actions upon start.
 
         There is no standard start behavior. Some RMs will not need to perform
         any actions upon start.
 
-        This method should not be overriden directly. Specific functionality
+        This method should not be overridden directly. Specific functionality
         should be added in the do_start method.
 
         """
         should be added in the do_start method.
 
         """
@@ -545,7 +561,7 @@ class ResourceManager(Logger):
         There is no standard stop behavior. Some RMs will not need to perform
         any actions upon stop.
     
         There is no standard stop behavior. Some RMs will not need to perform
         any actions upon stop.
     
-        This method should not be overriden directly. Specific functionality
+        This method should not be overridden directly. Specific functionality
         should be added in the do_stop method.
       
         """
         should be added in the do_stop method.
       
         """
@@ -563,7 +579,7 @@ class ResourceManager(Logger):
         This method is responsible for deploying the resource (and invoking 
         the discover and provision methods).
  
         This method is responsible for deploying the resource (and invoking 
         the discover and provision methods).
  
-        This method should not be overriden directly. Specific functionality
+        This method should not be overridden directly. Specific functionality
         should be added in the do_deploy method.
        
         """
         should be added in the do_deploy method.
        
         """
@@ -581,7 +597,7 @@ class ResourceManager(Logger):
         This  method is responsible for releasing resources that were
         used during the experiment by the RM.
 
         This  method is responsible for releasing resources that were
         used during the experiment by the RM.
 
-        This method should not be overriden directly. Specific functionality
+        This method should not be overridden directly. Specific functionality
         should be added in the do_release method.
       
         """
         should be added in the do_release method.
       
         """
@@ -601,7 +617,7 @@ class ResourceManager(Logger):
     def fail(self):
         """ Sets the RM to state FAILED.
 
     def fail(self):
         """ Sets the RM to state FAILED.
 
-        This method should not be overriden directly. Specific functionality
+        This method should not be overridden directly. Specific functionality
         should be added in the do_fail method.
 
         """
         should be added in the do_fail method.
 
         """
@@ -1053,6 +1069,9 @@ class ResourceManager(Logger):
     def do_provision(self):
         self.set_provisioned()
 
     def do_provision(self):
         self.set_provisioned()
 
+    def do_configure(self):
+        pass
+
     def do_start(self):
         self.set_started()
 
     def do_start(self):
         self.set_started()
 
index 8c5a6c5..55ce104 100644 (file)
@@ -371,9 +371,9 @@ class LinuxNode(ResourceManager):
                 ip = sshfuncs.gethostbyname(self.get("hostname"))
                 self.set("ip", ip)
             except:
                 ip = sshfuncs.gethostbyname(self.get("hostname"))
                 self.set("ip", ip)
             except:
-                msg = "Local DNS can not resolve hostname %s" % self.get("hostname") 
-                self.error(msg)
-
+                if self.get("gateway") is None:
+                    msg = "Local DNS can not resolve hostname %s" % self.get("hostname") 
+                    self.error(msg)
 
         super(LinuxNode, self).do_provision()
 
 
         super(LinuxNode, self).do_provision()
 
index e7c94cf..9807a6c 100644 (file)
@@ -125,12 +125,7 @@ class NS3BaseNetDevice(NS3Base):
 
     @property
     def _rms_to_wait(self):
 
     @property
     def _rms_to_wait(self):
-        rms = set()
-        
-        node = self.node
-        rms.add(node)
-
-        rms.add(self.channel)
+        rms = set([self.node, self.channel])
         return rms
 
     def _configure_object(self):
         return rms
 
     def _configure_object(self):
index 2d14b85..0e5da2e 100644 (file)
@@ -121,20 +121,16 @@ class NS3BaseNode(NS3Base):
 
     @property
     def _rms_to_wait(self):
 
     @property
     def _rms_to_wait(self):
-        rms = set()
-        rms.add(self.simulation)
+        rms = set([self.simulation])
 
 
-        ipv4 = self.ipv4
-        if ipv4:
-            rms.add(ipv4)
+        if self.ipv4:
+            rms.add(self.ipv4)
 
 
-        arp = self.arp
-        if arp:
-            rms.add(arp)
+        if self.arp:
+            rms.add(self.arp)
 
 
-        mobility = self.mobility
-        if mobility:
-            rms.add(mobility)
+        if self.mobility:
+            rms.add(self.mobility)
 
         return rms
 
 
         return rms
 
index 9afa071..fff65e9 100644 (file)
@@ -38,7 +38,7 @@ class NS3BaseWifiNetDevice(NS3BaseNetDevice):
 
     @property
     def _rms_to_wait(self):
 
     @property
     def _rms_to_wait(self):
-        rms = set([self.node, self.node.ipv4])
+        rms = set([self.node])
         return rms
 
     def _configure_mac_address(self):
         return rms
 
     def _configure_mac_address(self):