aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os_net_config/__init__.py8
-rw-r--r--os_net_config/impl_eni.py14
-rw-r--r--os_net_config/impl_ifcfg.py18
3 files changed, 19 insertions, 21 deletions
diff --git a/os_net_config/__init__.py b/os_net_config/__init__.py
index 8d241af..5e1d091 100644
--- a/os_net_config/__init__.py
+++ b/os_net_config/__init__.py
@@ -117,3 +117,11 @@ class NetConfig(object):
logger.info('%s%s' % (self.log_prefix, msg))
if not self.noop:
os.remove(filename)
+
+ def ifdown(self, interface, iftype='interface'):
+ msg = 'running ifdown on %s: %s' % (iftype, interface)
+ self.execute(msg, '/sbin/ifdown', interface, check_exit_code=False)
+
+ def ifup(self, interface, iftype='interface'):
+ msg = 'running ifup on %s: %s' % (iftype, interface)
+ self.execute(msg, '/sbin/ifup', interface)
diff --git a/os_net_config/impl_eni.py b/os_net_config/impl_eni.py
index 880c4e4..5f46f33 100644
--- a/os_net_config/impl_eni.py
+++ b/os_net_config/impl_eni.py
@@ -211,24 +211,18 @@ class ENINetConfig(os_net_config.NetConfig):
if (utils.diff(_network_config_path(), new_config)):
for interface in self.interfaces.keys():
- msg = 'running ifdown on interface: %s' % interface
- self.execute(msg, '/sbin/ifdown', interface,
- check_exit_code=False)
+ self.ifdown(interface)
for bridge in self.bridges.keys():
- msg = 'running ifdown on bridge: %s' % bridge
- self.execute(msg, '/sbin/ifdown', bridge,
- check_exit_code=False)
+ self.ifdown(bridge, iftype='bridge')
self.write_config(_network_config_path(), new_config)
for bridge in self.bridges.keys():
- msg = 'running ifup on bridge: %s' % bridge
- self.execute(msg, '/sbin/ifup', bridge)
+ self.ifup(bridge, iftype='bridge')
for interface in self.interfaces.keys():
- msg = 'running ifup on interface: %s' % interface
- self.execute(msg, '/sbin/ifup', interface)
+ self.ifup(interface)
else:
logger.info('No interface changes are required.')
diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py
index 56a0e47..100edeb 100644
--- a/os_net_config/impl_ifcfg.py
+++ b/os_net_config/impl_ifcfg.py
@@ -259,28 +259,24 @@ class IfcfgNetConfig(os_net_config.NetConfig):
if ifcfg_file not in all_file_names:
interface_name = ifcfg_file[len(cleanup_pattern()) - 1:]
if interface_name != 'lo':
- msg = 'cleaning up interface: %s' % interface_name
- self.execute(msg, '/sbin/ifdown', interface_name,
- check_exit_code=False)
+ logger.info('cleaning up interface: %s'
+ % interface_name)
+ self.ifdown(interface_name)
self.remove_config(ifcfg_file)
for interface in restart_interfaces:
- msg = 'running ifdown on interface: %s' % interface
- self.execute(msg, '/sbin/ifdown', interface, check_exit_code=False)
+ self.ifdown(interface)
for bridge in restart_bridges:
- msg = 'running ifdown on bridge: %s' % bridge
- self.execute(msg, '/sbin/ifdown', bridge, check_exit_code=False)
+ self.ifdown(bridge, iftype='bridge')
for location, data in update_files.iteritems():
self.write_config(location, data)
for bridge in restart_bridges:
- msg = 'running ifup on bridge: %s' % bridge
- self.execute(msg, '/sbin/ifup', bridge)
+ self.ifup(bridge, iftype='bridge')
for interface in restart_interfaces:
- msg = 'running ifup on interface: %s' % interface
- self.execute(msg, '/sbin/ifup', interface)
+ self.ifup(interface)
return update_files