From: Jiri Pirko <jiri(a)mellanox.com>
User may simply call destroy method to remove the interface.
Signed-off-by: Jiri Pirko <jiri(a)mellanox.com>
---
lnst/Controller/Machine.py | 4 ++++
lnst/Controller/Task.py | 11 +++++++++++
2 files changed, 15 insertions(+)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index dbf71c3..ce78866 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -109,6 +109,10 @@ class Machine(object):
self._interfaces.append(iface)
return iface
+ def remove_interface(self, if_id):
+ iface = self.get_interface(if_id)
+ self._interfaces.remove(iface)
+
def interface_update(self, if_data):
try:
iface = self.get_interface(if_data["if_id"])
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py
index 2f16e84..4aeed17 100644
--- a/lnst/Controller/Task.py
+++ b/lnst/Controller/Task.py
@@ -395,6 +395,14 @@ class HostAPI(object):
interface.up()
return iface
+ def _remove_iface(self, iface):
+ interface = iface._if
+ interface.deconfigure()
+ interface.cleanup()
+ if_id = interface.get_id()
+ self._m.remove_interface(if_id)
+ self._ifaces.pop(if_id)
+
def create_bond(self, if_id=None, netns=None, ip=None,
options=None, slaves=None):
return self._add_iface("bond", if_id, netns, ip, options, slaves)
@@ -497,6 +505,9 @@ class InterfaceAPI(object):
self._if.configure()
self._if.up()
+ def destroy(self):
+ self._host._remove_iface(self)
+
class ModuleAPI(object):
""" An API class representing a module. """
--
2.4.3