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 3c10d78..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
@@ -33,18 +32,27 @@ PYTHON_VSYS_VERSION = "1.0"
 class PlanetlabVroute(LinuxApplication):
     _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"],
+              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.Design)
 
         cls._register_attribute(action)
+        cls._register_attribute(prefix)
+        cls._register_attribute(nexthop)
         cls._register_attribute(network)
 
     def __init__(self, ec, guid):
@@ -65,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,
@@ -86,10 +95,12 @@ 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(self.reschedule_delay, self.deploy)
@@ -113,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):
 
@@ -147,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("endpoint_prefix"))
+        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("endpoint_prefix"))
-        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!