From de6933d7530dd18d185c031bb6d8c1b79c71ff3c Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 3 Aug 2021 21:42:09 +0000 Subject: [PATCH 1/2] generate contents for ovf-env.xml when provisioning through IMDS --- cloudinit/sources/DataSourceAzure.py | 15 ++++++++++++- cloudinit/sources/helpers/azure.py | 32 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py index 2e7bfbe3f05..01e2c95904a 100755 --- a/cloudinit/sources/DataSourceAzure.py +++ b/cloudinit/sources/DataSourceAzure.py @@ -45,7 +45,8 @@ is_byte_swapped, dhcp_log_cb, push_log_to_kvp, - report_failure_to_fabric) + report_failure_to_fabric, + build_minimal_ovf) LOG = logging.getLogger(__name__) @@ -540,6 +541,18 @@ def crawl_metadata(self): ) crawled_data['metadata']['disable_password'] = imds_disable_password # noqa: E501 + if metadata_source == 'IMDS' and not crawled_data['files']: + try: + contents = build_minimal_ovf( + username=imds_username, + hostname=imds_hostname, + disableSshPwd=imds_disable_password) + crawled_data['files'] = {'ovf-env.xml': contents} + except Exception as e: + report_diagnostic_event( + "Failed to construct OVF from IMDS data %s" % e, + logger_func=LOG.debug) + # only use userdata from imds if OVF did not provide custom data # userdata provided by IMDS is always base64 encoded if not userdata_raw: diff --git a/cloudinit/sources/helpers/azure.py b/cloudinit/sources/helpers/azure.py index ad476076c5b..8e86b386e11 100755 --- a/cloudinit/sources/helpers/azure.py +++ b/cloudinit/sources/helpers/azure.py @@ -343,6 +343,38 @@ def http_with_retries(url, **kwargs) -> str: raise exc +def build_minimal_ovf( + username: str, + hostname: str, + disableSshPwd: str) -> bytes: + OVF_ENV_TEMPLATE = textwrap.dedent('''\ + + + 1.0 + + LinuxProvisioningConfiguration + + {username} + {disableSshPwd} + + {hostname} + + + + 1.0 + + true + + + + ''') + ret = OVF_ENV_TEMPLATE.format( + username=username, + hostname=hostname, + disableSshPwd=disableSshPwd) + return ret.encode('utf-8') class AzureEndpointHttpClient: From 36785694ac5681a8021029b02b6c00814878e18a Mon Sep 17 00:00:00 2001 From: James Falcon Date: Thu, 5 Aug 2021 13:28:56 -0500 Subject: [PATCH 2/2] flake8 --- cloudinit/sources/helpers/azure.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cloudinit/sources/helpers/azure.py b/cloudinit/sources/helpers/azure.py index 8e86b386e11..a5ac1d572b6 100755 --- a/cloudinit/sources/helpers/azure.py +++ b/cloudinit/sources/helpers/azure.py @@ -343,10 +343,11 @@ def http_with_retries(url, **kwargs) -> str: raise exc + def build_minimal_ovf( username: str, hostname: str, - disableSshPwd: str) -> bytes: + disableSshPwd: str) -> bytes: OVF_ENV_TEMPLATE = textwrap.dedent('''\