Replacing RM.rtype() for RM.get_type() for consistency
[nepi.git] / src / nepi / resources / planetlab / tap.py
index 411eb51..fc15662 100644 (file)
@@ -36,6 +36,8 @@ PYTHON_VSYS_VERSION = "1.0"
 @clsinit_copy
 class PlanetlabTap(LinuxApplication):
     _rtype = "PlanetlabTap"
+    _help = "Creates a TAP device on a PlanetLab host"
+    _backend = "planetlab"
 
     @classmethod
     def _register_attributes(cls):
@@ -86,10 +88,55 @@ class PlanetlabTap(LinuxApplication):
 
     @property
     def node(self):
-        node = self.get_connected(PlanetlabNode.rtype())
+        node = self.get_connected(PlanetlabNode.get_rtype())
         if node: return node[0]
         return None
 
+    """
+    def trace(self, name, attr = TraceAttr.ALL, block = 512, offset = 0):
+        self.info("Retrieving '%s' trace %s " % (name, attr))
+
+        path = os.path.join(self.run_home, name)
+        
+        command = "(test -f %s && echo 'success') || echo 'error'" % path
+        (out, err), proc = self.node.execute(command)
+
+        if (err and proc.poll()) or out.find("error") != -1:
+            msg = " Couldn't find trace %s " % name
+            self.error(msg, out, err)
+            return None
+    
+        if attr == TraceAttr.PATH:
+            return path
+
+        if attr == TraceAttr.ALL:
+            (out, err), proc = self.node.check_output(self.run_home, name)
+            
+            if proc.poll():
+                msg = " Couldn't read trace %s " % name
+                self.error(msg, out, err)
+                return None
+
+            return out
+
+        if attr == TraceAttr.STREAM:
+            cmd = "dd if=%s bs=%d count=1 skip=%d" % (path, block, offset)
+        elif attr == TraceAttr.SIZE:
+            cmd = "stat -c%%s %s " % path
+
+        (out, err), proc = self.node.execute(cmd)
+
+        if proc.poll():
+            msg = " Couldn't find trace %s " % name
+            self.error(msg, out, err)
+            return None
+        
+        if attr == TraceAttr.SIZE:
+            out = int(out.strip())
+
+        return out
+    """
+
     def upload_sources(self):
         # upload vif-creation python script
         pl_vif_create = os.path.join(os.path.dirname(__file__), "scripts",
@@ -145,7 +192,7 @@ class PlanetlabTap(LinuxApplication):
         if_name = self.wait_if_name()
         self.set("deviceName", if_name) 
 
-    def deploy(self):
+    def do_deploy(self):
         if not self.node or self.node.state < ResourceState.PROVISIONED:
             self.ec.schedule(reschedule_delay, self.deploy)
         else:
@@ -158,17 +205,13 @@ class PlanetlabTap(LinuxApplication):
             if not self.get("install"):
                 self.set("install", self._install)
 
-            try:
-                self.discover()
-                self.provision()
-            except:
-                self.fail()
-                raise
+            self.do_discover()
+            self.do_provision()
+
             self.debug("----- READY ---- ")
             self.set_ready()
 
-    def start(self):
+    def do_start(self):
         if self.state == ResourceState.READY:
             command = self.get("command")
             self.info("Starting command '%s'" % command)
@@ -177,10 +220,9 @@ class PlanetlabTap(LinuxApplication):
         else:
             msg = " Failed to execute command '%s'" % command
             self.error(msg, out, err)
-            self.fail()
             raise RuntimeError, msg
 
-    def stop(self):
+    def do_stop(self):
         command = self.get('command') or ''
         
         if self.state == ResourceState.STARTED:
@@ -204,24 +246,23 @@ class PlanetlabTap(LinuxApplication):
 
                 if out.strip().find(self.get("deviceName")) == -1: 
                     # tap is not running is not running (socket not found)
-                    self._finish_time = tnow()
-                    self._state = ResourceState.FINISHED
+                    self.finish()
 
             self._last_state_check = tnow()
 
         return self._state
 
-    def release(self):
+    def do_release(self):
         # Node needs to wait until all associated RMs are released
         # to be released
         from nepi.resources.linux.udptunnel import UdpTunnel
-        rms = self.get_connected(UdpTunnel.rtype())
+        rms = self.get_connected(UdpTunnel.get_rtype())
         for rm in rms:
             if rm.state < ResourceState.STOPPED:
                 self.ec.schedule(reschedule_delay, self.release)
                 return 
 
-        super(PlanetlabTap, self).release()
+        super(PlanetlabTap, self).do_release()
 
     def wait_if_name(self):
         """ Waits until the if_name file for the command is generated, 
@@ -241,7 +282,6 @@ class PlanetlabTap(LinuxApplication):
         else:
             msg = "Couldn't retrieve if_name"
             self.error(msg, out, err)
-            self.fail()
             raise RuntimeError, msg
 
         return if_name