commit 3e0183bbc12fbba3a3f236e10742fd585012738c
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri May 15 10:36:57 2015 +0200
Task, Interface: add {get, set}_mtu methods
The Device class (Slave) now tracks mtu changes for the interface and
the changes are sent to the Controller through an update message.
The Interface class (Controller) got two new methods: {get, set}_mtu.
get_mtu just reads the value currently stored in the object (this gets
updated automatically).
set_mtu sends a config command, this means that deconfiguration will
take care of resetting the mtu value to the original, however it also
means that for 'get' we use Netlink and for 'set' we use sysfs. This
will need to be addressed in the future.
Finally the InterfaceAPI class gained the {get, set}_mtu methods that
connect to the Interface class.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
lnst/Controller/Machine.py | 27 +++++++++++++++++++++++++--
lnst/Controller/Task.py | 6 ++++++
lnst/Slave/InterfaceManager.py | 6 +++++-
3 files changed, 36 insertions(+), 3 deletions(-)
---
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index e303c1a..dc30ef0 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -91,8 +91,7 @@ class Machine(object):
except:
iface = None
if iface:
- iface.set_hwaddr(if_data["hwaddr"])
- iface.set_devname(if_data["devname"])
+ iface.update(if_data)
#
# Factory methods for constructing interfaces on this machine. The
@@ -513,6 +512,7 @@ class Interface(object):
self._netns = None
self._peer = None
+ self._mtu = None
def get_id(self):
return self._id
@@ -612,6 +612,29 @@ class Interface(object):
except IndexError:
raise PrefixMissingError
+ def get_mtu(self):
+ return self._mtu
+
+ def set_mtu(self, mtu):
+ command = {"type": "config",
+ "host": self._machine.get_id(),
+ "persistent": False,
+ "options":[
+ {"name": "/sys/class/net/%s/mtu" %
self._devname,
+ "value": str(mtu)}
+ ]}
+ if self._netns != None:
+ command["netns"] = self._netns
+
+ self._machine.run_command(command)
+ self._mtu = mtu
+ return self._mtu
+
+ def update(self, if_data):
+ self.set_hwaddr(if_data["hwaddr"])
+ self.set_devname(if_data["devname"])
+ self._mtu = if_data["mtu"]
+
def _get_config(self):
config = {"hwaddr": self._hwaddr, "type": self._type,
"addresses": self._addresses, "slaves":
self._slaves.keys(),
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py
index 16d9282..f2ee4e0 100644
--- a/lnst/Controller/Task.py
+++ b/lnst/Controller/Task.py
@@ -353,6 +353,12 @@ class InterfaceAPI(object):
def get_ip_prefix(self, ip_index):
return VolatileValue(self._if.get_prefix, ip_index)
+ def get_mtu(self):
+ return VolatileValue(self._if.get_mtu)
+
+ def set_mtu(self, mtu):
+ return self._if.set_mtu(mtu)
+
class ModuleAPI(object):
""" An API class representing a module. """
diff --git a/lnst/Slave/InterfaceManager.py b/lnst/Slave/InterfaceManager.py
index 5727646..fc65ccc 100644
--- a/lnst/Slave/InterfaceManager.py
+++ b/lnst/Slave/InterfaceManager.py
@@ -270,6 +270,7 @@ class Device(object):
self._slaves = []
self._netns = None
self._peer = None
+ self._mtu = None
self._if_manager = if_manager
@@ -282,6 +283,7 @@ class Device(object):
self._ip = None #TODO
self.set_master(nl_msg.get_attr("IFLA_MASTER"), primary=True)
self._netns = None
+ self._mtu = nl_msg.get_attr("IFLA_MTU")
self._initialized = True
@@ -292,6 +294,7 @@ class Device(object):
self._state = nl_msg.get_attr("IFLA_OPERSTATE")
self._ip = None #TODO
self.set_master(nl_msg.get_attr("IFLA_MASTER"), primary=True)
+ self._mtu = nl_msg.get_attr("IFLA_MTU")
link = nl_msg.get_attr("IFLA_LINK")
if link != None:
@@ -316,7 +319,8 @@ class Device(object):
#return an update message that will be sent to the controller
return {"type": "if_update",
"devname": self._name,
- "hwaddr": self._hwaddr}
+ "hwaddr": self._hwaddr,
+ "mtu": self._mtu}
return None
def del_link(self):
Show replies by date