summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAndrew Kutz <101085+akutz@users.noreply.github.com>2021-08-09 21:24:07 -0500
committerGitHub <noreply@github.com>2021-08-09 20:24:07 -0600
commit8b4a9bc7b81e61943af873bad92e2133f8275b0b (patch)
tree500881356564dacf85a8ff9cf0bc602b8069eda8 /tools
parent049d62b658b06e729291def6b7b6f9520827d0ba (diff)
downloadvyos-cloud-init-8b4a9bc7b81e61943af873bad92e2133f8275b0b.tar.gz
vyos-cloud-init-8b4a9bc7b81e61943af873bad92e2133f8275b0b.zip
Datasource for VMware (#953)
This patch finally introduces the Cloud-Init Datasource for VMware GuestInfo as a part of cloud-init proper. This datasource has existed since 2018, and rapidly became the de facto datasource for developers working with Packer, Terraform, for projects like kube-image-builder, and the de jure datasource for Photon OS. The major change to the datasource from its previous incarnation is the name. Now named DatasourceVMware, this new version of the datasource will allow multiple transport types in addition to GuestInfo keys. This datasource includes several unique features developed to address real-world situations: * Support for reading any key (metadata, userdata, vendordata) both from the guestinfo table when running on a VM in vSphere as well as from an environment variable when running inside of a container, useful for rapid dev/test. * Allows booting with DHCP while still providing full participation in Cloud-Init instance data and Jinja queries. The netifaces library provides the ability to inspect the network after it is online, and the runtime network configuration is then merged into the existing metadata and persisted to disk. * Advertises the local_ipv4 and local_ipv6 addresses via guestinfo as well. This is useful as Guest Tools is not always able to identify what would be considered the local address. The primary author and current steward of this datasource spoke at Cloud-Init Con 2020 where there was interest in contributing this datasource to the Cloud-Init codebase. The datasource currently lives in its own GitHub repository at https://github.com/vmware/cloud-init-vmware-guestinfo. Once the datasource is merged into Cloud-Init, the old repository will be deprecated.
Diffstat (limited to 'tools')
-rw-r--r--tools/.github-cla-signers1
-rwxr-xr-xtools/ds-identify76
2 files changed, 76 insertions, 1 deletions
diff --git a/tools/.github-cla-signers b/tools/.github-cla-signers
index 3c2c6d14..5089dd70 100644
--- a/tools/.github-cla-signers
+++ b/tools/.github-cla-signers
@@ -1,5 +1,6 @@
ader1990
ajmyyra
+akutz
AlexBaranowski
Aman306
andrewbogott
diff --git a/tools/ds-identify b/tools/ds-identify
index 73e27c71..234ffa81 100755
--- a/tools/ds-identify
+++ b/tools/ds-identify
@@ -125,7 +125,7 @@ DI_DSNAME=""
# be searched if there is no setting found in config.
DI_DSLIST_DEFAULT="MAAS ConfigDrive NoCloud AltCloud Azure Bigstep \
CloudSigma CloudStack DigitalOcean Vultr AliYun Ec2 GCE OpenNebula OpenStack \
-OVF SmartOS Scaleway Hetzner IBMCloud Oracle Exoscale RbxCloud UpCloud"
+OVF SmartOS Scaleway Hetzner IBMCloud Oracle Exoscale RbxCloud UpCloud VMware"
DI_DSLIST=""
DI_MODE=""
DI_ON_FOUND=""
@@ -1364,6 +1364,80 @@ dscheck_Vultr() {
return $DS_NOT_FOUND
}
+vmware_has_envvar_vmx_guestinfo() {
+ [ -n "${VMX_GUESTINFO:-}" ]
+}
+
+vmware_has_envvar_vmx_guestinfo_metadata() {
+ [ -n "${VMX_GUESTINFO_METADATA:-}" ]
+}
+
+vmware_has_envvar_vmx_guestinfo_userdata() {
+ [ -n "${VMX_GUESTINFO_USERDATA:-}" ]
+}
+
+vmware_has_envvar_vmx_guestinfo_vendordata() {
+ [ -n "${VMX_GUESTINFO_VENDORDATA:-}" ]
+}
+
+vmware_has_rpctool() {
+ command -v vmware-rpctool >/dev/null 2>&1
+}
+
+vmware_rpctool_guestinfo_metadata() {
+ vmware-rpctool "info-get guestinfo.metadata"
+}
+
+vmware_rpctool_guestinfo_userdata() {
+ vmware-rpctool "info-get guestinfo.userdata"
+}
+
+vmware_rpctool_guestinfo_vendordata() {
+ vmware-rpctool "info-get guestinfo.vendordata"
+}
+
+dscheck_VMware() {
+ # Checks to see if there is valid data for the VMware datasource.
+ # The data transports are checked in the following order:
+ #
+ # * envvars
+ # * guestinfo
+ #
+ # Please note when updating this function with support for new data
+ # transports, the order should match the order in the _get_data
+ # function from the file DataSourceVMware.py.
+
+ # Check to see if running in a container and the VMware
+ # datasource is configured via environment variables.
+ if vmware_has_envvar_vmx_guestinfo; then
+ if vmware_has_envvar_vmx_guestinfo_metadata || \
+ vmware_has_envvar_vmx_guestinfo_userdata || \
+ vmware_has_envvar_vmx_guestinfo_vendordata; then
+ return "${DS_FOUND}"
+ fi
+ fi
+
+ # Do not proceed unless the detected platform is VMware.
+ if [ ! "${DI_VIRT}" = "vmware" ]; then
+ return "${DS_NOT_FOUND}"
+ fi
+
+ # Do not proceed if the vmware-rpctool command is not present.
+ if ! vmware_has_rpctool; then
+ return "${DS_NOT_FOUND}"
+ fi
+
+ # Activate the VMware datasource only if any of the fields used
+ # by the datasource are present in the guestinfo table.
+ if { vmware_rpctool_guestinfo_metadata || \
+ vmware_rpctool_guestinfo_userdata || \
+ vmware_rpctool_guestinfo_vendordata; } >/dev/null 2>&1; then
+ return "${DS_FOUND}"
+ fi
+
+ return "${DS_NOT_FOUND}"
+}
+
collect_info() {
read_uname_info
read_virt