aboutsummaryrefslogtreecommitdiffstats
path: root/os_net_config/impl_ifcfg.py
diff options
context:
space:
mode:
authormarios <marios@redhat.com>2014-08-01 17:21:35 +0300
committerDan Prince <dprince@redhat.com>2014-08-11 15:50:52 -0400
commit97f5eee7d135f462e82aa2c1ac9716971ad16ddc (patch)
tree72bfeb7cb8991afe5581750548c67359d3e694f6 /os_net_config/impl_ifcfg.py
parent2a2a50221559d81958ae309d193ab0e18602d268 (diff)
Adds mock ability to the ENI and Ifcfg providers
Specifying mock=True for 'apply' will return a string representing the changes required, or commands to be used in order to implement the requested/specified configuration. This is also exposed to the cli, with -m (--mock), e.g. os-net-config --mock -c ./etc/example_os_net_config_1.json -p eni
Diffstat (limited to 'os_net_config/impl_ifcfg.py')
-rw-r--r--os_net_config/impl_ifcfg.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py
index 2ba7502..6b920ae 100644
--- a/os_net_config/impl_ifcfg.py
+++ b/os_net_config/impl_ifcfg.py
@@ -162,8 +162,9 @@ class IfcfgNetConfig(os_net_config.NetConfig):
if bond.routes:
self._addRoutes(bond.name, bond.routes)
- def apply(self):
- logger.info('applying network configs...')
+ def apply(self, mock=False):
+ if not mock:
+ logger.info('applying network configs...')
restart_interfaces = []
restart_bridges = []
update_files = {}
@@ -175,7 +176,7 @@ class IfcfgNetConfig(os_net_config.NetConfig):
restart_interfaces.append(interface_name)
update_files[ifcfg_config_path(interface_name)] = iface_data
update_files[route_config_path(interface_name)] = route_data
- else:
+ elif not mock:
logger.info('No changes required for interface: %s' %
interface_name)
@@ -186,9 +187,15 @@ class IfcfgNetConfig(os_net_config.NetConfig):
restart_bridges.append(bridge_name)
update_files[bridge_config_path(bridge_name)] = bridge_data
update_files[route_config_path(bridge_name)] = route_data
- else:
+ elif not mock:
logger.info('No changes required for bridge: %s' % bridge_name)
+ if mock:
+ mock_str = ""
+ for location, data in update_files.iteritems():
+ mock_str += "%s:\n%s" % (location, data)
+ return mock_str
+
for interface in restart_interfaces:
logger.info('running ifdown on interface: %s' % interface)
processutils.execute('/sbin/ifdown', interface,