�
܍~c�p � � � d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl m
Z
ddl mZ ddl m
Z
mZmZ ddlmZmZmZ dZ ej e� � ZdZd Zd
Z ed� � ZdZd
ZdZdZdZ dZ!dZ"dZ#dZ$ G d� dej% � � Z&d� Z'd� Z(d� Z)d� Z*d� Z+d� Z,d� Z-d� Z.efd�Z/efd �Z0efd!�Z1efd"�Z2d#� Z3d$� Z4e&ej5 ffe&ej5 ej6 ffgZ7d%� Z8d&� Z9d.d(�Z:d)� Z;d*� Z<d+� Z=d,� Z>ed-k r e>� � dS dS )/a� Cloud-Init DataSource for VMware
This module provides a cloud-init datasource for VMware systems and supports
multiple transports types, including:
* EnvVars
* GuestInfo
Netifaces (https://github.com/al45tair/netifaces)
Please note this module relies on the netifaces project to introspect the
runtime, network configuration of the host on which this datasource is
running. This is in contrast to the rest of cloud-init which uses the
cloudinit/netinfo module.
The reasons for using netifaces include:
* Netifaces is built in C and is more portable across multiple systems
and more deterministic than shell exec'ing local network commands and
parsing their output.
* Netifaces provides a stable way to determine the view of the host's
network after DHCP has brought the network online. Unlike most other
datasources, this datasource still provides support for JINJA queries
based on networking information even when the network is based on a
DHCP lease. While this does not tie this datasource directly to
netifaces, it does mean the ability to consistently obtain the
correct information is paramount.
* It is currently possible to execute this datasource on macOS
(which many developers use today) to print the output of the
get_host_info function. This function calls netifaces to obtain
the same runtime network configuration that the datasource would
persist to the local system's instance data.
However, the netinfo module fails on macOS. The result is either a
hung operation that requires a SIGINT to return control to the user,
or, if brew is used to install iproute2mac, the ip commands are used
but produce output the netinfo module is unable to parse.
While macOS is not a target of cloud-init, this feature is quite
useful when working on this datasource.
For more information about this behavior, please see the following
PR comment, https://bit.ly/3fG7OVh.
The authors of this datasource are not opposed to moving away from
netifaces. The goal may be to eventually do just that. This proviso was
added to the top of this module as a way to remind future-us and others
why netifaces was used in the first place in order to either smooth the
transition away from netifaces or embrace it further up the cloud-init
stack.
� N)�dmi)�log)�net�sources�util)�ProcessExecutionError�subp�whichz/sys/class/dmi/id/product_uuidzNo value found�envvar� guestinfozvmware-rpctool�redactzcleanup-guestinfo�
VMX_GUESTINFOz---z
local-ipv4z
local-ipv6zwait-on-network�ipv4�ipv6c �X � e Zd ZdZdZdd�Zd� Zd� Zd� Ze d� � � Z
d � Zd
� Zd� Z
dS )
�DataSourceVMwarea�
Setting the hostname:
The hostname is set by way of the metadata key "local-hostname".
Setting the instance ID:
The instance ID may be set by way of the metadata key "instance-id".
However, if this value is absent then the instance ID is read
from the file /sys/class/dmi/id/product_uuid.
Configuring the network:
The network is configured by setting the metadata key "network"
with a value consistent with Network Config Versions 1 or 2,
depending on the Linux distro's version of cloud-init:
Network Config Version 1 - http://bit.ly/cloudinit-net-conf-v1
Network Config Version 2 - http://bit.ly/cloudinit-net-conf-v2
For example, CentOS 7's official cloud-init package is version
0.7.9 and does not support Network Config Version 2. However,
this datasource still supports supplying Network Config Version 2
data as long as the Linux distro's cloud-init package is new
enough to parse the data.
The metadata key "network.encoding" may be used to indicate the
format of the metadata key "network". Valid encodings are base64
and gzip+base64.
�VMwareNc �r � t j � | ||||� � d | _ t | _ d S �N)r �
DataSource�__init__�data_access_method�VMWARE_RPCTOOL�vmware_rpctool)�self�sys_cfg�distro�paths�ud_procs �D/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceVMware.pyr zDataSourceVMware.__init__� s7 � ���#�#�D�'�6�5�'�J�J�J�"&���,����� c �� � d\ }}}t j � t d� � r?t d� � }t d� � }t d� � }|s|s|rt
| _ | j sdt j d� � }|�t �
d� � d S d
|� � � vrt �
d� � d S | j sX| j rQt d| j � � }t d| j � � }t d| j � � }|s|s|rt | _ | j st � d� � d S t � d
| � � � � � t% t' |