From 27aeec5a1dec62a4218e3bcbe84dd110a96138ba Mon Sep 17 00:00:00 2001 From: Eifoen <35534229+Eifoen@users.noreply.github.com> Date: Tue, 2 Jan 2024 14:00:23 +0100 Subject: [PATCH] Add network metadata support for vmware metadata service - Added parsing of vmware metadata as NetworkDetailsV2 - Using NoCloudNetworkConfigV1Parser for parsing the data - Functionality is analog to cloud-init --- .../services/vmwareguestinfoservice.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cloudbaseinit/metadata/services/vmwareguestinfoservice.py b/cloudbaseinit/metadata/services/vmwareguestinfoservice.py index e469c1afd..15bbb7af6 100644 --- a/cloudbaseinit/metadata/services/vmwareguestinfoservice.py +++ b/cloudbaseinit/metadata/services/vmwareguestinfoservice.py @@ -25,6 +25,7 @@ from cloudbaseinit.metadata.services import base from cloudbaseinit.osutils import factory as osutils_factory from cloudbaseinit.utils import serialization +from cloudbaseinit.metadata.services.nocloudservice import NoCloudNetworkConfigV1Parser CONF = cloudbaseinit_conf.CONF LOG = oslo_logging.getLogger(__name__) @@ -151,3 +152,23 @@ def get_admin_username(self): def get_admin_password(self): return self._meta_data.get('admin-password') + + def get_network_details_v2(self): + try: + raw_data = self._meta_data.get('network-config', decode=True) + network_data = serialization.parse_json_yaml(raw_data) + except base.NotExistingMetadataException: + LOG.info("V2 network metadata not found") + return + except serialization.YamlParserConfigError: + LOG.exception("V2 network metadata could not be deserialized") + return + + network_data_version = network_data.get('version') + if network_data_version != 1: + LOG.error("Network data version '%s' is not supported", + network_data_version) + return + + network_config_parser = NoCloudNetworkConfigV1Parser() + return network_config_parser.parse(network_data.get("config"))