X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Fresources%2Flinux%2Finterface.py;h=b166d4c00d2a67497b4464a6d0a6cab3c46f8355;hb=23d041fe2f0d9badf6d637009e2d42a4794325c1;hp=9ccdc4f683f8355d721d7bd7203b220ba6ba9626;hpb=99d8b2a4431d8fafd0385e189375106d46f1abd9;p=nepi.git diff --git a/src/nepi/resources/linux/interface.py b/src/nepi/resources/linux/interface.py index 9ccdc4f6..b166d4c0 100644 --- a/src/nepi/resources/linux/interface.py +++ b/src/nepi/resources/linux/interface.py @@ -19,7 +19,7 @@ from nepi.execution.attribute import Attribute, Types, Flags from nepi.execution.resource import ResourceManager, clsinit_copy, \ - ResourceState, reschedule_delay, failtrap + ResourceState from nepi.resources.linux.node import LinuxNode from nepi.resources.linux.channel import LinuxChannel @@ -30,45 +30,46 @@ import re import tempfile import time -# TODO: UP, MTU attributes! - +# TODO: +# - check UP, MTU attributes! +# - clean up code and test! @clsinit_copy class LinuxInterface(ResourceManager): - _rtype = "LinuxInterface" + _rtype = "linux::Interface" _help = "Controls network devices on Linux hosts through the ifconfig tool" - _backend = "linux" + _platform = "linux" @classmethod def _register_attributes(cls): ip4 = Attribute("ip4", "IPv4 Address", - flags = Flags.ExecReadOnly) + flags = Flags.Design) ip6 = Attribute("ip6", "IPv6 Address", - flags = Flags.ExecReadOnly) + flags = Flags.Design) mac = Attribute("mac", "MAC Address", - flags = Flags.ExecReadOnly) + flags = Flags.Design) mask4 = Attribute("mask4", "IPv4 network mask", - flags = Flags.ExecReadOnly) + flags = Flags.Design) mask6 = Attribute("mask6", "IPv6 network mask", type = Types.Integer, - flags = Flags.ExecReadOnly) + flags = Flags.Design) mtu = Attribute("mtu", "Maximum transmition unit for device", type = Types.Integer) devname = Attribute("deviceName", "Name of the network interface (e.g. eth0, wlan0, etc)", - flags = Flags.ExecReadOnly) + flags = Flags.Design) up = Attribute("up", "Link up", type = Types.Bool) tear_down = Attribute("tearDown", "Bash script to be executed before " + \ "releasing the resource", - flags = Flags.ExecReadOnly) + flags = Flags.Design) cls._register_attribute(ip4) cls._register_attribute(ip6) @@ -92,18 +93,17 @@ class LinuxInterface(ResourceManager): @property def node(self): - node = self.get_connected(LinuxNode.rtype()) + node = self.get_connected(LinuxNode.get_rtype()) if node: return node[0] return None @property def channel(self): - chan = self.get_connected(LinuxChannel.rtype()) + chan = self.get_connected(LinuxChannel.get_rtype()) if chan: return chan[0] return None - @failtrap - def discover(self): + def do_discover(self): devname = self.get("deviceName") ip4 = self.get("ip4") ip6 = self.get("ip4") @@ -182,10 +182,9 @@ class LinuxInterface(ResourceManager): self.error(msg) raise RuntimeError, msg - super(LinuxInterface, self).discover() + super(LinuxInterface, self).do_discover() - @failtrap - def provision(self): + def do_provision(self): devname = self.get("deviceName") ip4 = self.get("ip4") ip6 = self.get("ip4") @@ -226,37 +225,31 @@ class LinuxInterface(ResourceManager): self.error(msg, out, err) raise RuntimeError, "%s - %s - %s" % (msg, out, err) - super(LinuxInterface, self).provision() + super(LinuxInterface, self).do_provision() - @failtrap - def deploy(self): + def do_deploy(self): # Wait until node is provisioned node = self.node chan = self.channel if not node or node.state < ResourceState.PROVISIONED: - self.ec.schedule(reschedule_delay, self.deploy) + self.ec.schedule(self.reschedule_delay, self.deploy) elif not chan or chan.state < ResourceState.READY: - self.ec.schedule(reschedule_delay, self.deploy) + self.ec.schedule(self.reschedule_delay, self.deploy) else: # Verify if the interface exists in node. If not, configue # if yes, load existing configuration - self.discover() - self.provision() + self.do_discover() + self.do_provision() - super(LinuxInterface, self).deploy() + super(LinuxInterface, self).do_deploy() - def release(self): - try: - tear_down = self.get("tearDown") - if tear_down: - self.execute(tear_down) - except: - import traceback - err = traceback.format_exc() - self.error(err) + def do_release(self): + tear_down = self.get("tearDown") + if tear_down: + self.execute(tear_down) - super(LinuxInterface, self).release() + super(LinuxInterface, self).do_release() def valid_connection(self, guid): # TODO: Validate! @@ -274,6 +267,7 @@ class LinuxInterface(ResourceManager): attr = self._attrs["up"] attr._value = up attr = self._attrs["mtu"] + attr._value = mtu def add_set_hooks(self): attrup = self._attrs["up"] @@ -283,7 +277,7 @@ class LinuxInterface(ResourceManager): attrmtu.set_hook = self.set_hook_mtu def set_hook_up(self, oldval, newval): - if oldval == newval: + if self.state == ResourceState.NEW or oldval == newval: return oldval # configure interface up @@ -302,7 +296,7 @@ class LinuxInterface(ResourceManager): return newval def set_hook_mtu(self, oldval, newval): - if oldval == newval: + if self.state == ResourceState.NEW or oldval == newval: return oldval cmd = "ifconfig %s mtu %d" % (self.get("deviceName"), newval)