diff options
author | PengpengSun <40026211+PengpengSun@users.noreply.github.com> | 2021-07-21 00:49:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-20 11:49:37 -0500 |
commit | f0ab1e64852d50f4fe0de84e0bca0ee8bb516a9f (patch) | |
tree | dcda5287cdd9ae2b480c2957d23683a921557554 /cloudinit | |
parent | ec6afadbf0f0f77d5b58dccd70df77da89c2c91d (diff) | |
download | vyos-cloud-init-f0ab1e64852d50f4fe0de84e0bca0ee8bb516a9f.tar.gz vyos-cloud-init-f0ab1e64852d50f4fe0de84e0bca0ee8bb516a9f.zip |
VMware: add network-config support in ovf-env.xml (#947)
Details:
1. Support guest set network config through guestinfo.ovfEnv using OVF
2. 'network-config' Property is optional
3. 'network-config' Property's value has to be base64 encoded
Added unittests and updated ovf-env.xml example
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/sources/DataSourceOVF.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/cloudinit/sources/DataSourceOVF.py b/cloudinit/sources/DataSourceOVF.py index 9e83dccc..e909f058 100644 --- a/cloudinit/sources/DataSourceOVF.py +++ b/cloudinit/sources/DataSourceOVF.py @@ -358,8 +358,11 @@ class DataSourceOVF(sources.DataSource): if contents: break if contents: - (md, ud, cfg) = read_ovf_environment(contents) + read_network = ('com.vmware.guestinfo' == name) + (md, ud, cfg) = read_ovf_environment(contents, read_network) self.environment = contents + if 'network-config' in md and md['network-config']: + self._network_config = md['network-config'] found.append(name) # There was no OVF transports found @@ -507,13 +510,14 @@ def read_vmware_imc(config): # This will return a dict with some content # meta-data, user-data, some config -def read_ovf_environment(contents): +def read_ovf_environment(contents, read_network=False): props = get_properties(contents) md = {} cfg = {} ud = None cfg_props = ['password'] md_props = ['seedfrom', 'local-hostname', 'public-keys', 'instance-id'] + network_props = ['network-config'] for (prop, val) in props.items(): if prop == 'hostname': prop = "local-hostname" @@ -521,6 +525,12 @@ def read_ovf_environment(contents): md[prop] = val elif prop in cfg_props: cfg[prop] = val + elif prop in network_props and read_network: + try: + network_config = base64.b64decode(val.encode()) + md[prop] = safeload_yaml_or_dict(network_config).get('network') + except Exception: + LOG.debug("Ignore network-config in wrong format") elif prop == "user-data": try: ud = base64.b64decode(val.encode()) |