summaryrefslogtreecommitdiff
path: root/cloudinit/net/eni.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-07-13 22:03:42 -0400
committerScott Moser <smoser@ubuntu.com>2016-07-13 22:03:42 -0400
commitefef1c263ab1c473fd90f3782a785edab7d02430 (patch)
treebc5313a90762ce0b37ccd509b7d385f49f9bc2dc /cloudinit/net/eni.py
parent9f7ce5f090689b664ffce7e0b4ac78bfeafd1a79 (diff)
downloadvyos-cloud-init-efef1c263ab1c473fd90f3782a785edab7d02430.tar.gz
vyos-cloud-init-efef1c263ab1c473fd90f3782a785edab7d02430.zip
ConfigDrive: write 'injected' files and legacy networking
Previous commit disabled the consumption of 'injected' files in configdrive (openstack server boot --file=/target/file=local-file) unless the datasource was in 'pass' mode. The default mode is 'net' so that would never happen. Also here are: a.) a fix for 'links_path_prefix' string from debian, to finally disable the rendering of systemd.link files (LP: #1594546) b.) some comments to apply_network_config c.) implement a backwards compatibility for for distros that do not yet implement apply_network_config by converting the network config into ENI format and calling apply_network. This is required because prior to the previous commit, those distros would have had 'apply_network' called with the openstack provided ENI file. But after this change they will have apply_network_config called by cloudinit's main. d.) a network_state_to_eni helper for converting net config to eni it supports the not-actually-correct 'hwaddress' field in ENI. LP: #1602373
Diffstat (limited to 'cloudinit/net/eni.py')
-rw-r--r--cloudinit/net/eni.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/cloudinit/net/eni.py b/cloudinit/net/eni.py
index e5ed10fd..419e7a74 100644
--- a/cloudinit/net/eni.py
+++ b/cloudinit/net/eni.py
@@ -352,7 +352,7 @@ class Renderer(renderer.Renderer):
content += down + route_line + eol
return content
- def _render_interfaces(self, network_state):
+ def _render_interfaces(self, network_state, render_hwaddress=False):
'''Given state, emit etc/network/interfaces content.'''
content = ""
@@ -397,6 +397,8 @@ class Renderer(renderer.Renderer):
iface['mode'] = 'dhcp'
content += _iface_start_entry(iface, index)
+ if render_hwaddress and iface.get('mac_address'):
+ content += " hwaddress %s" % iface['mac_address']
content += _iface_add_subnet(iface, subnet)
content += _iface_add_attrs(iface)
for route in subnet.get('routes', []):
@@ -411,8 +413,6 @@ class Renderer(renderer.Renderer):
for route in network_state.iter_routes():
content += self._render_route(route)
- # global replacements until v2 format
- content = content.replace('mac_address', 'hwaddress')
return content
def render_network_state(self, target, network_state):
@@ -448,3 +448,21 @@ class Renderer(renderer.Renderer):
""
])
util.write_file(fname, content)
+
+
+def network_state_to_eni(network_state, header=None, render_hwaddress=False):
+ # render the provided network state, return a string of equivalent eni
+ eni_path = 'etc/network/interfaces'
+ renderer = Renderer({
+ 'eni_path': eni_path,
+ 'eni_header': header,
+ 'links_path_prefix': None,
+ 'netrules_path': None,
+ })
+ if not header:
+ header = ""
+ if not header.endswith("\n"):
+ header += "\n"
+ contents = renderer._render_interfaces(
+ network_state, render_hwaddress=render_hwaddress)
+ return header + contents