From: Ondrej Lichtner <olichtne(a)redhat.com>
This patch adds support for configuring veth interfaces from the
Interface class and its subclass SoftInterface. The most important
changes are in the configure and deconfigure methods.
When configuring a veth interface we call a new slave method
'create_if_pair' that creates and configures both of the paired
interfaces. The first of the configured interfaces also marks the second
one as configured so it skiped.
Deconfiguration follows a similar pattern by calling the
'deconfigure_if_pair' method.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/Machine.py | 36 +++++++++++++++++++++++++++++++-----
lnst/Controller/NetTestController.py | 3 +++
2 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index 7bacad1..eefb3aa 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -458,6 +458,7 @@ class Interface(object):
self._ovs_conf = None
self._netns = None
+ self._peer = None
def get_id(self):
return self._id
@@ -539,6 +540,12 @@ class Interface(object):
def get_netns(self):
return self._netns
+ def set_peer(self, peer):
+ self._peer = peer
+
+ def get_peer(self):
+ return self._peer
+
def get_prefix(self, num):
try:
return self._addresses[num].split('/')[1]
@@ -551,7 +558,8 @@ class Interface(object):
"options": self._options,
"slave_options": self._slave_options,
"master": None, "other_masters": [],
- "ovs_conf": self._ovs_conf, "netns": self._netns}
+ "ovs_conf": self._ovs_conf, "netns": self._netns,
+ "peer": self._peer}
if self._master["primary"] != None:
config["master"] = self._master["primary"].get_id()
@@ -736,14 +744,23 @@ class SoftInterface(Interface):
def configure(self):
if self._configured:
- msg = "Unable to configure interface %s on machine %s. " \
- "It has been configured already." % (self.get_id(),
- self._machine.get_id())
- raise MachineError(msg)
+ return
logging.info("Configuring interface %s on machine %s", self.get_id(),
self._machine.get_id())
+ if self._type == "veth":
+ peer_if = self._machine.get_interface(self._peer)
+ peer_config = peer_if._get_config()
+ dev_name, peer_name = self._machine._rpc_call("create_if_pair",
+ self._id, self._get_config(),
+ self._peer, peer_config)
+ self.set_devname(dev_name)
+ peer_if.set_devname(peer_name)
+ self._configured = True
+ peer_if._configured = True
+ return
+
if self._netns != None:
dev_name = self._machine._rpc_call_to_netns(self._netns,
"create_soft_interface", self._id,
self._get_config())
@@ -757,6 +774,15 @@ class SoftInterface(Interface):
if not self._configured:
return
+ if self._type == "veth":
+ peer_if = self._machine.get_interface(self._peer)
+
+ self._machine._rpc_call("deconfigure_if_pair", self._id,
self._peer)
+
+ self._configured = False
+ peer_if._configured = False
+ return
+
if self._netns != None:
self._machine._rpc_call_to_netns(self._netns,
"deconfigure_interface",
self.get_id())
diff --git a/lnst/Controller/NetTestController.py b/lnst/Controller/NetTestController.py
index f62ca45..f3cdc60 100644
--- a/lnst/Controller/NetTestController.py
+++ b/lnst/Controller/NetTestController.py
@@ -310,6 +310,9 @@ class NetTestController:
if iface_xml_data["netns"] != None:
iface.set_netns(iface_xml_data["netns"])
+ if "peer" in iface_xml_data:
+ iface.set_peer(iface_xml_data["peer"])
+
def _prepare_tasks(self):
self._tasks = []
for task_data in self._recipe["tasks"]:
--
1.9.3