3 �~�f-� � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl mZmZm Z mZmZmZ ddlmZ ddlmZmZmZ dZeje�ZdZdZd Zd ZdZdZ d Z!dZ"dZ#dZ$dZ%dZ&dZ'G dd� dej(�Z)dd� Z*dd� Z+dd� Z,dd� Z-dd� Z.d d!� Z/d"d#� Z0d$d%� Z1d&d'� Z2d(d)� Z3d*d+� Z4d,d-� Z5d.d � Z6d/d0� Z7d1d2� Z8d3d4� Z9d5d6� Z:d7d8� Z;e)ej<ffe)ej<ej=ffgZ>d9d:� Z?d;d<� Z@dId>d?�ZAd@dA� ZBdBdC� ZCdDdE� ZDdFdG� ZEedHk�r�eE� dS )Ja� Cloud-Init DataSource for VMware This module provides a cloud-init datasource for VMware systems and supports multiple transports types, including: * EnvVars * GuestInfo * IMC (Guest Customization) 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)� atomic_helper�dmi�log�net�sources�util)�guestcust_util)�ProcessExecutionError�subp�whichz/sys/class/dmi/id/product_uuidzNo value foundZenvvar� guestinfoZimcZredactzcleanup-guestinfo� VMX_GUESTINFOz---z local-ipv4z local-ipv6zwait-on-network�ipv4�ipv6c @ s� e Zd ZdZdZd dd�Zdd� Zdd � Zd d� Zdd � Z dd� Z edd� �Zdd� Z dd� Zdd� Zdd� Zdd� Zdd� Zdd� ZdS )!�DataSourceVMwareau 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. imc transport: Either Network Config Version 1 or Network Config Version 2 is supported which depends on the customization type. For LinuxPrep customization, Network config Version 1 data is parsed from the customization specification. For CloudinitPrep customization, Network config Version 2 data is parsed from the customization specification. envvar and guestinfo tranports: Network Config Version 2 data is supported 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. ZVMwareNc C sT t jj| ||||� i | _d | _d | _d | _t| jdft | j dft| jdfg| _ d S )NFT)r � DataSource�__init__�cfg�data_access_method�rpctool� rpctool_fn�DATA_ACCESS_METHOD_ENVVAR�get_envvar_data_fn�DATA_ACCESS_METHOD_GUESTINFO�get_guestinfo_data_fn�DATA_ACCESS_METHOD_IMC�get_imc_data_fn� possible_data_access_method_list)�self�sys_cfg�distro�pathsZud_proc� r"