diff options
author | Anh Vo <anhvo@microsoft.com> | 2021-04-23 10:18:05 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-23 09:18:05 -0500 |
commit | d5cca27a56145a5eb3d2ebad6749989b2fb7dcd3 (patch) | |
tree | 3722759a417229b182ee2a25aa6b0b89736e4771 /cloudinit/sources/DataSourceAzure.py | |
parent | ced836e69274af905bbc1e5f5fde71de4066c86c (diff) | |
download | vyos-cloud-init-d5cca27a56145a5eb3d2ebad6749989b2fb7dcd3.tar.gz vyos-cloud-init-d5cca27a56145a5eb3d2ebad6749989b2fb7dcd3.zip |
Azure: eject the provisioning iso before reporting ready (#861)
Due to hyper-v implementations, iso ejection is more efficient if performed
from within the guest. The code will attempt to perform a best-effort ejection.
Failure during ejection will not prevent reporting ready from happening. If iso
ejection is successful, later iso ejection from the platform will be a no-op.
In the event the iso ejection from the guest fails, iso ejection will still happen at
the platform level.
Diffstat (limited to 'cloudinit/sources/DataSourceAzure.py')
-rwxr-xr-x | cloudinit/sources/DataSourceAzure.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py index 8c7fb021..eac6405a 100755 --- a/cloudinit/sources/DataSourceAzure.py +++ b/cloudinit/sources/DataSourceAzure.py @@ -332,6 +332,7 @@ class DataSourceAzure(sources.DataSource): dsname = 'Azure' _negotiated = False _metadata_imds = sources.UNSET + _ci_pkl_version = 1 def __init__(self, sys_cfg, distro, paths): sources.DataSource.__init__(self, sys_cfg, distro, paths) @@ -346,8 +347,13 @@ class DataSourceAzure(sources.DataSource): # Regenerate network config new_instance boot and every boot self.update_events['network'].add(EventType.BOOT) self._ephemeral_dhcp_ctx = None - self.failed_desired_api_version = False + self.iso_dev = None + + def _unpickle(self, ci_pkl_version: int) -> None: + super()._unpickle(ci_pkl_version) + if "iso_dev" not in self.__dict__: + self.iso_dev = None def __str__(self): root = sources.DataSource.__str__(self) @@ -459,6 +465,13 @@ class DataSourceAzure(sources.DataSource): '%s was not mountable' % cdev, logger_func=LOG.warning) continue + report_diagnostic_event("Found provisioning metadata in %s" % cdev, + logger_func=LOG.debug) + + # save the iso device for ejection before reporting ready + if cdev.startswith("/dev"): + self.iso_dev = cdev + perform_reprovision = reprovision or self._should_reprovision(ret) perform_reprovision_after_nic_attach = ( reprovision_after_nic_attach or @@ -1226,7 +1239,9 @@ class DataSourceAzure(sources.DataSource): @return: The success status of sending the ready signal. """ try: - get_metadata_from_fabric(None, lease['unknown-245']) + get_metadata_from_fabric(fallback_lease_file=None, + dhcp_opts=lease['unknown-245'], + iso_dev=self.iso_dev) return True except Exception as e: report_diagnostic_event( @@ -1332,7 +1347,8 @@ class DataSourceAzure(sources.DataSource): metadata_func = partial(get_metadata_from_fabric, fallback_lease_file=self. dhclient_lease_file, - pubkey_info=pubkey_info) + pubkey_info=pubkey_info, + iso_dev=self.iso_dev) LOG.debug("negotiating with fabric via agent command %s", self.ds_cfg['agent_command']) |