aboutsummaryrefslogtreecommitdiffstats
path: root/os_net_config/cli.py
diff options
context:
space:
mode:
authorSteven Hardy <shardy@redhat.com>2015-01-15 18:30:48 +0000
committerSteven Hardy <shardy@redhat.com>2015-02-24 09:20:41 +0000
commit6945fe5afdc12574fe00ad440319b7873f818e84 (patch)
tree69a85a7e8e933cda10afae4435ea2ebb6af8f918 /os_net_config/cli.py
parente9791d7db9bae2a19367ec69c8b0083c6aa089a4 (diff)
Add mapping option to influence nicN mapping order
Currently there's a fixed mapping between abstracted interface names (nic1, nic2 etc) and the underlying biosdevname for the device. In many cases, this mapping based on system enumeration is sufficient, but in some cases, particularly when you perform detailed pre-deployment discovery of interfaces, you may wish to alter the mapping independently of the config (e.g if the config is in a heat template, and the discovery data is provided at runtime). So this adds a -m option to os-net-config, which enables a mapping file to be provided, such that specific interfaces may be mapped to their abstract names based on knowledge of the devices or the networks they are connected to. The mapping file has the following format, where em1 and em2 are device names as detected by the OS (e.g biosdevname): interface_mapping: nic1: em2 nic2: em1 Or you can use the device MAC instead: interface_mapping: nic1: 12:34:56:78:9a:bc nic2: 12:34:56:de:f0:12 Change-Id: I93e6d3ed733244834bb3c2126c91db705b4d9167
Diffstat (limited to 'os_net_config/cli.py')
-rw-r--r--os_net_config/cli.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/os_net_config/cli.py b/os_net_config/cli.py
index 2df13c9..d22573d 100644
--- a/os_net_config/cli.py
+++ b/os_net_config/cli.py
@@ -38,6 +38,9 @@ def parse_opts(argv):
parser.add_argument('-c', '--config-file', metavar='CONFIG_FILE',
help="""path to the configuration file.""",
default='/etc/os-net-config/config.yaml')
+ parser.add_argument('-m', '--mapping-file', metavar='MAPPING_FILE',
+ help="""path to the interface mapping file.""",
+ default='/etc/os-net-config/mapping.yaml')
parser.add_argument('-p', '--provider', metavar='PROVIDER',
help="""The provider to use."""
"""One of: ifcfg, eni, iproute.""",
@@ -94,6 +97,8 @@ def main(argv=sys.argv):
opts = parse_opts(argv)
configure_logger(opts.verbose, opts.debug)
logger.info('Using config file at: %s' % opts.config_file)
+ if opts.mapping_file:
+ logger.info('Using mapping file at: %s' % opts.mapping_file)
iface_array = []
provider = None
@@ -116,6 +121,7 @@ def main(argv=sys.argv):
logger.error('Unable to set provider for this operating system.')
return 1
+ # Read config file containing network configs to apply
if os.path.exists(opts.config_file):
with open(opts.config_file) as cf:
iface_array = yaml.load(cf.read()).get("network_config")
@@ -123,10 +129,23 @@ def main(argv=sys.argv):
else:
logger.error('No config file exists at: %s' % opts.config_file)
return 1
+
if not isinstance(iface_array, list):
logger.error('No interfaces defined in config: %s' % opts.config_file)
return 1
+
+ # Read the interface mapping file, if it exists
+ # This allows you to override the default network naming abstraction
+ # 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")
+ logger.debug('interface_mapping JSON: %s' % str(iface_mapping))
+ else:
+ iface_mapping = None
+
for iface_json in iface_array:
+ iface_json.update({'nic_mapping': iface_mapping})
obj = objects.object_from_json(iface_json)
provider.add_object(obj)
files_changed = provider.apply(noop=opts.noop, cleanup=opts.cleanup)