Index networks using id, not links

Rather then creating our own index for networks, use the existing ID
that already exists from config-drive. This help is clouds where
multiple networks use the same link.

Change-Id: I412541effdfdda6f8d11f2b4d8ce9d6ca9e9c165
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
Paul Belanger 2016-09-07 15:47:08 -04:00
parent 2dd24defd9
commit 90105f3b57
No known key found for this signature in database
GPG Key ID: 611A80832067AF38
2 changed files with 15 additions and 6 deletions

View File

@ -146,7 +146,9 @@ def write_redhat_interfaces(interfaces, sys_interfaces):
interface_name = "{0}.{1}".format(
vlan_raw_device, interface['vlan_id'])
elif 'bond_mode' in interface:
interface_name = iname
# It is possible our interface does not have a link, so fall back
# to iname which is the link id.
interface_name = interface.get('link', iname)
else:
interface_name = sys_interfaces[interface['mac_address']]
@ -314,8 +316,11 @@ def write_gentoo_interfaces(interfaces, sys_interfaces):
if len(raw_macs) == 1:
interface_name = sys_interfaces[raw_macs[0]]
else:
# It is possible our interface does not have a link, so
# fall back to interface id.
interface_name = next(
intf['id'] for intf in interfs if 'bond_mode' in intf)
intf.get('link', intf['id']) for intf in interfs
if 'bond_mode' in intf)
files_to_write.update(
_write_gentoo_interface(interface_name, interfs))
_setup_gentoo_network_init(interface_name, interfs)
@ -379,7 +384,9 @@ def write_debian_interfaces(interfaces, sys_interfaces):
interface_name = "{0}.{1}".format(vlan_raw_device,
interface['vlan_id'])
elif 'bond_mode' in interface:
interface_name = iname
# It is possible our interface does not have a link, so fall back
# to iname which is the link id.
interface_name = interface.get('link', iname)
else:
interface_name = sys_interfaces[interface['mac_address']]
@ -573,7 +580,9 @@ def get_config_drive_interfaces(net):
continue
link.update(network)
link['id'] = i
interfaces[i] = link
# NOTE(pabelanger): Make sure we index by the existing network id,
# rather then creating out own.
interfaces[network['id']] = link
return interfaces

View File

@ -31,8 +31,8 @@ sample_data_path = os.path.join(
distros = ['Ubuntu', 'Debian', 'Fedora', 'RedHat', 'CentOS', 'Gentoo']
styles = ['hp', 'rax', 'liberty', 'nokey']
ips = {'hp': '127.0.1.1',
'rax': '10.208.169.118',
'liberty': '192.0.2.2',
'rax': '23.253.229.154',
'liberty': '23.253.229.154',
'nokey': '127.0.1.1'}
built_scenarios = []