From fe0c153a6d9ba8e8c29da85254b78c6a701b5d29 Mon Sep 17 00:00:00 2001 From: sidaf Date: Wed, 1 Feb 2023 12:12:50 +0000 Subject: [PATCH 1/2] Fixes for pep8: H306: imports not in alphabetical order; pep8: W292 no newline at end of file --- .../metadata/services/vmwareguestinfoservice.py | 15 +++++++++++++++ doc/source/services.rst | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/cloudbaseinit/metadata/services/vmwareguestinfoservice.py b/cloudbaseinit/metadata/services/vmwareguestinfoservice.py index e469c1afd..81533d757 100644 --- a/cloudbaseinit/metadata/services/vmwareguestinfoservice.py +++ b/cloudbaseinit/metadata/services/vmwareguestinfoservice.py @@ -23,6 +23,7 @@ from cloudbaseinit import conf as cloudbaseinit_conf from cloudbaseinit import exception from cloudbaseinit.metadata.services import base +from cloudbaseinit.metadata.services import nocloudservice from cloudbaseinit.osutils import factory as osutils_factory from cloudbaseinit.utils import serialization @@ -151,3 +152,17 @@ def get_admin_username(self): def get_admin_password(self): return self._meta_data.get('admin-password') + + def get_network_details_v2(self): + network_data = self._meta_data.get('network') + if not network_data: + LOG.info("No network configuration found in metadata") + 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 = nocloudservice.NoCloudNetworkConfigV1Parser() + return network_config_parser.parse(network_data.get("config")) + diff --git a/doc/source/services.rst b/doc/source/services.rst index a38b64385..66427790f 100644 --- a/doc/source/services.rst +++ b/doc/source/services.rst @@ -518,6 +518,19 @@ Example metadata in yaml format: public-keys-data: | ssh-key 1 ssh-key 2 + network: + version: 1 + config: + - type: physical + name: interface0 + mac_address: "52:54:00:12:34:00" + subnets: + - type: static + address: 192.168.1.10 + netmask: 255.255.255.0 + dns_nameservers: + - 192.168.1.11 + This metadata content needs to be set as string in the guestinfo dictionary, thus needs to be converted to base64 (it is recommended to @@ -551,6 +564,9 @@ Capabilities: * admin user name * admin user password * user data + * static network configuration (`network config v1 + `_ + format) Config options for `vmwareguestinfo` section: From 15bbbefa9400b9ce88ee2093abe555b4c225add1 Mon Sep 17 00:00:00 2001 From: sidaf Date: Wed, 1 Feb 2023 20:51:36 +0000 Subject: [PATCH 2/2] Update --- .../metadata/services/vmwareguestinfoservice.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cloudbaseinit/metadata/services/vmwareguestinfoservice.py b/cloudbaseinit/metadata/services/vmwareguestinfoservice.py index 81533d757..3d9cff344 100644 --- a/cloudbaseinit/metadata/services/vmwareguestinfoservice.py +++ b/cloudbaseinit/metadata/services/vmwareguestinfoservice.py @@ -158,11 +158,16 @@ def get_network_details_v2(self): if not network_data: LOG.info("No network configuration found in metadata") return - network_data_version = network_data.get("version") + if 'version' not in network_data: + LOG.error("No network version information found in metadata") + 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 + if 'config' not in network_data: + LOG.error("Network configuration does not exist") + return network_config_parser = nocloudservice.NoCloudNetworkConfigV1Parser() return network_config_parser.parse(network_data.get("config")) -