add network configuration options via vmware extra_config key
Signed-off-by: Jeremy Kimber <jeremy.kimber@garmin.com> Change-Id: If18ad9d04b9b07a0c061d039334d3dcef67721e1
This commit is contained in:
parent
04c642408b
commit
ee8402f040
|
@ -23,6 +23,7 @@ from oslo_log import log as oslo_logging
|
||||||
from cloudbaseinit import conf as cloudbaseinit_conf
|
from cloudbaseinit import conf as cloudbaseinit_conf
|
||||||
from cloudbaseinit import exception
|
from cloudbaseinit import exception
|
||||||
from cloudbaseinit.metadata.services import base
|
from cloudbaseinit.metadata.services import base
|
||||||
|
from cloudbaseinit.metadata.services import nocloudservice
|
||||||
from cloudbaseinit.osutils import factory as osutils_factory
|
from cloudbaseinit.osutils import factory as osutils_factory
|
||||||
from cloudbaseinit.utils import serialization
|
from cloudbaseinit.utils import serialization
|
||||||
|
|
||||||
|
@ -151,3 +152,22 @@ class VMwareGuestInfoService(base.BaseMetadataService):
|
||||||
|
|
||||||
def get_admin_password(self):
|
def get_admin_password(self):
|
||||||
return self._meta_data.get('admin-password')
|
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
|
||||||
|
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"))
|
||||||
|
|
|
@ -187,3 +187,14 @@ class VMwareGuestInfoServiceTest(unittest.TestCase):
|
||||||
mock_get_guestinfo_value.return_value = "no encoding"
|
mock_get_guestinfo_value.return_value = "no encoding"
|
||||||
self.assertRaises(exception.CloudbaseInitException,
|
self.assertRaises(exception.CloudbaseInitException,
|
||||||
self._service._get_guest_data, 'fake_key')
|
self._service._get_guest_data, 'fake_key')
|
||||||
|
|
||||||
|
@ddt.data(({}, None),
|
||||||
|
({'version': 2}, None),
|
||||||
|
({'version': 1}, None))
|
||||||
|
@ddt.unpack
|
||||||
|
def test_get_network(self, network_data, expected_return_value):
|
||||||
|
self._service._meta_data = {
|
||||||
|
"network": network_data
|
||||||
|
}
|
||||||
|
config = self._service.get_network_details_v2()
|
||||||
|
self.assertEqual(config, expected_return_value)
|
||||||
|
|
|
@ -518,6 +518,18 @@ Example metadata in yaml format:
|
||||||
public-keys-data: |
|
public-keys-data: |
|
||||||
ssh-key 1
|
ssh-key 1
|
||||||
ssh-key 2
|
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
|
This metadata content needs to be set as string in the guestinfo
|
||||||
dictionary, thus needs to be converted to base64 (it is recommended to
|
dictionary, thus needs to be converted to base64 (it is recommended to
|
||||||
|
@ -551,6 +563,9 @@ Capabilities:
|
||||||
* admin user name
|
* admin user name
|
||||||
* admin user password
|
* admin user password
|
||||||
* user data
|
* user data
|
||||||
|
* static network configuration (`network config v1
|
||||||
|
<https://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v1.html>`_
|
||||||
|
format)
|
||||||
|
|
||||||
Config options for `vmwareguestinfo` section:
|
Config options for `vmwareguestinfo` section:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue