관리-도구
편집 파일: DataSourceVMware.cpython-39.pyc
a '�Dg=� � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl m Z mZmZm Z mZmZ ddlmZ ddlmZ ddlmZmZmZ dZe�e�ZdZd Zd ZdZdZ d Z!dZ"dZ#dZ$dZ%dZ&dZ'dZ(G dd� dej)�Z*dd� Z+dd� Z,dd� Z-dd� Z.dd � Z/d!d"� Z0d#d$� Z1d%d&� Z2d'd(� Z3d)d*� Z4d+d,� Z5d-d.� Z6d/d � Z7d0d1� Z8d2d3� Z9d4d5� Z:d6d7� Z;d8d9� Z<e*ej=ffe*ej=ej>ffgZ?d:d;� Z@d<d=� ZAdOd?d@�ZBdAdB� ZCeDeDdC�dDdE�ZEeDeDdC�dFdG�ZFdHdI� ZGdJdK� ZHdLdM� ZIedNk�r�eI� dS )Pz�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) � N)� atomic_helper�dmi�net�netinfo�sources�util)�loggers)�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�Zedd�� fdd�Zd d � Zdd� Z d d� Z dd� Zdd� Ze dd� �Zdd� Zdd� Zdd� Zdd� Zdd� Zdd � Zd!d"� Z� ZS )$�DataSourceVMwareav 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 transports: 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 j�| ||||� 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# �F/usr/lib/python3.9/site-packages/cloudinit/sources/DataSourceVMware.pyr ` s �zDataSourceVMware.__init__)�ci_pkl_version�returnc sz t � �|� dD ]}t| |�st| |d � qt| d�sBt| di � t| d�svt| dt| jdft| jdft| j dfg� d S )N)r r r r FT) �super� _unpickle�hasattr�setattrr r r r r r )r r% �attr�� __class__r# r$ r( u s* �� ��zDataSourceVMware._unpicklec C s t j�| �}d|| jf S )Nz%s [seed=%s])r r �__str__r )r �rootr# r# r$ r. � s zDataSourceVMware.__str__c C s� d\}}}| j D ]8\}}}|r&t� s&q|� \}}}|s>|s>|r|| _ qJq| js^t�d� dS t�d| �� � tt|��| _ || _ || _| �� | j s�| j s�| jr�dS dS dS )a� _get_data loads the metadata, userdata, and vendordata from one of the following locations in the given order: * envvars * guestinfo * imc Please note when updating this function with support for new data transports, the order should match the order in the dscheck_VMware function from the file ds-identify. �NNNz)failed to find a valid data access methodFzusing data access method %sTN) r �is_vmware_platformr �LOG�debug�info�_get_subplatform�process_metadata�load_json_or_yaml�metadataZuserdata_rawZvendordata_raw�redact_keys)r �md�ud�vdr Zget_data_fnZrequire_vmware_platformr# r# r$ � _get_data� s. � zDataSourceVMware._get_datac C sD t | j�}t�d|� t|| j| j� t�| j|g�| _| � � dS )a( setup(is_new_instance) This is called before user-data and vendor-data have been processed. Unless the datasource has set mode to 'local', then networking per 'fallback' or per 'network_config' will have been written and brought up the OS at this point. zgot host-info: %sN) �wait_on_networkr8 r2 r4 �advertise_local_ip_addrsr r r � mergemanydictZpersist_instance_data)r Zis_new_instance� host_infor# r# r$ �setup� s zDataSourceVMware.setupc C sL d }| j tkrt}n&| j tkr$t}n| j tkr4t}ntjS d| j |d�f S )Nz%s (%s)r8 ) r r �get_guestinfo_envvar_key_namer �get_guestinfo_key_namer �get_imc_key_namer ZMETADATA_UNKNOWN)r Zget_key_name_fnr# r# r$ r5 � s �z!DataSourceVMware._get_subplatformc C s | j S �N)r �r r# r# r$ �get_config_obj� s zDataSourceVMware.get_config_objc C sB d| j v rt�d� nt�d� d| j�� i| j d<