summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/reporting/handlers.py15
-rw-r--r--cloudinit/sources/DataSourceAzure.py16
2 files changed, 30 insertions, 1 deletions
diff --git a/cloudinit/reporting/handlers.py b/cloudinit/reporting/handlers.py
index 2c1f4998..ff07f940 100644
--- a/cloudinit/reporting/handlers.py
+++ b/cloudinit/reporting/handlers.py
@@ -347,6 +347,21 @@ class HyperVKvpReportingHandler(ReportingHandler):
break
return result_array
+ def write_key(self, key: str, value: str) -> None:
+ """Write KVP key-value.
+
+ Values will be truncated as needed.
+ """
+ if len(value) >= self.HV_KVP_AZURE_MAX_VALUE_SIZE:
+ value = value[0 : self.HV_KVP_AZURE_MAX_VALUE_SIZE - 1]
+
+ data = [self._encode_kvp_item(key, value)]
+
+ try:
+ self._append_kvp_item(data)
+ except (OSError, IOError):
+ LOG.warning("failed posting kvp=%s value=%s", key, value)
+
def _encode_event(self, event):
"""
encode the event into kvp data bytes.
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index d0af2089..969cb376 100644
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -25,7 +25,7 @@ from cloudinit.net.dhcp import (
NoDHCPLeaseMissingDhclientError,
)
from cloudinit.net.ephemeral import EphemeralDHCPv4
-from cloudinit.reporting import events
+from cloudinit.reporting import events, handlers, instantiated_handler_registry
from cloudinit.sources.azure import errors, identity, imds
from cloudinit.sources.helpers import netlink
from cloudinit.sources.helpers.azure import (
@@ -1175,6 +1175,20 @@ class DataSourceAzure(sources.DataSource):
return reprovision_data
@azure_ds_telemetry_reporter
+ def _report_failure_to_host(self, error: errors.ReportableError) -> bool:
+ """Report failure to host via well-known key."""
+ value = error.as_description()
+ kvp_handler = instantiated_handler_registry.registered_items.get(
+ "telemetry"
+ )
+ if not isinstance(kvp_handler, handlers.HyperVKvpReportingHandler):
+ LOG.debug("KVP handler not enabled, skipping host report.")
+ return False
+
+ kvp_handler.write_key("PROVISIONING_REPORT", value)
+ return True
+
+ @azure_ds_telemetry_reporter
def _report_failure(self, error: errors.ReportableError) -> bool:
"""Tells the Azure fabric that provisioning has failed.