From a4ad189558a414c6029b4dfbc8e459339ebe534d Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Wed, 21 Jan 2015 17:24:08 +0000 Subject: Add a persist_mapping option to the mapping file This adds the option to permanently rewrite the configuration so the aliases are used instead of the system name. This is useful where you have a variety of hardware and you want to have consistent device naming accross all platforms - this allows you to essentially rename the interfaces permanently so they match the abstracted nicN names. Note, this needs to be run with --cleanup or the old (now conflicting) configs will still be in place, and it may require a reboot before the changes are fully applied. Change-Id: I5af146e764b72c4beaa41c549fabff0af8802152 --- os_net_config/cli.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'os_net_config/cli.py') diff --git a/os_net_config/cli.py b/os_net_config/cli.py index d22573d..939eeaa 100644 --- a/os_net_config/cli.py +++ b/os_net_config/cli.py @@ -74,6 +74,14 @@ def parse_opts(argv): help="Cleanup unconfigured interfaces.", required=False) + parser.add_argument( + '--persist-mapping', + dest="persist_mapping", + action='store_true', + help="Make aliases defined in the mapping file permanent " + "(WARNING, permanently renames nics).", + required=False) + opts = parser.parse_args(argv[1:]) return opts @@ -139,13 +147,18 @@ def main(argv=sys.argv): # mappings by specifying a specific nicN->name or nicN->MAC mapping if os.path.exists(opts.mapping_file): with open(opts.mapping_file) as cf: - iface_mapping = yaml.load(cf.read()).get("interface_mapping") + iface_map = yaml.load(cf.read()) + iface_mapping = iface_map.get("interface_mapping") logger.debug('interface_mapping JSON: %s' % str(iface_mapping)) + persist_mapping = opts.persist_mapping + logger.debug('persist_mapping: %s' % persist_mapping) else: iface_mapping = None + persist_mapping = False for iface_json in iface_array: iface_json.update({'nic_mapping': iface_mapping}) + iface_json.update({'persist_mapping': persist_mapping}) obj = objects.object_from_json(iface_json) provider.add_object(obj) files_changed = provider.apply(noop=opts.noop, cleanup=opts.cleanup) -- cgit 1.2.3-korg