/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__/DataSourceAzure.cpython-310.pyc (52963B)
o th5 @sUddlZddlZddlZddlZddlZddlZddlZddlmm Z ddl m Z ddl mZddlmZmZmZddlmZmZmZmZddlZddlmZmZmZmZmZmZddlm Z ddl!m"Z"m#Z#dd l$m%Z%dd l&m'Z'm(Z(m)Z)dd l*m+Z+m,Z,dd l-m.Z.dd l/m0Z0m1Z1m2Z2m3Z3ddl4m5Z5ddl6m7Z7m8Z8m9Z9m:Z:m;Z;mZ>m?Z?m@Z@mAZAmBZBmCZCddlDmEZEzddlFZFejGeFjFdejHdddZIeeJd<Wn$eKeLfyz ddlMZNeNjOjPjOZIWn eKyddZIYnwYnweQeRZSdZTddiZUdZVdZWdZXdZYGddde ZZd Z[ee\eJd!<gd"Z]d#d$Z^d%d&Z_d'e\d(e\d)ee\fd*d+Z`d,e\d)e\fd-d.Zae;d)ee\fd/d0Zbe;d,e\d)ee\fd1d2Zcdd)e\fd3d4Zdd5d6Zed7d8Zfd9d:Zgd)ee\fd;d<Zheird=ZWehd>ZjejdureSkd?d@ejZVneSkdAdZ[eXdBeVidCdCdDZldBdEdFgdCdGieWdHdIgdJZmdKeTgZndLZodMZpGdNdOdOejqZrdPdQZsdRdSZtdTdUZudVdWZvdXdYZwddZd[Zxe;d\d]Zye;d^d_Zze;eVd`d`fdae\dbe\dce{dde{fdedfZ|e;ddgdhZ}e;didjZ~dkdlZe;dmdnZe;e[fdodpZe;dqdrZe;dsdtZe;duedve{d)efdwdxZe;d)efdydzZe;dd{d|ZerZerejffgZd}d~ZdS)N)Enum)Path) monotonicsleeptime)AnyDictListOptional)net performancesourcesssh_utilsubputil) cc_mounts) EventScope EventType) device_driver)NoDHCPLeaseErrorNoDHCPLeaseInterfaceErrorNoDHCPLeaseMissingDhclientError)EphemeralDHCPv4EphemeralIPv4Network)events)errorsidentityimdskvp)netlink) DEFAULT_WIRESERVER_ENDPOINTNonAzureDataSource OvfEnvXmlazure_ds_reporterazure_ds_telemetry_reporterbuild_minimal_ovf dhcp_log_cbget_boot_telemetryget_metadata_from_fabricget_system_inforeport_diagnostic_eventreport_dmesg_to_kvpreport_failure_to_fabric)UrlErrorz$6$)strlen)salt blowfish_hashcCstd)zRaise when called so that importing this module doesn't throw ImportError when ds_detect() returns false. In this case, crypt and passlib are not needed. z/crypt and passlib not found, missing dependency) ImportError)_r4C/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceAzure.pyr1AsAzure instance-idziid-AZURE-NODEz/dev/disk/cloud/azure_resourceext4z/var/lib/waagentz/dev/sr0c@s eZdZdZdZdZdZdZdS)PPSTypeNonePreprovisionedOSDiskRunningSavableUnknownN)__name__ __module__ __qualname__NONEOS_DISKRUNNINGSAVABLEUNKNOWNr4r4r4r5r9Xs r9z/sys/firmware/acpi/tables/OEM0PLATFORM_ENTROPY_SOURCE)z"/etc/netplan/90-hotplug-azure.yamlz /usr/local/sbin/ephemeral_eth.shz+/etc/udev/rules.d/10-net-device-added.rulesz#/run/network/interfaces.ephemeral.dcCs|D]9}td|r=|}t|dkr=|dd}t|dkr=|ddkr=|d|r=|dd}|dSqd S) z dev.storvsc.1.%pnpinfo: classid=32412632-86cb-44a2-9b5c-50d1417354f5 deviceid=00000000-0001-8899-0000-000000000000 pnpinfo=rdeviceid.N) splitlinesresearchsplitlen startswith) sysctl_outrLlinefieldscolumnscompsr4r4r5"find_storvscid_from_sysctl_pnpinfols       rZcCs2|D]}t||r|}|dSqdS)z scbus0 on ata0 bus 0 scbus1 on ata1 bus 0 scbus2 on blkvsc0 bus 0 scbus3 on blkvsc1 bus 0 scbus4 on storvsc2 bus 0 scbus5 on storvsc3 bus 0 scbus-1 on xpt0 bus 0 rN)rOrPrQrR)camcontrol_outdisk_drvrVitemsr4r4r5find_busdev_from_disks  r^r[busdevreturncCsN|D] }t||r$|d}t|dkr$|dd}|dSqdS)z at scbus1 target 0 lun 0 (cd0,pass0) at scbus2 target 0 lun 0 (da0,pass1) at scbus3 target 1 lun 0 (da1,pass2) (rJrM,rN)rOrPrQrRrS)r[r_rVr]dev_passr4r4r5find_dev_from_busdevs     rdmacc CsZt|dkr)d|dd|dd|dd|dd|dd|ddg}|S) z1Normalize mac address with colons and lower-case. :rrJ )rSjoinlowerrer4r4r5normalize_mac_addresss >rocCsddtDS)z-Get Hyper-V NICs as normalized MAC addresses.cSs$g|]}|ddkrt|dqS)rJ hv_netvscrMro).0nr4r4r5 s   z1get_hv_netvsc_macs_normalized..)r get_interfacesr4r4r4r5get_hv_netvsc_macs_normalizedsrvcsffddtD}d|vrdSt|dkr&td|ftjd|dStd|ftjdd S) z0Determine the device driver to match on, if any.cs$g|]}t|dkr|dqS)rMrJrqrrirnr4r5rts z3determine_device_driver_for_mac..rprMz4Assuming driver for interface with mac=%s drivers=%r logger_funcrz=Unable to specify driver for interface with mac=%s drivers=%rN)r rurSr*LOGdebugwarning)redriversr4rnr5determine_device_driver_for_macs(  rc Cs:zt|jWStjytdd||YSw)NzFailed to execute: %s )rstdoutProcessExecutionErrorr{r|rl)cmdfail_retr4r4r5execute_or_debugs rcCstddgddS)Nsysctlz dev.storvsc)rrr4r4r4r5get_dev_storvsc_sysctlrcCs tgdS)N) camcontroldevlistz-brr4r4r4r5get_camcontrol_dev_bus rcCs tddgS)Nrrrr4r4r4r5get_camcontrol_devrrc Csd}|dkr d}|d}dt|}d||}t}t||}|s)tddSt}t}d|}t||} | rMt || } | durKtd dS| Sd |} t|| } | rkt || } | duritd dS| SdS) N00000000rM00000001rJ000z{0}-{1}z#Fail to find storvsc id from sysctlz blkvsc{0}zFail to find /dev/daXz storvsc{0}) strformatrrZr{r|rrr^rd) port_idg0g1g0g1rU storvscidcamcontrol_b_outr[blkvscscbusxdevnamestorvscr4r4r5get_resource_disk_on_freebsds<            rz freebsd-ufsrMzresource disk is not None/dev/zresource disk is None ephemeral0T)data_dir disk_aliasesapply_network_config&apply_network_config_for_secondary_ipsgptd) table_typelayout overwritez ephemeral0.1) filesystemdevice) disk_setupfs_setup datasourcenever_destroy_ntfsREDACTEDc sTeZdZdZejejejhiZ dZ e j Z dZddZdeddffd d Zd d Zd dZededefddZeddddddeededededef ddZedddZdefddZddd Zed!d"Zed#edefd$d%Z dfd'd( Z!ed)d*Z"ed+d,Z#d-d.Z$d/d0Z%ede&efd1d2Z'd3e(de&efd4d5Z)de&efd6d7Z*d8d9Z+d:d;Z,dd?Z.ed@dAZ/e CddDedEede0fdFdGZ1edHdIZ2edddJdKedLeddfdMdNZ3edOdPZ4ede5j5fdQdRZ6edSdTZ7eddUdVZ8edWdXZ9edYdZZ:ede;fd[d\Zd^edefd_d`Z?eddadbee&edee&efdcddZ@d3e(deefdedfZAdge(d3e(deBfdhdiZCedjdkZDedle(d3e(dee&efdmdnZEdodpZFedqdrZGeHdsdtZIedudvZJeHdwdxZKeHdydzZLed3e(defd{d|ZMd}d~ZNddZOZPS)DataSourceAzurer6FrMcCstj||||tj|jd|_i|_d|_t t |t it g|_d|_d|_d|_tj|jdd|_d|_d|_d|_d|_t|_dS)Nazuredatareported_readyF)r DataSource__init__ospathrlseed_dircfgseedr mergemanydictget_cfg_by_path DS_CFG_PATHBUILTIN_DS_CONFIGds_cfg_iso_dev_network_config_ephemeral_dhcp_ctx cloud_dir_reported_ready_marker_file_route_configured_for_imds _route_configured_for_wireserver _system_uuid_vm_idr _wireserver_endpoint)selfsys_cfgdistropathsr4r4r5rEs$ zDataSourceAzure.__init__ci_pkl_versionr`NcsPt|d|_d|_tj|jjdd|_ d|_ d|_ d|_ d|_ t|_dS)NrrF)super _unpicklerrrrrlrrrrrrrr r)rr __class__r4r5rYs   zDataSourceAzure._unpicklecCstj|}d||jfS)Nz %s [seed=%s])r r__str__r)rrootr4r4r5rgs zDataSourceAzure.__str__cCsH|jdurd}n|jdrd}n |jdkrd}nd}d||jfS)z/Return the subplatform metadata source details.Nunknownz/devz config-diskrzseed-dirz%s (%s))rrTrm)rsubplatform_typer4r4r5_get_subplatformks  z DataSourceAzure._get_subplatformephipv4cCs<|jsdSdd|jD}d|v|_|j|v|_|jp|jS)NFcSsg|] }|dddqS)r/)rR)rrrr4r4r5rt}sz5DataSourceAzure._check_if_primary..z169.254.169.254) static_routesrrr)rrrouted_networksr4r4r5_check_if_primaryws z!DataSourceAzure._check_if_primaryT)ifacereport_failure_if_not_primary retry_sleeptimeout_minutesrrrrc Cs|jdur tdtd|tftjdt|j|t d|_d}t }||d}t j ddt d |durz|j}Wnty]td tjd|jtjt |d d d Ynotyntdtjdd|_tytd|tjd|jtjt ||dd d Yn>ty}ztd|tjdWYd}~n(d}~wtjy}ztd|j|j|j|jftjdWYd}~nd}~ww|durt ||krt|nn|dus8|durd|_t|d}||j_ d|vr|d|_!t"|} |jj#} | dur td|$| } td|| | | j%| j&||j'|j(ftjd|r>| s>|jtj)|| | j%| j&|dd d | WdS1sKwYdS)aSetup ephemeral networking. Keep retrying DHCP up to specified number of minutes. This does not kill dhclient, so the timeout in practice may be up to timeout_minutes + the system-configured timeout for dhclient. :param timeout_minutes: Number of minutes to keep retrying for. :raises NoDHCPLeaseError: If unable to obtain DHCP lease. :returns: True if NIC is determined to be primary. Nz/Bringing up networking when already configured.z2Bringing up ephemeral networking with iface=%s: %rry)r dhcp_log_func<zobtain-dhcp-leasezobtain dhcp leasename descriptionparentzInterface not found for DHCP)durationT host_onlyzdhclient executable not foundz&Failed to obtain DHCP lease (iface=%s))r interfacezFile not found during DHCP %rz7Command failed: cmd=%r stderr=%r stdout=%r exit_code=%srz unknown-245zdhcp context missing ephipv4z{Obtained DHCP lease on interface %r (primary=%r driver=%r router=%r routes=%r lease=%r imds_routed=%r wireserver_routed=%r))rdriverrouterrlease)*r RuntimeErrorr*r rur{r|rrr&rrReportEventStackr# obtain_leaserr}_report_failurer$ReportableErrorDhcpInterfaceNotFoundrerrorrReportableErrorDhcpLeaseFileNotFoundErrorrrrstderrr exit_coderrrr_ephipv4rrrrr(ReportableErrorDhcpOnNonPrimaryInterface) rrrrrr start_timedeadlinerrrprimaryr4r4r5_setup_ephemeral_networkings          :      &z+DataSourceAzure._setup_ephemeral_networkingcCs.d|_d|_|jdur dS|jd|_dS)zTeardown ephemeral networking.FN)rrr clean_networkrr4r4r5_teardown_ephemeral_networking$s    z.DataSourceAzure._teardown_ephemeral_networkingcCs|jdup |jjdu S)z"Check if networking is configured.N)rrrr4r4r5_is_ephemeral_networking_up/s  z+DataSourceAzure._is_ephemeral_networking_upc Cszgd}t|\}}td|||ftjdWdStjye}z>t|jtr8tdt }| |n"td|j |j |j|jftjdt |}| |WYd}~dSWYd}~dSd}~ww)abCheck if azure-proxy-agent is ready for communication with WS/IMDS. If ProvisionGuestProxyAgent is true, query azure-proxy-agent status, waiting up to 120 seconds for the proxy to negotiate with Wireserver and configure an eBPF proxy. Once azure-proxy-agent is ready, it will exit with code 0 and cloud-init can then expect to be able to communicate with these services. Fail deployment if azure-proxy-agent is not found or otherwise returns an error. For more information, check out: https://github.com/azure/guestproxyagent )zazure-proxy-agentz--statusz--wait120z1Executing %s resulted in stderr=%r with stdout=%rryzGFailed to activate Azure Guest Proxy Agent: azure-proxy-agent not foundzgFailed to activate Azure Guest Proxy Agent: status check failed cmd=%r stderr=%r stdout=%r exit_code=%sN)rr*r{r|r isinstancereasonrrr!ReportableErrorProxyAgentNotFoundrrrrr&ReportableErrorProxyAgentStatusFailure)rrouterrr report_errorreportable_errorr4r4r5_check_azure_proxy_agent_status6s@     z/DataSourceAzure._check_azure_proxy_agent_statusc Cs |td|j|jftjdi}|jd}d}ddi}ddd diii}d}i}t|j|D]`}z:| d rWt rIt j |t d d \}}}}n t |t \}}}}||_nt |\}}}}|}td |tjdWn-ty~td|tjdYq0t jytd|tjdYq0wd} t| tjdt|jp|du} | rdnd} z|j| dWn tyYnwi} |r|dr||jdd} | s|durd} t| t| ||| } | tjkrgt rd} t| tjdt| |sd} t| tjdt| | tj kr|!n| tj"kr(|#n| tj$kr3|%n|&|'\}}}}|drI||jdd} |(| }|dtjj)fvrg|*t+j,d|d|j-| d|pqd|_.|/||t 0|d| ig|dt1| }t2| }t3| }|rtd |||ddd <|rtd!|||d"d<|durtd#|| |d$d%<|j.dkr|d&szt4|||d'}d(|i|d&<Wnt5y}ztd)|tjdWYd}~nd}~ww|s(t6| }|r(td*zt78d9|:|d+<Wnt5y'td,tjdYnw||kr6td-|tjdt;}|rB||d"d.<|<|d"d/<|j=d0ur|r|j>|| d1}z|j?|d2}Wn t5yoY|Swtd3||r||d"d4<|@|S)5aWalk all instance metadata sources returning a dict on success. @return: A dictionary of any metadata content for this instance. @raise: InvalidMetaDataException when the expected metadata service is unavailable, broken or disabled. zAzure VM ID: %s System UUID: %sryrNlocal-hostnamer system_info default_userrrudf)mtypez!Found provisioning metadata in %sz$Did not find Azure data source in %sz%s was not mountablezUnable to find provisioning media, falling back to IMDS metadata. Be aware that IMDS metadata does not support admin passwords or custom-data (user-data only).rrProvisionGuestProxyAgentT)report_failurezNo OVF or IMDS availablez%Free BSD is not supported for PPS VMszDHCP failed while in source PPSzextended.compute.ppsType)keyvalue)imds_mdIMDSr)rfilesmetadata userdata_rawz Username retrieved from IMDS: %sz Hostname retrieved from IMDS: %srz(Disable password retrieved from IMDS: %sr ssh_pwauthr)usernamehostnamedisable_ssh_password_auth ovf-env.xmlz)Failed to construct OVF from IMDS data %szRetrieved userdata from IMDSrzBad userdata in IMDSzusing files cached in %s random_seedr7F)rr pubkey_infoznegotiating returned %s public-keys)A _query_vm_idr*rrr{inforlist_possible_azure_dsrrTr is_FreeBSDmount_cbload_azure_ds_dirrr|r!MountFailedErrorr}boolrrrgetrget_metadata_from_imdsr InvalidMetaDataException_determine_pps_typer9rBrrD_wait_for_pps_running_reuserE_wait_for_pps_savable_reuserC_wait_for_pps_os_disk_shutdown_wait_for_pps_unknown_reuse _reprovision_ppstype_from_imdsrrr"ReportableErrorImdsInvalidMetadatavalidate_imds_network_metadatarupdater_username_from_imds_hostname_from_imds_disable_password_from_imdsr% Exception_userdata_from_imdsbase64 b64decoderlrR_get_random_seed_iid _negotiated!_determine_wireserver_pubkey_info _report_ready_cleanup_markers)r crawled_dataddir ovf_sourcemdrrrsrcmsgrequires_imds_metadatarrpps_type imds_ppstype imds_username imds_hostnameimds_disable_passwordcontentse imds_userdatarr'ssh_keysr4r4r5crawl_metadatalsL                                         zDataSourceAzure.crawl_metadatarc Cst}|d}|js d}nd}d}d}ztj||dWStyI}z"t|}t|}tj||d}|js?t|j t j r?d}WYd}~n d}~wt yd}zt|}tj |d}WYd}~nd}~ww|j|| dtd|tjd iS) Ni, )max_connection_errorsretry_deadline) exceptionrFr_rz!Ignoring IMDS metadata due to: %sry)rrr fetch_metadata_with_api_fallbackr-rrReportableErrorImdsUrlErrorrcauserequestsConnectionError ValueError+ReportableErrorImdsMetadataParsingExceptionrr*r{r}) rrrr^r] error_string error_reportrrr4r4r5r2KsH z&DataSourceAzure.get_metadata_from_imdsr4cstt||tj|_dS)z.Reset any cached class attributes to defaults.N)rrclear_cached_attrsr UNSET_metadata_imds)r attr_defaultsrr4r5rjys z"DataSourceAzure.clear_cached_attrscCs4tj}|dur dS|jdurdSt|jdS)zQCheck platform environment to report if this datasource may run. NTFr$)rChassisAssetTag query_systemrrexists)r chassis_tagr4r4r5 ds_detect~s  zDataSourceAzure.ds_detectc CsztWnty}z td|WYd}~nd}~wwztWnty;}z td|WYd}~nd}~wwzLz|}Wn?tjya}z||WYd}~W| dSd}~wty}zt |}||WYd}~W| dSd}~wwW| n| w|j r|j j dkr|j drtt}tj|rtd|tjdt|d tg|_ntd |tjd|d |_|d d |_t|d tg|_|d |_t|j d|ddddS)zCrawl and process datasource metadata caching metadata as attrs. @return: True on success, False on error, invalid or disabled datasource. z Failed to get boot telemetry: %sNz$Failed to get system information: %sFubunturzXEphemeral resource disk '%s' exists. Merging default Azure cloud ephemeral disk configs.ryrzdEphemeral resource disk '%s' does not exist. Not merging default Azure cloud ephemeral disk configs.rrrrri)dirmodeT)r'rAr{r}r)r[rReportableErrorrr!ReportableErrorUnhandledExceptionrrrr1*maybe_remove_ubuntu_network_config_scriptsRESOURCE_DISK_PATHrrrpr*r|rr#BUILTIN_CLOUD_EPHEMERAL_DISK_CONFIGrrlDEFAULT_METADATArr write_files)rrXrKrrdevpathr4r4r5 _get_datasz                  zDataSourceAzure._get_datacCs&|jrd|jvr |St|jdS)Nr7)rrFrrr4r4r5get_instance_idszDataSourceAzure.get_instance_idcCs|jd|S)Nr)rr1)rrr4r4r5device_name_to_devicerz%DataSourceAzure.device_name_to_devicec Cs0z ||jdWSttfyY|Sw)z+ Retrieve public SSH keys. r)_get_public_keys_from_imdsrKeyErrorrf_get_public_keys_from_ovfrr4r4r5get_public_ssh_keyss z#DataSourceAzure.get_public_ssh_keysrcCsz dd|ddD}Wntyd}t|tjdwtdd|Dr5d }t|tjdt|d t|}t|tjd|S) zGet SSH keys from IMDS metadata. :raises KeyError: if IMDS metadata is malformed/missing. :raises ValueError: if key format is not supported. :returns: List of keys. cSg|]}|dqS)keyDatar4)rr public_keyr4r4r5rtsz>DataSourceAzure._get_public_keys_from_imds..compute publicKeysz"No SSH keys found in IMDS metadatarycss|] }t|d VqdS))rN)_key_is_openssh_formatted)rrrr4r4r5 sz=DataSourceAzure._get_public_keys_from_imds..zKey(s) not in OpenSSH formatzRetrieved {} keys from IMDS)rr*r{r|anyrfrrS)rrrZlog_msgr4r4r5rs   z*DataSourceAzure._get_public_keys_from_imdscCsXg}z|jd}dt|}t|tjdW|Sty+d}t|tjdY|Sw)zYGet SSH keys that were fetched from wireserver. :returns: List of keys. r(zRetrieved {} keys from OVFryzNo keys available from OVF)rrrSr*r{r|r)rrZrr4r4r5rs  z)DataSourceAzure._get_public_keys_from_ovfcCs|jSNrrr4r4r5get_config_objszDataSourceAzure.get_config_objcCst|Sr)r instance_id_matches_system_uuidr~)rrr4r4r5check_instance_idsz!DataSourceAzure.check_instance_idc Cs|jszt|_Wnty}ztj|dd}~ww|js?z t|j|_WdSty>}ztj||jdd}~wwdS)zQuery the system UUID and VM IDs, if needed. They are initialized to None, check only if they are unset. Raise as reportable error on failure. r`N)r_ system_uuid) rrquery_system_uuidrrReportableErrorVmIdentificationrconvert_system_uuid_to_vm_idrfrrr4r4r5r)s&  zDataSourceAzure._query_vm_idcCs`|tj|jdd}tj|r-t| }t |j }| |j |fvr-|S|j S)Nrr7)r)rrrlr get_cpathrprload_text_filestriprbyte_swap_system_uuidrrm)rprevious prev_iid_path swapped_idr4r4r5rF3s   zDataSourceAzure._iidc Csz;d}tjddtd t|}Wdn1swY|dur0d}t|tjdWdStd|tjdWdSt yQ}z tt |tj dd}~ww)zUse the netlink socket provided to wait for nic detach event. NOTE: The function doesn't close the socket. The caller owns closing the socket and disposing it safely. Nzwait-for-nic-detachzwait for nic detachrzHPreprovisioned nic not detached as expected. Proceeding without failing.ryz%The preprovisioned nic %s is detached) rrr#rwait_for_nic_detach_eventr*r{r}r|AssertionErrorrr)rnl_sockifnamerPrr4r4r5_wait_for_nic_detachEs,  z$DataSourceAzure._wait_for_nic_detachr皙?rretriescCsft|D]}|jj|rtd|tjddS|d|kr#t|qtd|||ftjddS)NzThe link %s is up.ryrMz;The link %s is not up after %f seconds, continuing anyways.)ranger networkingtry_set_link_upr*r{r*r)rrrrrxr4r4r5wait_for_link_upes     z DataSourceAzure.wait_for_link_upcCs@|j}td|t|djttdt dtj ddS)Nz*Creating a marker file to report ready: %sz{pid}: {time} )pidrzRSuccessfully created reported ready marker file while in the preprovisioning pool.ry) rr{r*r write_filerrgetpidrr*r|)rrr4r4r5_create_report_ready_markerys  z+DataSourceAzure._create_report_ready_marker) create_markerexpect_url_errorrrc Csz|Wn3ty9}z'|r t|tr tdtjdd|_nd}t|tjdt ||WYd}~nd}~wwd|_ |rE| dSdS)zReport ready for PPS, creating the marker file upon completion. :raises sources.InvalidMetaDataException: On error reporting ready. z,Ignoring http call failure, it was expected.ryNz9Failed reporting ready while in the preprovisioning pool.F) rIrArr-r*r{r|rrr r3rGr)rrrrrPr4r4r5_report_ready_for_ppss(    z%DataSourceAzure._report_ready_for_ppsc Cstdz[g}d} d}tjddt|tdt||}Wdn1s*wY||t d|tjd | ||sRtd ||j |d dd }|r\td WdS| q t y|}zt t|tjd WYd}~dSd}~ww)z6Wait until the primary nic for the vm is hot-attached.z*Waiting for primary nic to be hot-attachedFTNzwait-for-nic-attachz4wait for nic attach after %d nics have been attachedrzDetected nic %s attached.ryz!Checking if %s is the primary nicr)rrrzFound primary nic for this VM.)r{r*rrrSr#rwait_for_nic_attach_eventappendr*rrrrrr)rr nics_foundprimary_nic_foundrrr4r4r5"_wait_for_hot_attached_primary_nicsL      * z2DataSourceAzure._wait_for_hot_attached_primary_nicc Cs<ztWStjy}z td|tjdd}~ww)Nz!Failed to create netlink socket: ry)rcreate_bound_netlink_socketNetlinkCreateSocketErrorr*r{rrr4r4r5_create_bound_netlink_sockets z,DataSourceAzure._create_bound_netlink_socketcCs*|jddtdtjdtdt)z4Report ready and wait for host to initiate shutdown.F)rz"Waiting for host to shutdown VM...ryi3)rr*r{r*rrReportableErrorOsDiskPpsFailurerr4r4r5r7s z.DataSourceAzure._wait_for_pps_os_disk_shutdownc Cs|}z_|jdus|jjdurtd|jj}|td|tjddt d,zt ||Wnt yN}zt d|tjdWYd}~nd}~wwWdn1sYwYW|n|w|dS) z9Report ready and wait for nic link to switch upon re-use.Nzmissing ephemeral contextz#Wait for vnetswitch to happen on %sz!wait-for-media-disconnect-connectzwait for vnet switchrz'Error while waiting for vnet switch: %sry)rrrrrr{r|rrr#r!wait_for_media_disconnect_connectrr*rcloser)rrrrXr4r4r5r5s<   z+DataSourceAzure._wait_for_pps_running_reusec Cs|}z=|jddz|Wntjy0}ztd|tjdd|_WYd}~nd}~ww| || |W| dS| w)z@Report ready and wait for nic(s) to be hot-attached upon re-use.T)rzLIgnoring failure while tearing down networking, NIC was likely unplugged: %rryN) rrrrrr*r{r*rrrr)rrrXr4r4r5r6"s$    z+DataSourceAzure._wait_for_pps_savable_reusecCs&tj|jr dS||dS)z0Report ready if needed for unknown/recovery PPS.N)rrisfilerrrrr4r4r5r88s z+DataSourceAzure._wait_for_pps_unknown_reusec Csd}d}|sT|s |d7}z|jddWn tyYqwtjddtd"zt}WntyB| YWdqwWdn1sMwY|rt d |t j d |S) z0Poll IMDs for reprovisiondata XML document data.rNrMrrzget-reprovision-data-from-imdszget reprovision data from imdsrz#attempted dhcp %d times after reusery) rrrrrr#rfetch_reprovision_datar-rr*r{r|)r dhcp_attemptsreprovision_datar4r4r5 _poll_imdsDs<   zDataSourceAzure._poll_imdsrrc Cs0|j|jd}td|tjdtt|}|r|S|rQztdtj dt |j |dd|_ WdSt yP}ztd|tjdWYd}~nd}~wwz*td tj d|z|jd d Wn tynYnwt |j |dd|_ WdSt y}ztd |tj dWYd}~d Sd}~ww)aReport failure to Azure host and fabric. For errors that may be recoverable (e.g. DHCP), host_only provides a mechanism to report the failure that can be updated later with success. DHCP will not be attempted if host_only=True and networking is down. @param error: Error to report. @param host_only: Only report to host (error may be recoverable). @return: The success status of sending the failure signal. vm_idz#Azure datasource failure occurred: ryz>Using cached ephemeral dhcp context to report failure to Azure)endpointencoded_reportTz@Failed to report failure using cached ephemeral dhcp context: %sNz3Using new ephemeral dhcp to report failure to Azurerrz5Failed to report failure using new ephemeral dhcp: %sF)as_encoded_reportrr*r{rr+rreport_via_kvprr|r,rrGrArrr)rrrrreportedrXr4r4r5rbsn  zDataSourceAzure._report_failurer&r'c Cslttj|jdz t|j|j|j|d}Wnty-}z t d|t j dd}~wwd|_d|_ |S)zTells the fabric provisioning has completed. :param pubkey_info: Fingerprints of keys to request from Wireserver. :raises Exception: if failed to report. :returns: List of SSH keys, if requested. r)rriso_devr'zQError communicating with Azure fabric; You may experience connectivity issues: %sryNT) r+rreport_success_to_hostrr(rrrrAr*r{r}rG)rr'rrXr4r4r5rIs,   zDataSourceAzure._report_readyc CsLz |dddWSty%}ztd|tjdWYd}~dSd}~ww)NextendedrppsTypez2Could not retrieve pps configuration from IMDS: %sry)rAr*r{r|)rrrXr4r4r5r:sz"DataSourceAzure._ppstype_from_imdsovf_cfgcCstj|jr tj}nO|ddtjjks| |tjjkr"tj}n8|ddtj jks5| |tj jkr9tj }n!|ddusS|ddtj jksS| |tj jkrWtj }ntj }t d|jtjd|S)z@Determine PPS type using OVF, IMDS data, and reprovision marker.PreprovisionedVMTypeNPreprovisionedVmTz PPS type: %sry)rrrrr9rFr1rErr:rCrDrBr*r{r*)rrrrRr4r4r5r4s&  z#DataSourceAzure._determine_pps_typecCsZ|}tjddtdt|\}}}|||d|ifWdS1s&wYdS)zrInitiate the reprovisioning workflow. Ephemeral networking is up upon successful reprovisioning. zreprovisioning-read-azure-ovfz$read azure ovf during reprovisioningrr$N)rrrr#read_azure_ovf)rrWrNudrr4r4r5r9s$zDataSourceAzure._reprovisionrc Csbd}z||W|Sttfy0|dd}d|dur#t|nd}t|tjdY|Sw)zDetermine the fingerprints we need to retrieve from Wireserver. :return: List of keys to request from Wireserver, if any, else None. N_pubkeysz"Retrieved {} fingerprints from OVFrry) rrrfr1rrSr*r{r|)rrrr'rr4r4r5rHs  z1DataSourceAzure._determine_wireserver_pubkey_infocCst|jdS)zCleanup any marker files.N)rdel_filerrr4r4r5rJsz DataSourceAzure._cleanup_markerscCs8|j}zt|||jtddWtdStw)NF)is_new_instance preserve_ntfs)r get_ipath_curaddress_ephemeral_resizerr1DS_CFG_KEY_PRESERVE_NTFSr+)rrr instance_dirr4r4r5activates  zDataSourceAzure.activatecC|jdididS)NrrplatformFaultDomainrr1rr4r4r5availability_zone$s z!DataSourceAzure.availability_zonec Cs|jr8|jtjkr8|jdr8zt|jd|jddWSty7}ztdt |WYd}~nd}~wwzt WStyW}ztdt |WYd}~iSd}~ww)z:Generate network configuration according to configuration.rnetworkr)rz?Failed generating network config from IMDS network metadata: %sNz-Failed generating fallback network config: %s) rlr rkrr16generate_network_config_from_instance_network_metadatarAr{rr-_generate_network_config_from_fallback_config)rrXr4r4r5_generate_network_config,s4  z(DataSourceAzure._generate_network_configcCs(|jr |jtjkr |jS||_|jS)z,Provide network configuration v2 dictionary.)rr rkrrr4r4r5network_configKs zDataSourceAzure.network_configcCr)Nrrlocationrrr4r4r5regionUszDataSourceAzure.regioncst}z|d}dd|dDWnty(td|dtjdYdSwfdd|D}|s6d Std ||ftjd|jrH|jjsJdSt |jj}|rXt |t sZdSt |}||vrmtd ||ftjddS) z=Validate IMDS network config and report telemetry for errors.rcSsg|]}t|dqS) macAddressrqrwr4r4r5rt`s zBDataSourceAzure.validate_imds_network_metadata..rz6IMDS network metadata has incomplete configuration: %rryFcsg|]}|vr|qSr4r4)rrm imds_macsr4r5rtlsTz>IMDS network metadata is missing configuration for NICs %r: %rz3IMDS network metadata is missing primary NIC %r: %r) rvrr*r1r{r}rrr get_interface_macrrro)rr local_macsr missing_macs primary_macr4rr5r<YsL z.DataSourceAzure.validate_imds_network_metadatacCsttdS)z Remove resource disk entries from fstab, which are configured by cloud-init i.e. lines containing "/dev/disk/cloud/azure_resource" and cloudconfig comment. N)r cleanup_fstabrxrr4r4r5_cleanup_resourcedisk_fstabsz+DataSourceAzure._cleanup_resourcedisk_fstabcCs |dSr)rrr4r4r5cleans zDataSourceAzure.clean)r`N)r4r)rr)F)Qr?r@rAdsnamerNETWORKrBOOT_NEW_INSTANCEBOOTdefault_update_eventsrGr rkrl_ci_pkl_versionrintrrrr$rr0rr rrrrrr[rr2rjrrr}r~rr rdictrrrrr)rFrfloatrrrrsocketrr7r5r6r8bytesrrrurrIr:r9r4r9rHrJrpropertyrrrrr<rr __classcell__r4r4rr5r9s    6 _-  H       & 8  $    D   "         /rcC(z |dddWStyYdSw)Nr osProfile adminUsernamer imds_datar4r4r5r>  r>cCs$z|ddWStyYdSw)NruserDatarrr4r4r5rBs  rBcCr)Nrr computerNamerrr4r4r5r?rr?cCs,z |ddddkWStyYdSw)NrrdisablePasswordAuthenticationtruerrr4r4r5r@s r@cCsFd|vrdSt}z||}Wn tyYdSw|jduS)z? Validate whether or not the key is OpenSSH-formatted. z FN)rrAuthKeyLineParserparse TypeErrorkeytype)rparseraklr4r4r5rs   rcCs`dD]+}g}td|D]}||t|}tj|r&||tj|fq |r-|SqgS)N)z-partprrM)rrrrrprrealpath)r|maxnumsufffoundpnumppathr4r4r5_partitions_on_devices rcCs*tjddd}td|tj||vS)Nz TYPE=ntfsT)no_cachezntfs_devices found = %s)rfind_devs_withr{r|rrr)r| ntfs_devicesr4r4r5_has_ntfs_filesystems rc Cs|rddttf}d|fStj|sdd|fStd|tj|t |}|s2dd|fSt |}|dkrLd|d d d |Df}d|fS|dkrW|d \}}n|d \}}t |sld|||f}d|fSt dd}d|||f}t jddtdy} ztj||dddidd} Wn@tjy} z3d| _dt| vrd|dfWYd} ~ WdSd|d|| ffWYd} ~ WdSd} ~ ww| d krd| | _tddttd|d | fWdSWdn1swYd|d!fS)"aDetermine if the ephemeral drive at devpath should be reformatted. A fresh ephemeral disk is formatted by Azure and will: a.) have a partition table (dos or gpt) b.) have 1 partition that is ntfs formatted, or have 2 partitions with the second partition ntfs formatted. (larger instances with >2TB ephemeral disk have gpt, and will have a microsoft reserved partition as part 1. LP: #1686514) c.) the ntfs partition will have no files other than possibly 'dataloss_warning_readme.txt' User can indicate that NTFS should never be destroyed by setting DS_CFG_KEY_PRESERVE_NTFS in dscfg. If data is found on NTFS, user is warned to set DS_CFG_KEY_PRESERVE_NTFS to make sure cloud-init does not accidentally wipe their data. If cloud-init cannot mount the disk to check for data, destruction will be allowed, unless the dscfg key is set.z:config says to never destroy NTFS (%s.%s), skipping checksrNFzdevice %s does not existzResolving realpath of %s -> %szdevice %s was not partitionedrJz&device %s had 3 or more partitions: %srcSr)rMr4)rrr r4r4r5rtsz*can_dev_be_reformatted..rMrz5partition %s (%s) on device %s was not ntfs formattedcs(tddgtfddt|DS)Nzdataloss_warning_readme.txtzsystem volume informationcsg|] }|vr|qSr4)rm)rrfignoredr4r5rtsz?can_dev_be_reformatted..count_files..)setrSrlistdir)mpr4rr5 count_filessz+can_dev_be_reformatted..count_filesz1partition %s (%s) on device %s was ntfs formattedzmount-ntfs-and-countrntfsLANGC)rupdate_env_for_mount log_errorzcannot mount ntfszunknown filesystem type 'ntfs'Tz^ but this system cannot mount NTFS, assuming there are no important files. Formatting allowed.Nz but mount of %s failed: %szmounted and counted %d fileszxit looks like you're using NTFS on the ephemeral disk, to ensure that filesystem does not get wiped, set %s.%s in configz but had %d files on it.z3 and had no important files. Safe for reformatting.)rlrrrrrpr{r|rrrSrr$rrr#rr-r/rrr}) r|rrP partitions partition_len cand_part cand_pathrbmsgevt file_countrXr4r4r5can_dev_be_reformatteds          %r,Frr|rrc Cstj|std|tjddStd|tjdd}d}|r%d\}}nt||\}}td|||s7dSdD]E}tj|dd |}d ||f}tj|rxz t|td |Wq9t yw} z t d || WYd} ~ q9d} ~ wwtd |q9dS)Nz,Ephemeral resource disk '%s' does not exist.ryz$Ephemeral resource disk '%s' exists.F)TzFirst instance boot.zreformattable=%s: %s)rmountssemconfig_zMarker "%s" for module "%s"z %s removed.z%s: remove failed! (%s)z%s did not exist.) rrrpr*r{r|r,rlunlinkrr}) rr|rrresultrPmodsempathr)rXr4r4r5rKs>     rcCsjdd}|sdS|s i}t|||D]\}}tj||}d|vr*|||}tj||ddqdS)NcSsbzt|}|D]}d|jvr|jtkrt|_q t|WSty0t d||YSw)z>Azure provides the UserPassword in plain text. So we redact it UserPasswordz#failed to redact userpassword in %s) ET fromstringitertagtextDEF_PASSWD_REDACTIONtostringrAr{critical)cntfnamerelemr4r4r5_redact_passwordys       z%write_files.._redact_passwordr$i)filenamecontentmode)r ensure_dirr]rrrlr)datadirrrtr@rrBr>r4r4r5r{ws  r{cCst|}i}i}|jp d}|jr|j|d<|jr|j|d<|jdur*|j |d<n|jr1d|d<i}|jr;|j|d<|jrNd|d <t|jkrNt |j|d <|rVd |i|d <|j |d <t d|j t j d|j|d<t d|jt j d|j|d<t d|jt j d|||fS)zParse OVF XML contents. :return: Tuple of metadata, configuration, userdata dicts. :raises NonAzureDataSource: if XML is not in Azure's format. :raises errors.ReportableError: if XML is unparsable or invalid. rrrNr TrF lock_passwd hashed_passwdrrrzPreprovisionedVm: %sryrzPreprovisionedVMType: %srzProvisionGuestProxyAgent: %s)r" parse_text custom_datar" public_keysr#passwordr!r: encrypt_passpreprovisioned_vmr*r{r*preprovisioned_vm_typeprovision_guest_proxy_agent)rWovf_envrNrrdefuserr4r4r5rsJ            rcCst|Sr)r1)rKr4r4r5rLsrLcCs`zt|}|d WdWdS1swYWdSty/td|YdSw)z;Return boolean indicating path to cdrom device has content.iNTzcdrom (%s) is not configuredF)openreadIOErrorr{r|) cdrom_devfpr4r4r5_check_freebsd_cdroms  $ rWcCs(|durdStj|dd}t|S)zIReturn content random seed file if available, otherwise, return None.NT)quiet)rload_binary_filerC b64encodedecode)sourcerr4r4r5rEs rEccsZ|VtVtrd}t|r|VndD] }td|EdHq|r+|VdSdS)Nz/dev/cd0)iso9660rzTYPE=%s)DEFAULT_PROVISIONING_ISO_DEVrr,rWr)r cache_dirrUfstyper4r4r5r+s r+c Cstj|d}tj|stdtd!t|d }|}Wdn1s+wYWdn1s:wYt |\}}}|||d|ifS)Nr$zNo ovf-env file foundzReading ovf-env.xmlrb) rrrlrr!r TimedrRrSr) source_dirovf_filerVrWrNrrr4r4r5r.s  r.network_metadatarc Csdid}t|dD]\}}d}dj|d}d|dd i}|d kr'd|d <d |dd }dD]\} || idg} | sEtd| |q/d }| dkrNd} n d} | rZd |d<||d<|s]q/| ddD]'} || dd d| } | d}|ds~g|d<|ddj|| dqcq/|r|rt|d}|d|i|dt |}|r||d d!<||d"|<q td#|||q |S)$zConvert imds network metadata dictionary to network v2 configuration. :param: network_metadata: Dict of "network" key from instance metadata. :return: Dictionary containing network version 2 standard configuration. rJ)version ethernetsrFzeth{idx})idxz route-metricrMrrzuse-dnsT)dhcp4zdhcp4-overridesdhcp6)ipv4ipv6 ipAddresszNo %s addresses found for: %rrk24128rjzdhcp6-overridesNsubnetprefixprivateIpAddress addressesz {ip}/{prefix})iprqr macaddress)matchzset-namervrrgzrBr?r@rrrr,r0rr{rrLrWrEr+r.rrrrwDataSourceAzureNetDEP_FILESYSTEMrrr4r4r4r5s(        <       +       g   p +  7      P &