summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorWesley Wiedenmeier <wesley.wiedenmeier@gmail.com>2016-03-22 01:17:12 -0500
committerWesley Wiedenmeier <wesley.wiedenmeier@gmail.com>2016-03-22 01:17:12 -0500
commit7e399773a95e21e4c825dab61847d6abcd2aa511 (patch)
treed14a8adedfa6f4fee0331a8919f5422634ca3041 /cloudinit
parentaab9331089abcf3f5074f3cf7659502ca0752114 (diff)
downloadvyos-cloud-init-7e399773a95e21e4c825dab61847d6abcd2aa511.tar.gz
vyos-cloud-init-7e399773a95e21e4c825dab61847d6abcd2aa511.zip
For find_fallback_network_device, kwarg rename_to_default specifies whether or
not to attempt renaming the network interface to the default interface. Default interface is controleld by net.DEFAULT_PRIMARY_INTERFACE and is currently set to eth0 for legacy reasons. By default cloud-init will not attempt to rename the device as this does not work in some situtations depending on the backing driver of the device.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/net/__init__.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
index 4641e54d..e2e50441 100644
--- a/cloudinit/net/__init__.py
+++ b/cloudinit/net/__init__.py
@@ -48,6 +48,8 @@ NET_CONFIG_BRIDGE_OPTIONS = [
"bridge_hello", "bridge_maxage", "bridge_maxwait", "bridge_stp",
]
+DEFAULT_PRIMARY_INTERFACE = 'eth0'
+
def sys_dev_path(devname, path=""):
return SYS_CLASS_NET + devname + "/" + path
@@ -282,9 +284,10 @@ def parse_net_config(path):
return ns
-def find_fallback_network_device():
+def find_fallback_network_device(rename_to_default=False):
"""Determine which attached net dev is most likely to have a connection and
generate network state to run dhcp on that interface"""
+ # by default use eth0 as primary interface
ns = {'interfaces': {}, 'dns': {'search': [], 'nameservers': []},
'routes': []}
default_link_file = textwrap.dedent("""
@@ -348,8 +351,8 @@ def find_fallback_network_device():
# if eth0 exists use it above anything else, otherwise get the interface
# that looks 'first'
- if 'eth0' in potential_interfaces:
- name = 'eth0'
+ if DEFAULT_PRIMARY_INTERFACE in potential_interfaces:
+ name = DEFAULT_PRIMARY_INTERFACE
else:
potential_interfaces.sort(
key=lambda x: int(x.strip(string.ascii_letters)))
@@ -358,18 +361,23 @@ def find_fallback_network_device():
sysfs_mac = os.path.join(SYS_CLASS_NET, name, 'address')
mac = util.load_file(sysfs_mac).strip()
+ target_name = name
+ if rename_to_default:
+ target_name = DEFAULT_PRIMARY_INTERFACE
+
# generate net config for interface, rename interface to eth0 for backwards
# compatibility, and attempt both dhcp4 and dhcp6
- ns['interfaces']['eth0'] = {
- 'mac_address': mac, 'name': 'eth0', 'type': 'physical',
+ ns['interfaces'][target_name] = {
+ 'mac_address': mac, 'name': target_name, 'type': 'physical',
'mode': 'manual', 'inet': 'inet',
'subnets': [{'type': 'dhcp4'}, {'type': 'dhcp6'}]
}
# insert params into link file
- link_file = default_link_file.format(name=name, mac=mac)
+ link_file = default_link_file.format(name=target_name, mac=mac)
- syslink_name = "/etc/systemd/network/50-cloud-init-{}.link".format(name)
+ syslink_name = "/etc/systemd/network/50-cloud-init-{}.link".format(
+ target_name)
return (ns, link_file, syslink_name)