Modified FailureManager to abort only when critical resources fail
[nepi.git] / src / nepi / resources / linux / interface.py
index 85a031a..9ccdc4f 100644 (file)
@@ -1,24 +1,25 @@
-"""
-    NEPI, a framework to manage network experiments
-    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.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-"""
+#
+#    NEPI, a framework to manage network experiments
+#    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.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
 
 from nepi.execution.attribute import Attribute, Types, Flags
-from nepi.execution.resource import ResourceManager, clsinit, ResourceState
+from nepi.execution.resource import ResourceManager, clsinit_copy, \
+        ResourceState, reschedule_delay, failtrap
 from nepi.resources.linux.node import LinuxNode
 from nepi.resources.linux.channel import LinuxChannel
 
@@ -31,16 +32,17 @@ import time
 
 # TODO: UP, MTU attributes!
 
-reschedule_delay = "0.5s"
 
-@clsinit
+@clsinit_copy
 class LinuxInterface(ResourceManager):
     _rtype = "LinuxInterface"
+    _help = "Controls network devices on Linux hosts through the ifconfig tool"
+    _backend = "linux"
 
     @classmethod
     def _register_attributes(cls):
         ip4 = Attribute("ip4", "IPv4 Address",
-                flags = Flags.ExecReadOnly)
+              flags = Flags.ExecReadOnly)
 
         ip6 = Attribute("ip6", "IPv6 Address",
                 flags = Flags.ExecReadOnly)
@@ -56,7 +58,7 @@ class LinuxInterface(ResourceManager):
                 flags = Flags.ExecReadOnly)
 
         mtu = Attribute("mtu", "Maximum transmition unit for device",
-            type = Types.Integer)
+                type = Types.Integer)
 
         devname = Attribute("deviceName", 
                 "Name of the network interface (e.g. eth0, wlan0, etc)",
@@ -100,6 +102,7 @@ class LinuxInterface(ResourceManager):
         if chan: return chan[0]
         return None
 
+    @failtrap
     def discover(self):
         devname = self.get("deviceName")
         ip4 = self.get("ip4")
@@ -110,7 +113,7 @@ class LinuxInterface(ResourceManager):
         mtu = self.get("mtu")
 
         # Get current interfaces information
-        (out, err), proc = self.node.execute("ifconfig", sudo = True)
+        (out, err), proc = self.node.execute("ifconfig", sudo = True, tty = True)
 
         if err and proc.poll():
             msg = " Error retrieving interface information "
@@ -181,6 +184,7 @@ class LinuxInterface(ResourceManager):
 
         super(LinuxInterface, self).discover()
 
+    @failtrap
     def provision(self):
         devname = self.get("deviceName")
         ip4 = self.get("ip4")
@@ -224,6 +228,7 @@ class LinuxInterface(ResourceManager):
 
         super(LinuxInterface, self).provision()
 
+    @failtrap
     def deploy(self):
         # Wait until node is provisioned
         node = self.node
@@ -236,19 +241,20 @@ class LinuxInterface(ResourceManager):
         else:
             # Verify if the interface exists in node. If not, configue
             # if yes, load existing configuration
-            try:
-                self.discover()
-                self.provision()
-            except:
-                self._state = ResourceState.FAILED
-                raise
+            self.discover()
+            self.provision()
 
             super(LinuxInterface, self).deploy()
 
     def release(self):
-        tear_down = self.get("tearDown")
-        if tear_down:
-            self.execute(tear_down)
+        try:
+            tear_down = self.get("tearDown")
+            if tear_down:   
+                self.execute(tear_down)
+        except:
+            import traceback
+            err = traceback.format_exc()
+            self.error(err)
 
         super(LinuxInterface, self).release()