aboutsummaryrefslogtreecommitdiffstats
path: root/os_net_config/__init__.py
diff options
context:
space:
mode:
authorSteven Hardy <shardy@redhat.com>2015-01-26 21:09:59 +0000
committerSteven Hardy <shardy@redhat.com>2015-03-05 13:11:09 +0000
commit3f36600d1c7159f3ba00a2449e381cd32239af4e (patch)
treeeb11dc1d0ed4ecbc4b99c4a81e167adec88f7270 /os_net_config/__init__.py
parent3304fa066d1dae93df0f597c1709c955e3857a5d (diff)
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
Diffstat (limited to 'os_net_config/__init__.py')
-rw-r--r--os_net_config/__init__.py14
1 files changed, 14 insertions, 0 deletions
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')