From: Jiri Pirko jiri@mellanox.com
When user passes None and the if_id is generated by Machine class, get the created id and use it further.
Fixes: c1ef94696 ("Task: Allow to create software devices from running task") Signed-off-by: Jiri Pirko jiri@mellanox.com --- lnst/Controller/Task.py | 1 + 1 file changed, 1 insertion(+)
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py index 8670150..2f16e84 100644 --- a/lnst/Controller/Task.py +++ b/lnst/Controller/Task.py @@ -365,6 +365,7 @@ class HostAPI(object):
def _add_iface(self, if_type, if_id, netns, ip, options, slaves): interface = self._m.new_soft_interface(if_id, if_type) + if_id = interface.get_id() iface = InterfaceAPI(interface, self) self._ifaces[if_id] = iface
From: Jiri Pirko jiri@mellanox.com
User may simply call destroy method to remove the interface.
Signed-off-by: Jiri Pirko jiri@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. """
lnst-developers@lists.fedorahosted.org