applied the except and raise fixers to the master branch to close the gap with py3
[nepi.git] / src / nepi / resources / planetlab / vroute.py
index 681e755..ea4fbbb 100644 (file)
@@ -3,9 +3,8 @@
 #    Copyright (C) 2013 INRIA
 #
 #    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+#    it under the terms of the GNU General Public License version 2 as
+#    published by the Free Software Foundation;
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,8 +17,7 @@
 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
 
 from nepi.execution.attribute import Attribute, Flags, Types
-from nepi.execution.resource import clsinit_copy, ResourceState, \
-        reschedule_delay
+from nepi.execution.resource import clsinit_copy, ResourceState 
 from nepi.resources.linux.application import LinuxApplication
 from nepi.resources.planetlab.node import PlanetlabNode
 from nepi.resources.planetlab.tap import PlanetlabTap
@@ -32,20 +30,29 @@ PYTHON_VSYS_VERSION = "1.0"
 
 @clsinit_copy
 class PlanetlabVroute(LinuxApplication):
-    _rtype = "PlanetlabVroute"
+    _rtype = "planetlab::Vroute"
     _help = "Creates a Vroute on a PlanetLab host"
-    _backend = "planetlab"
+    _platform = "planetlab"
 
     @classmethod
     def _register_attributes(cls):
         action = Attribute("action", "Either add or del",
               allowed = ["add", "del"],
-              flags = Flags.ExecReadOnly)
+              default = "add",
+              flags = Flags.Design)
+
+        prefix = Attribute("prefix", "IPv4 Prefix",
+              flags = Flags.Design)
+
+        nexthop = Attribute("nexthop", "IPv4 Address of the next hop",
+              flags = Flags.Design)
 
         network = Attribute("network", "IPv4 Network Address",
-              flags = Flags.ExecReadOnly)
+              flags = Flags.Design)
 
         cls._register_attribute(action)
+        cls._register_attribute(prefix)
+        cls._register_attribute(nexthop)
         cls._register_attribute(network)
 
     def __init__(self, ec, guid):
@@ -66,7 +73,8 @@ class PlanetlabVroute(LinuxApplication):
 
     def upload_sources(self):
         # upload vif-creation python script
-        pl_vroute = os.path.join(os.path.dirname(__file__), "scripts",
+        pl_vroute = os.path.join(os.path.dirname(__file__), 
+                "scripts",
                 "pl-vroute.py")
 
         self.node.upload(pl_vroute,
@@ -87,13 +95,15 @@ class PlanetlabVroute(LinuxApplication):
         # Overwrite file every time. 
         # The stop.sh has the path to the socket, wich should change
         # on every experiment run.
-        super(PlanetlabVroute, self).upload_start_command(overwrite = True)
-
-        (out, err), proc = self.execute_command(self.get("command"), blocking = True)
+        command = self.get("command")
+        shfile = os.path.join(self.app_home, "start.sh")
+        self.node.run_and_wait(command, self.run_home,
+                shfile=shfile,
+                overwrite=True)
+  
     def do_deploy(self):
         if not self.tap or self.tap.state < ResourceState.PROVISIONED:
-            self.ec.schedule(reschedule_delay, self.deploy)
+            self.ec.schedule(self.reschedule_delay, self.deploy)
         else:
             if not self.get("command"):
                 self.set("command", self._start_command)
@@ -114,7 +124,7 @@ class PlanetlabVroute(LinuxApplication):
         else:
             msg = " Failed to execute command '%s'" % command
             self.error(msg, out, err)
-            raise RuntimeError, msg
+            raise RuntimeError(msg)
 
     def do_stop(self):
 
@@ -148,20 +158,26 @@ class PlanetlabVroute(LinuxApplication):
         command = ["sudo -S python ${SRC}/pl-vroute.py"]
         command.append("-a %s" % self.get("action"))
         command.append("-n %s" % self.get("network"))
-        command.append("-p %d" % self.tap.get("prefix4"))
+        command.append("-p %s" % self.get("prefix"))
         command.append("-g %s" % self.tap.get("pointopoint"))
         command.append("-f %s" % self.tap.get("deviceName"))
-        return " ".join(command)
+        command = " ".join(command)
+
+        command = self.replace_paths(command)
+        return command
 
     @property
     def _stop_command(self):
         command = ["sudo -S python ${SRC}/pl-vroute.py"]
         command.append("-a %s" % "del")
         command.append("-n %s" % self.get("network"))
-        command.append("-p %d" % self.tap.get("prefix4"))
-        command.append("-g %s" % self.tap.get("pointopoint"))
+        command.append("-p %s" % self.get("prefix"))
+        command.append("-g %s" % self.get("nexthop"))
         command.append("-f %s" % self.tap.get("deviceName"))
-        return " ".join(command)
+        command = " ".join(command)
+        
+        command = self.replace_paths(command)
+        return command
 
     def valid_connection(self, guid):
         # TODO: Validate!