From 3f36600d1c7159f3ba00a2449e381cd32239af4e Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Mon, 26 Jan 2015 21:09:59 +0000 Subject: Enable renaming of interfaces without reboot When using persist_mapping to rename nics, you can either use --no-activate then reboot, or with this patch, allow activation and we'll take the device links down and rename on the fly avoiding the need for a reboot. Change-Id: Ife9486c9f5447e9c7a55f90ba075e22b6344ad67 --- os_net_config/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'os_net_config/__init__.py') diff --git a/os_net_config/__init__.py b/os_net_config/__init__.py index 5e1d091..e1bee26 100644 --- a/os_net_config/__init__.py +++ b/os_net_config/__init__.py @@ -125,3 +125,17 @@ class NetConfig(object): def ifup(self, interface, iftype='interface'): msg = 'running ifup on %s: %s' % (iftype, interface) self.execute(msg, '/sbin/ifup', interface) + + def ifrename(self, oldname, newname): + msg = 'renaming %s to %s: ' % (oldname, newname) + # ifdown isn't enough when renaming, we need the link down + for name in (oldname, newname): + if utils._is_active_nic(name): + self.execute(msg, '/sbin/ip', + 'link', 'set', 'dev', name, 'down') + self.execute(msg, '/sbin/ip', + 'link', 'set', 'dev', name, 'link', 'down') + self.execute(msg, '/sbin/ip', + 'link', 'set', 'dev', oldname, 'name', newname) + self.execute(msg, '/sbin/ip', + 'link', 'set', 'dev', newname, 'up') -- cgit 1.2.3-korg