/usr/lib/python3/dist-packages/cloudinit/sources/__pycache__
NameSizeModeActions
DataSourceAkamai.cpython-310.pyc85290644editdlrm
DataSourceAliYun.cpython-310.pyc121310644editdlrm
DataSourceAltCloud.cpython-310.pyc72320644editdlrm
DataSourceAzure.cpython-310.pyc529630644editdlrm
DataSourceBigstep.cpython-310.pyc19580644editdlrm
DataSourceCloudCIX.cpython-310.pyc47660644editdlrm
DataSourceCloudSigma.cpython-310.pyc37920644editdlrm
DataSourceCloudStack.cpython-310.pyc103020644editdlrm
DataSourceConfigDrive.cpython-310.pyc85910644editdlrm
DataSourceDigitalOcean.cpython-310.pyc38830644editdlrm
DataSourceEc2.cpython-310.pyc286660644editdlrm
DataSourceExoscale.cpython-310.pyc61090644editdlrm
DataSourceGCE.cpython-310.pyc101260644editdlrm
DataSourceHetzner.cpython-310.pyc63390644editdlrm
DataSourceIBMCloud.cpython-310.pyc137660644editdlrm
DataSourceLXD.cpython-310.pyc137980644editdlrm
DataSourceMAAS.cpython-310.pyc119180644editdlrm
DataSourceNoCloud.cpython-310.pyc99850644editdlrm
DataSourceNone.cpython-310.pyc14170644editdlrm
DataSourceNWCS.cpython-310.pyc41470644editdlrm
DataSourceOpenNebula.cpython-310.pyc124340644editdlrm
DataSourceOpenStack.cpython-310.pyc81680644editdlrm
DataSourceOracle.cpython-310.pyc147910644editdlrm
DataSourceOVF.cpython-310.pyc94540644editdlrm
DataSourceRbxCloud.cpython-310.pyc75520644editdlrm
DataSourceScaleway.cpython-310.pyc111630644editdlrm
DataSourceSmartOS.cpython-310.pyc253120644editdlrm
DataSourceUpCloud.cpython-310.pyc45220644editdlrm
DataSourceVMware.cpython-310.pyc284110644editdlrm
DataSourceVultr.cpython-310.pyc36410644editdlrm
DataSourceWSL.cpython-310.pyc115500644editdlrm
__init__.cpython-310.pyc324600644editdlrm
Edit: /usr/lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceVMware.cpython-310.pyc (28411B)
o th@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z ddlmZmZmZmZmZmZddlmZmZmZddlmZddlmZddlmZmZm Z d Z!e"e#Z$d Z%d Z&d Z'd Z(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3ej4ej5ej6ej7hiZ8ej4ej6ej7hiZ9gdZ:dZ;ddZZ?d!d"Z@d#d$ZAd%d&ZBd'd(ZCd)d*ZDd+d,ZEd-d.ZFd/d0ZGd1d2ZHd3d4ZId5d6ZJd7d8ZKd9d:ZLd;d ZMdd?ZOd@dAZPdBdCZQdDdEZRe?ejSffe?ejSejTffgZUdFdGZVdHdIZWd\dKdLZXdMdNZYdOeZdPeZfdQdRZ[dOeZdPeZfdSdTZ\dUdVZ]dWdXZ^dYdZZ_e#d[krEe_dSdS)]zCloud-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)DictSet) atomic_helperdminetnetinfosourcesutil) EventScope EventTypeuserdata_to_events)loggers)guestcust_util)ProcessExecutionErrorsubpwhichz/sys/class/dmi/id/product_uuidzNo value foundenvvar guestinfoimcredactzcleanup-guestinfo VMX_GUESTINFOz---z local-ipv4z local-ipv6zwait-on-networkipv4ipv6zcloudinit.updates.supportedzcloudinit.updates.enabled)e1000e1000evlancevmxnet2vmxnet3vrdmaz9 ENV{}=="{}", GOTO="cloudinit_hook" GOTO="cloudinit_end" cCs tjdddkr |St|S)z cache is a wrapper around functools.cache that no-ops when Python is <3.9, the version in which functools.cache was introduced. N) )sys version_info functoolscache)functionr'D/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceVMware.pyr%ms r%cCs|r tdd|SdS)Nz{ID_NET_DRIVER}|) _EXTRA_HOTPLUG_UDEV_RULES_FORMATformatjoin) driver_idsr'r'r(get_extra_hotplug_udev_rulesxs  r.cseZdZdZdZeeZee Z e e Z d,ddZdeddffdd Zd d Zd d ZddZddZddZddZeddZddZddZeddZddZd d!Zd"d#Zd$d%Z d&d'Z!d(d)Z"d*d+Z#Z$S)-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. VMwareNcCsTtj|||||i|_d|_d|_d|_t|jdft |j dft |j dfg|_ dS)NFT)r DataSource__init__cfgdata_access_methodrpctool rpctool_fnDATA_ACCESS_METHOD_ENVVARget_envvar_data_fnDATA_ACCESS_METHOD_GUESTINFOget_guestinfo_data_fnDATA_ACCESS_METHOD_IMCget_imc_data_fn possible_data_access_method_list)selfsys_cfgdistropathsud_procr'r'r(r2s   zDataSourceVMware.__init__ci_pkl_versionreturncst|dD] }t||st||dqt|ds!t|dit|ds;t|dt|jdft|jdft|j dfgt|dsGt t |_ dSdS)N)r5r6r3r=FTextra_hotplug_udev_rules) super _unpicklehasattrsetattrr7r8r9r:r;r<r.DEFAULT_NETWORK_DRIVERSrE)r>rCattr __class__r'r(rGs6         zDataSourceVMware._unpicklecCstj|}d||jfS)Nz %s [seed=%s])rr1__str__r4)r>rootr'r'r(rNs zDataSourceVMware.__str__cCsd\}}}|jD]\}}}|rtsq|\}}}|s|s|r$||_nq|js/tddStd|tt||_ ||_ ||_ | |j sQ|j sQ|j rSdSdS)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 %sT) r=is_vmware_platformr4LOGdebuginfo_get_subplatformprocess_metadataload_json_or_yamlmetadata userdata_rawvendordata_raw redact_keys)r>mdudvdr4 get_data_fnrequire_vmware_platformr'r'r( _get_datas0     zDataSourceVMware._get_datacCsLt|j}td|t||j|jt|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_networkrXrRrTadvertise_local_ip_addrsr5r6r mergemanydictinit_extra_hotplug_udev_rulespersist_instance_data)r>is_new_instance host_infor'r'r(setups  zDataSourceVMware.setupcCs||dS)aactivate(cfg, is_new_instance) This is called before the init_modules will be called but after the user-data and vendor-data have been fully processed. The cfg is fully up to date config, it contains a merged view of system config, datasource config, user config, vendor config. It should be used rather than the sys_cfg passed to __init__. is_new_instance is a boolean indicating if this is a new instance. N)advertise_update_events)r>r3rgr'r'r(activate?szDataSourceVMware.activatecCsLd}|jtkr t}n|jtkrt}n |jtkrt}ntjSd|j|dfS)Nz%s (%s)rX) r4r7get_guestinfo_envvar_key_namer9get_guestinfo_key_namer;get_imc_key_namerMETADATA_UNKNOWN)r>get_key_name_fnr'r'r(rUOs   z!DataSourceVMware._get_subplatformcCs|jSN)r3r>r'r'r(get_config_objbszDataSourceVMware.get_config_objcCsBd|jvr tdntdd|ji|jd<|jddS)Nnetworkzusing metadata network configzusing fallback network configconfig)rXrRrSr@generate_fallback_configrrr'r'r(network_configes     zDataSourceVMware.network_configcCsJt|j}t|di}tt|t|g}t|j||j |j S)Nupdates) copydeepcopydefault_update_eventsr getr rdrjsupported_update_eventsr5r6)r>r3default_events user_eventsenabled_eventsr'r'r(rjps" z(DataSourceVMware.advertise_update_eventscCst|}|r ||_dSdSrq)r.get_network_driversrE)r>rulesr'r'r(res  z.DataSourceVMware.init_extra_hotplug_udev_rulescCs<t}|jrd|jvr|jd}dd|D}td||S)Nznetwork-driverscSsg|]}|dqS) )strip).0sr'r'r( sz8DataSourceVMware.get_network_drivers..zgot network drivers %s)rJrXrRrT)r>network_driversr'r'r(rs   z$DataSourceVMware.get_network_driverscCs<|jr d|jvr |jdStt|jd<|jdS)Nz instance-id)rXr load_text_filePRODUCT_UUID_FILE_PATHrstriplowerrrr'r'r(get_instance_ids   z DataSourceVMware.get_instance_idcCs.|jr|jtkrtrtd|dSdS)Nz"Cache fallback is allowed for : %sTF)r4r;rQrRrSrUrrr'r'r(check_if_fallback_is_alloweds z-DataSourceVMware.check_if_fallback_is_allowedcCs,dD]}||jvrt|j|SqgS)N)zpublic-keys-datapublic_keys_dataz public-keys public_keys)rXrnormalize_pubkey_data)r>key_namer'r'r(get_public_ssh_keyss  z$DataSourceVMware.get_public_ssh_keyscCsPd}t|jvr |jt}n t|jvr|jt}|jtkr&t||j|jdSdSrq)REDACTrXCLEANUP_GUESTINFOr4r9guestinfo_redact_keysr5r6)r>keys_to_redactr'r'r(r[s      zDataSourceVMware.redact_keyscCs:d\}}}tjtdrtd}td}td}|||fS)z< check to see if there is data via env vars rPrXuserdata vendordata)osenvironr|rguestinfo_envvar)r>r\r]r^r'r'r(r8s  z#DataSourceVMware.get_envvar_data_fnc Cs@td}td}|r||_t|_td||r&|s ||_t|_td||js0tddSdd}z||j|jWSty}zWt td |j||r[|j|kr[WYd }~dS|sit d WYd }~dSt d ||_t|_z||j|jWWYd }~Styt td |j|YWYd }~dSwd }~ww) zK check to see if there is data via the guestinfo transport vmtoolsdzvmware-rpctoolzdiscovered vmware-rpctool: %szdiscovered vmtoolsd: %szno rpctool discoveredrPcSsDd\}}}td|td||}td||}td||}|||fS)NrPzquery guestinfo with %srXrr)rRrTr)r5r6r\r]r^r'r'r(query_guestinfos      z?DataSourceVMware.get_guestinfo_data_fn..query_guestinfoz%Failed to query guestinfo with %s: %sNz$vmtoolsd fallback option not presentzfallback to vmtoolsd) rr5exec_vmware_rpctoolr6rRrS exec_vmtoolsd Exceptionr logexcrT)r>rvmware_rpctoolrerrorr'r'r(r:sZ       z&DataSourceVMware.get_guestinfo_data_fnc Csd\}}}t|j}t|j}|s|std|||fSts(|||fSt|j}|dur7|||fSt j |}t |}t |\} } | rh|rhtdt|jj|jd|||j\}}}|_n| rz|rztdt|\}}}ntdt||||fS)zN check to see if there is data via vmware guest customization rPz-Customization for VMware platform is disabledNz3Getting data via VMware customization configurationscriptszFGetting data via VMware raw cloudinit data customization configurationz1No allowed customization configuration data found)ris_vmware_cust_enabledr?is_raw_data_cust_enabledds_cfgrRrSis_cust_plugin_availableget_cust_cfg_filerpathdirnameparse_cust_cfgget_cust_cfg_typeget_data_from_imc_cust_cfgrA cloud_dir get_cpathr@r3#get_data_from_imc_raw_data_cust_cfgr del_dir) r>r\r]r^allow_vmware_custallow_raw_data_cust cust_cfg_file cust_cfg_dircust_cfgis_vmware_cust_cfgis_raw_data_cust_cfgr'r'r(r<sL              z DataSourceVMware.get_imc_data_fnrq)%__name__ __module__ __qualname____doc__dsnameryrzSUPPORTED_UPDATE_EVENTSr}DEFAULT_UPDATE_EVENTSr{r.rJrEr2intrGrNrarirkrUrspropertyrwrjrer%rrrrr[r8r:r< __classcell__r'r'rLr(r/s:$   9         Lr/cCs>td}|durtddSd|vrtddSdS)Nzsystem-product-namezNo system-product-name foundFvmwarezNot a VMware platformT)r read_dmi_datarRrSr) system_typer'r'r(rQWs    rQcCsvtd||d}|dvrtd||tt|}n|dvr.td||t|}ntd||}t|S)z decode returns the decoded string value of data key is a string used to identify the data being decoded in log messages z'Getting encoded data for key=%s, enc=%sN)z gzip+base64zgz+b64zDecoding %s format %s)base64b64zPlain-text data %s)rRrSr decomp_gziprb64d decode_binary)keyenc_typedataraw_datar'r'r(decodebs   rcCs&t|}|}|r|tkrdS|S)a  get_none_if_empty_val returns None if the provided value, once stripped of its trailing whitespace, is empty or equal to GUESTINFO_EMPTY_YAML_VAL. The return value is always a string, regardless of whether the input is a bytes class or a string. N)r rrGUESTINFO_EMPTY_YAML_VAL)valr'r'r(get_none_if_empty_valws  rcCsh|r|r|sdS|t}|rtt|||td||t}|r2tt|||td|dSdS)z advertise_local_ip_addrs gets the local IP address information from the provided host_info map and sets the addresses in the guestinfo namespace Nz-advertised local ipv4 address %s in guestinfoz-advertised local ipv6 address %s in guestinfo)r| LOCAL_IPV4guestinfo_set_valuerRrT LOCAL_IPV6)rhr5r6 local_ipv4 local_ipv6r'r'r(rcs    rccCsh|r|sdSdd}||}|rtt|||td|||}|r0tt|||td|||fS)a advertise_update_events publishes the types of supported and enabled events to guestinfo. The string returned from this method adheres to the following format: SCOPE=TYPE[;TYPE][,SCOPE=TYPE[;TYPE]] For example: * network=boot;hotplug * network=boot-new-instance The only supported event scope at the moment is network, but there may be more scopes in the future, and this format will support them. )NNc SsJg}|D]\}}tdd|D}|d|d|qd|S)Ncss|]}t|VqdSrq)str)r event_typer'r'r( s zEadvertise_update_events..get_events_string..z{}={};,)itemssortedappendr+r,)eventsevent_scopes_and_types_list event_scope event_typesevent_types_listr'r'r(get_events_strings z2advertise_update_events..get_events_stringz3advertised supported update events in guestinfo: %sz1advertised enabled update events in guestinfo: %s)r&SUPPORTED_UPDATE_EVENTS_GUEST_INFO_KEYrRrT$ENABLED_UPDATE_EVENTS_GUEST_INFO_KEY)r}enabled_update_eventsr5r6rsupported_events_stringenabled_events_stringr'r'r(rjs8 rjcCs t|}|r|Std|dS)z handle_returned_guestinfo_val returns the provided value if it is not empty or set to GUESTINFO_EMPTY_YAML_VAL, otherwise None is returned No value found for key %sN)rrRrS)rrr'r'r(handle_returned_guestinfo_vals  rcCsdS)Nz vmware-toolsr'rr'r'r(rnsrncCsd|S)Nz guestinfo.r'rr'r'r(rmsrmcCsdt|dddS)Nzvmx.._)rmupperreplacerr'r'r(rlsrlcCs,t|}|sdSt|d}tt|||S)N .encoding)guestinfo_envvar_get_valuerrl)rrrr'r'r(rs  rcCst|}t|tj|dS)Nr)rlrrrr|)renv_keyr'r'r(rsrcCst||g\}}||fSrqrr5argstdoutstderrr'r'r(rsrcCst|d|g\}}||fS)Nz--cmdrrr'r'r(r srcCs4t|||}|s dSt|d||}tt|||S)zj guestinfo returns the guestinfo value for the provided key, decoding the value when required Nr)guestinfo_get_valuerrm)rr5r6rrr'r'r(rs c Cstd|z$||dt|\}}|tkrtd|n|s%td|t||WStyS}z|jtkr>td|n t td|||WYd}~dSd}~wt yh}z t td|||d}~ww)z: Returns a guestinfo value for the specified key. z"Getting guestinfo value for key %sz info-get rz(Failed to get guestinfo value for key %sz,Failed to get guestinfo value for key %s: %sNzCUnexpected error while trying to get guestinfo value for key %s: %s) rRrSrmNOVALrrrrr rr)rr5r6rrrr'r'r(rsB      rc Cs|dkrd}td||z||dt||fWdSty7}zttd|||WYd}~dSd}~wtyHttd||YdSw) z| Sets a guestinfo value for the specified key. Set value to an empty string to clear an existing guestinfo key. rrz$Setting guestinfo key=%s to value=%szinfo-set %s %sTz.Failed to set guestinfo key=%s to value=%s: %sNzAUnexpected error while trying to set guestinfo key=%s to value=%s)rRrSrmrr rr)rvaluer5r6rr'r'r(rFs6  rcCs|sdSt|ttfvr|g}|D].}t|}td|t|t||s*td|td|t|dd||s?td|qdS)z guestinfo_redact_keys redacts guestinfo of all of the keys in the given list. each key will have its value set to "---". Since the value is valid YAML, cloud-init can still read it if it tries. Nz clearing %szfailed to clear %szclearing %s.encodingrrzfailed to clear %s.encoding) typelisttuplermrRrTrrr)keysr5r6rrr'r'r(rqs     rc CsF|siSt|tr |Szt|WStjtfy"t|YSw)z load first attempts to unmarshal the provided data as JSON, and if that fails then attempts to unmarshal the data as YAML. If data is None then a new dictionary is returned. ) isinstancedictr load_jsonjsonJSONDecodeError TypeError load_yaml)rr'r'r(rWs  rWcCs|siSd}d|vr|d}|d=d}d|vr|d}|d=|rPt|tjjr4tddt|i}ntd|td||}dt |i}td|||d<|S) z_ process_metadata processes metadata and loads the optional network configuration. Nrtznetwork.encodingz#network data copied to 'config' keyruznetwork data to be decoded %szmetadata.networkznetwork data %s) r collectionsabcMappingrRrSryrzrrW)rrt network_encdec_netr'r'r(rVs*    rVcCs t|tS)zK Return a list of data sources that match this set of dependencies )rlist_from_depends datasources)dependsr'r'r(get_datasource_lists rc Csd}d}t}|dD]}|ddkr|d}nq |dD]}|ddkr-|d}nqd}d}t}||vr`||d}t|dkrNtd ||nt|dkr`d |d vr`|d d }||vr||d}t|dkrxtd ||nt|dkrd |d vr|d d }|dur|dur|D]'}||dD]} | d |krt||ddkr||dd d }nqq|dur|dur|D]'}||dD]} | d |krt||ddkr||dd d }nqq||fS) aI Returns the default IPv4 and IPv6 addresses based on the device(s) used for the default route. Please note that None may be returned for either address family if that family has no default route or if there are multiple addresses associated with the device used by the default route for a given address. Nr destination0.0.0.0ifacerz::/0z,device %s has more than one ipv4 address: %siprz,device %s has more than one ipv6 address: %s)r route_info netdev_infolenrRrS) ipv4_ifipv6_ifroutesrouterrnetdevaddrsdev_nameaddrr'r'r(get_default_ip_addrss^             r%rcCst|}|r |dkrt}zt|ddtjdtj}Wn tjy'Y|Sw|D] }|dr7|d}|Sq*|S)zoGet fully qualified domain name from name. An empty argument is interpreted as meaning the local host. rNrr )rr get_hostnamesocket getaddrinfo SOCK_DGRAM AI_CANONNAMEr)namer"r$r'r'r(getfqdn s$ r,cCs&ttj|}|o|jp|jp|j S)zn Returns false if the address is loopback, link local or unspecified; otherwise true is returned. )rmaybe_get_address ipaddress ip_address is_link_local is_loopbackis_unspecified)rr$r'r'r(is_valid_ip_addr!sr3r$rDcCs,|dsiS|d|d|ddS)a Takes a cloudinit.netinfo formatted address and converts to netifaces format, since this module was originally written with netifaces as the network introspection module. netifaces ipv4 format: { "broadcast": "10.15.255.255", "netmask": "255.240.0.0", "addr": "10.0.1.4" } cloudinit.netinfo ipv4 format: { "ip": "10.0.1.4", "mask": "255.240.0.0", "bcast": "10.15.255.255", "scope": "global", } rbcastmask) broadcastnetmaskr$)r|)r$r'r'r( convert_to_netifaces_ipv4_format,s r8cCs>|dsiSt|d}|jd|jjt|jdS)a Takes a cloudinit.netinfo formatted address and converts to netifaces format, since this module was originally written with netifaces as the network introspection module. netifaces ipv6 format: { "netmask": "ffff:ffff:ffff:ffff::/64", "addr": "2001:db8:abcd:1234::1" } cloudinit.netinfo ipv6 format: { "ip": "2001:db8:abcd:1234::1/64", "scope6": "global", } r/)r7r$)r|r. IPv6Interfacer7rt prefixlenrr)r$rr'r'r( convert_to_netifaces_ipv6_formatHs r<cCsddtttdii}tt}|r$||d<||d<||d<t\}}|r/||t<|r5||t<|ddd}|ddd}|ddd }t }|D]}g} g} ||d D] } | t | q_||d D] } | t | qo|| d } | d krqS| r| s| r| } i}| rg}| D]}t|dsq| |q||d <| rg}| D]}t|dsq| |q||d <||| <| r| D]}|d} t| sqt|}|d=| r| |d<||| <q| r | D]}|d} t| sqt|}|d=| r| |d<||| <qqS|S)zP Returns host information such as the host name and network interfaces. rt interfaces)by-macby-ipv4by-ipv6hostnamezlocal-hostnamelocal_hostnamer>r?r@rrhwaddrz00:00:00:00:00:00r$mac)r  OrderedDictr,r r&r%rrrrrr8r<r|r3ryrz)rhrA default_ipv4 default_ipv6by_macby_ipv4by_ipv6ifacesr#af_inet4af_inet6r$rDrr af_inet4_valsip_info af_inet6_valsr'r'r( get_host_infoas           rQc Cs6d}d}t|vr6|t}t|vr!|t}t|tr|}nt|}t|vr6|t}t|tr1|}nt|}d\}}}|durt}|dpHi} | dpOi} | dpVi} | dp]i} |rn| rht | dknd}|snd}|r~| rxt | dknd}|s~d}|durt d||||t d |dus?t d |S) NF)NFFrtr=r?r@rzs        Z ?  ,+ $ B X8