Current File : //usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyo
�
�jbc@s{ddlZddlZddlZddlmZddlZddlZddlZddlZddl	m	Z	ddl
mZddlj
jZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZmZmZddlmZdd
l m!Z!ddl"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*ej+e,�Z-dZ.idd6Z/dddgZ0dZ1dddgZ2dddgZ3dZ4dZ5dZ6dZ7dZ8dZ9d Z:d!Z;d"Z<d#Z=d$Z>d%d&d'd(gZ?d)�Z@d*�ZAd+�ZBeCd,�ZDd-�ZEd.�ZFd/�ZGd0�ZHejI�r�d1Z5d2Z6d3Z7eHd4�ZJeJeCk	r�e-jKd5�d6eJZ4n
e-jKd7�eCZ>nie1d86e;d96eLd:6ie5d;6eLd<6d=d>6d?d@6dA6ie4dB6dC6e6dD6eLdE6ZMiiidFdG6dHgdI6eLdJ6dB6dK6ie7dL6dMdN6gdO6ZNdPe.gZOdQZPdRZQdSZRd?dT�ZSd?dU�ZTe$ejUd?dV���ZVdWejWfdX��YZXdYdZ�ZYe$d[��ZZe$d\��Z[e$e4d]e\e\d^��Z]e$d_��Z^e$eCd`��Z_e$da��Z`e$eCdb��Zae$dc��Zbdd�Zce$de��Zde$df��Zee$dg��Zfdhdi�Zge$dj��Zhe$e>dk��Zie$dl��Zje$dm��Zkdn�Zle$do��Zme$dp��Zne$eCdq��Zodr�Zpdseqfdt��YZrdueqfdv��YZseXZteXejuffgZvdw�ZwdS(xi����N(tpartial(ttime(tminidom(tlog(tnet(t	EventType(tEphemeralDHCPv4(tsources(tnetlink(tUrlErrortreadurltretry_on_url_exc(tutil(tevents(tazure_ds_reportertazure_ds_telemetry_reportertget_metadata_from_fabrictget_boot_telemetrytget_system_infotreport_diagnostic_eventtEphemeralDHCPv4WithReportingtis_byte_swappedtAzuresiid-AZURE-NODEsinstance-idtservicetwalinuxagenttstartt__builtin__tshs-xcs>i=$interface; x=0; ifdown $i || x=$?; ifup $i || x=$?; exit $xsLi=$interface; x=0; ifconfig down $i || x=$?; ifconfig up $i || x=$?; exit $xs/dev/disk/cloud/azure_resourceteth0s"/var/lib/dhcp/dhclient.eth0.leasestext4s 7783-7084-3265-9085-8269-3286-77s/var/lib/cloud/data/poll_imdss"/var/lib/cloud/data/reported_readys/var/lib/waagentis http://169.254.169.254/metadata/s/sys/firmware/acpi/tables/OEM0s"/etc/netplan/90-hotplug-azure.yamls /usr/local/sbin/ephemeral_eth.shs+/etc/udev/rules.d/10-net-device-added.ruless#/run/network/interfaces.ephemeral.dcCs�x�|j�D]�}tjd|�r
|j�}t|�dkr�|djd�}t|�dkr�|ddkr�|dj|�r�|djd�}|dSq�q
q
Wd	S(
s�
    dev.storvsc.1.%pnpinfo:
        classid=32412632-86cb-44a2-9b5c-50d1417354f5
        deviceid=00000000-0001-8899-0000-000000000000
    tpnpinfoiit=itdeviceidit.N(t
splitlinestretsearchtsplittlent
startswithtNone(t
sysctl_outR tlinetfieldstcolumnstcomps((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyt"find_storvscid_from_sysctl_pnpinfoTscCsAx:|j�D],}tj||�r
|j�}|dSq
WdS(s�
    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
    iN(R"R#R$R%R((tcamcontrol_outtdisk_drvR*titems((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytfind_busdev_from_diskhs
cCslxe|j�D]W}tj||�r
|jd�}t|�dkrd|djd�}|dSq
q
WdS(s�
    <Msft Virtual CD/ROM 1.0>          at scbus1 target 0 lun 0 (cd0,pass0)
    <Msft Virtual Disk 1.0>            at scbus2 target 0 lun 0 (da0,pass1)
    <Msft Virtual Disk 1.0>            at scbus3 target 1 lun 0 (da1,pass2)
    t(iit,iN(R"R#R$R%R&R((R/tbusdevR*R1tdev_pass((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytfind_dev_from_busdev{scCsJytj|�dSWn.tjk
rEtjddj|��|SXdS(NisFailed to execute: %st (RtsubptProcessExecutionErrortLOGtdebugtjoin(tcmdtfail_ret((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytexecute_or_debug�s
cCstddgdd�S(Ntsysctlsdev.storvscR?t(R@(((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytget_dev_storvsc_sysctl�scCstdddg�S(Nt
camcontroltdevlists-b(R@(((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytget_camcontrol_dev_bus�scCstddg�S(NRDRE(R@(((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytget_camcontrol_dev�scCs4d}|dkr%d}|d}ndt|�}dj||�}t�}t||�}|svtjd�dSt�}t�}dj|�}t	||�}	|	r�t
||	�}
|
dkr�tjd	�dS|
Sd
j|�}t	||�}	|	r0t
||	�}
|
dkr,tjd	�dS|
SdS(Nt00000000it00000001it000s{0}-{1}s#Fail to find storvsc id from sysctls	blkvsc{0}sFail to find /dev/daXs
storvsc{0}(tstrtformatRCR.R;R<R(RFRGR2R7(tport_idtg0tg1tg0g1R)t	storvscidtcamcontrol_b_outR/tblkvsctscbusxtdevnametstorvsc((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytget_resource_disk_on_freebsd�s<
	
		

thn0s/var/db/dhclient.leases.hn0sfreebsd-ufsisresource disk is not Nones/dev/sresource disk is Nonet
agent_commandtdata_dirtset_hostnamet	interfacetpolicytbuiltintcommandthostnamethostname_commandthostname_bouncet
ephemeral0tdisk_aliasestdhclient_lease_filetapply_network_configtgptt
table_typeidtlayoutt	overwritet
disk_setupt
filesystemsephemeral0.1tdevicetfs_setupt
datasourcetnever_destroy_ntfssTemporary StoragetREDACTEDcCs>t|ttf�s!|f}ntj|dt�dj�S(Ntcapturei(t
isinstancetlistttupleRR9tTruetstrip(Ra((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytget_hostname�scCs tjddt|�g�dS(Nthostnamectlsset-hostname(RR9RK(R`Ra((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR[sc	cs�|dd}t|�}tj|jd��sZtj|�sZ||krc|dkrcdVdSt||�z	|VWdt||�XdS(s�
    Set a temporary hostname, restoring the previous hostname on exit.

    Will have the value of the previous hostname when used as a context
    manager, or None if the hostname was not changed.
    RbR]R[tforceN(RxRtis_truetgettis_falseR(R[(t
temp_hostnametcfgRaR]tprevious_hostname((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyttemporary_hostnames	
	tDataSourceAzurecBs4eZdZeZejZd�Zd�Z	e
d��Ze
d��Zd�Z
e
d��Zd�Zdd�Ze
d	��Zd
�Zd�Zd�Zdd
�Ze
d��Zd�Ze
d��Zd�Zd�Ze
d��Ze
d��Zed��Zed��Z ed��Z!RS(RcCs�tjj||||�tjj|jd�|_i|_d|_	t
jt
j|t
i�tg�|_|jjd�|_d|_|jdjtj�d|_dS(NtazureRetnetwork(Rt
DataSourcet__init__tostpathR=tseed_dirRR(tseedRt
mergemanydicttget_cfg_by_pathtDS_CFG_PATHtBUILTIN_DS_CONFIGtds_cfgR|Ret_network_configt
update_eventstaddRtBOOTt_ephemeral_dhcp_ctx(tselftsys_cfgtdistrotpaths((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR�#s			cCs#tjj|�}d||jfS(Ns%s [seed=%s](RR�t__str__R�(R�troot((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR�1scCs�|jjd�}tjd|�|jdd}t||jd|���}|dk	r�tj|jjd��r�|jd}yt	d|d|d|�SWq�t
k
r�}tjd	|�tjtd
�q�XnWdQXt
S(Nslocal-hostnamesHostname in metadata is %sRbRaR[R`Rt
prev_hostnamesFailed publishing hostname: %sshandling set_hostname failed(tmetadataR|R;R<R�R�R(RR{tperform_hostname_bouncet	ExceptiontwarningtlogexctFalse(R�tazure_hostnameRatprevious_hnRte((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyt"bounce_network_with_azure_hostname5s"	
c
Cs�|jjd�}|jd}tjd||�|j�yt|�Wn.tjk
rztj	td|jd�nX|jd}g}d}x�|jjdg�D]o}|jdd�r�|d}tjd�q�t|d	d
�}|t
jj||�g7}tjd�q�Wtjdd
dddt��Ttjdtjdddtjd|df�}t|�r�tjd|�nWdQXi}	|p�t|�|	d<|	S(Nslocal-hostnameRYs/Getting metadata via agent.  hostname=%s cmd=%ssagent command '%s' failed.RZt_pubkeystvalues+ssh authentication: using value from fabrictfingerprints.crts1ssh authentication: using fingerprint from fabrictnameswaiting-for-ssh-public-keytdescriptions$wait for agents to retrieve ssh keystparenttlogfunctmsgs waiting for SSH public key filestfunctargsi�s$Did not find files, but going on: %sspublic-keys(R�R|R�R;R<R�tinvoke_agentRR:R�R(RRKR�R�R=R
tReportEventStackRtlog_timetwait_for_filesR&R�tpubkeys_from_crt_files(
R�R~t	agent_cmdtddirtfp_filest	key_valuetpktbnametmissingR�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytget_metadata_from_agentOsB
	



	
	cCs2|jjd�rd}nd}d||jfS(s/Return the subplatform metadata source details.s/devsconfig-disksseed-dirs%s (%s)(R�R'(R�tsubplatform_type((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyt_get_subplatform~s	c	Cs�i}|jd}|jg}tjjt�rD|jdd�n|jt��|rj|j	|�nd}t}x|D]�}yv|dkr�d}t}nW|j
d�r�tj�r�tj|tdd�}q�tj|t�}nt|�}Wn�tk
rtd|�q}nmtk
rR}d|}	t|	�tj|	��n8tjk
r�d	|}	t|	�tj|	�q}nX|p�|j|�}
|
r�tj�r�d
}	tj|	�t|	�tj|	��n|j�}nt|jdd�}|\}}
}}||_|j i|d
6|d6tj!|i|d6g�d6|
d6�|}tj"d|�Pq}W|s�d}	t|	�tj|	��n||kr�tj"d|�nt#�}|r�||dd<n|j$�|dd<|
r�tj%d�t&j'|j�o(t(|dd�}|rW|j)d|j*j+�|j*j,�q�y)t-t.��}|j)d|�WdQXWq�t/k
r�}td|��q�Xn|S(sWalk 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.
        RZitIMDSs/dev/tmtypetudfs$Did not find Azure data source in %ssBrokenAzureDataSource: %ss%s was not mountables%Free BSD is not supported for PPS VMstretriesi
RtfilestimdsR�tuserdata_rawsfound datasource in %ssNo Azure metadata foundsusing files cached in %strandom_seedsinstance-ids6Reporting ready to Azure after getting ReprovisionDataR�tleaseNs#exception while reporting ready: %s(0R�R�R�R�tisfiletREPROVISION_MARKER_FILEtinserttextendtlist_possible_azure_ds_devstappendR(R�RvR'Rt
is_FreeBSDtmount_cbtload_azure_ds_dirtNonAzureDataSourceRtBrokenAzureDataSourceRtInvalidMetaDataExceptiontMountFailedErrorR;R�t_should_reprovisionterrort_reprovisiontget_metadata_from_imdstfallback_interfaceR�tupdateR�R<t_get_random_seedt_iidtinfoRtis_uptgetattrt
_report_readyR�R�t
clean_networkRRR�(R�tcrawled_dataR�t
candidatestfoundtreprovisiontcdevtrettexcR�tperform_reprovisiontimds_mdtmdR�RR�R�tuse_cached_ephemeralR�R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytcrawl_metadata�s�

	







		
	

cCs
t|j�S(s@Check platform environment to report if this datasource may run.(t_is_platform_viableR�(R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��scCs&tt|�j|�tj|_dS(s.Reset any cached class attributes to defaults.N(tsuperR�tclear_cached_attrsRtUNSETt_metadata_imds(R�t
attr_defaults((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��scCs�|j�stSyt�Wn#tk
r@}tjd|�nXyt�Wn#tk
rq}tjd|�nXy(tjdtj	ddd|j
�}Wn'tjk
r�}tjd|�tSX|j
r�|j
jdkr�|jjd	�r�t�ntj|d
tg�|_|dd|_tj|dtg�|_|d
|_tj|jti�}tj||jg�|_t|jd|ddd�tS(s�Crawl and process datasource metadata caching metadata as attrs.

        @return: True on success, False on error, invalid or disabled
            datasource.
        s Failed to get boot telemetry: %ss$Failed to get system information: %sR�R�sCrawl of metadata serviceR�s"Could not crawl Azure metadata: %stubuntuRfRR�R�R�RZR�tdirmodei�(R�R�RR�R;R�RRR�R<R�RR�R�R�R�R|t*maybe_remove_ubuntu_network_config_scriptsR�tBUILTIN_CLOUD_CONFIGRR�tDEFAULT_METADATAR�R�R�R�twrite_filesRv(R�R�R�tuser_ds_cfg((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyt	_get_data�s>	

cCs|jdj|�S(NRd(R�R|(R�R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytdevice_name_to_device'scCs|jS(N(R(R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytget_config_obj*scCstj|j��S(N(Rtinstance_id_matches_system_uuidtget_instance_id(R�R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytcheck_instance_id-scCsqtjj|jjd�d�}tjd�}tjj|�rmtj|�j	�}t
||�rm|Sn|S(Ntdatasinstance-idssystem-uuid(R�R�R=R�t	get_cpathRt
read_dmi_datatexistst	load_fileRwR(R�tprevioust
prev_iid_pathtiid((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR�1s	cCs�|jtkritjd|j�|�|j�}tjd|�|r]|jj|�nt|_ntjd|j��dS(Ns$negotiating for %s (new_instance=%s)snegotiating returned %ssnegotiating already done for %s(	t_negotiatedR�R;R<R�t
_negotiateR�R�Rv(R�tis_new_instancetfabric_data((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytsetup;s		c
s�td}idd6}d
}ttjjt��}d�_d�_d}t	}d
}�fd�}t
jd�xtr�z�y�t
jdd	d
ddt�� t��_�jj�}	Wd
QX|r�|d7}n|rytj�}Wn;tjk
r+}
t|
�t
j|
��jj�PnXt}t
jd|�tj|djdtj�dt����jd|	�t	}t
jddd
ddt��Kytj ||	d�Wn+t!k
r�}t|�t
j"|�PnXWd
QXt}�jj�nSt
jddd
ddt��2t#|dt$d|d|dtdt	�j%}Wd
QXPWnt&k
rx�jj�nXWd
|r�|j'�nXqyW|r�td|�td�j�n|S(stPoll IMDS for the new provisioning data until we get a valid
        response. Then return the returned JSON object.s&reprovisiondata?api-version=2017-04-02ttruetMetadataiics�t|t�r�|jdkr��j�jkrq�jd9_tjd||j�j�tjd�j�n�jd7_tStjd||j�td|j�t	S(Ni�isJCall to IMDS with arguments %s failed with status code %s after %s retriess:Backing off logging threshold for the same exception to %dis:Call to IMDS with arguments %s failed  with status code %ss%polling IMDS failed with exception %s(
RsR	tcodetimds_poll_countertimds_logging_thresholdR;R<RvRR�(R�t	exception(R�(sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytexc_cbVs		
	
sWait for vnetswitch to happenR�sobtain-dhcp-leaseR�sobtain dhcp leaseR�Ns*Creating a marker file to report ready: %ss{pid}: {time}
tpidRR�s!wait-for-media-disconnect-connectswait for vnet switchR\sget-reprovision-data-from-imdssget reprovision data from imdsttimeouttheaderstexception_cbtinfinitetlog_req_resps#attempted dhcp %d times after reuses polled imds %d times after reuse((tIMDS_URLR(tboolR�R�R�tREPORTED_READY_MARKER_FILERRR�R;R<RvR
R�RRR�tobtain_leaseRtcreate_bound_netlink_sockettNetlinkCreateSocketErrorRR�R�R�Rt
write_fileRLtgetpidRR�t!wait_for_media_disconnect_connecttAssertionErrorR�R
tIMDS_TIMEOUT_IN_SECONDStcontentsR	tclose(
R�turlRtnl_socktreport_readyt
dhcp_attemptst
vnet_switchedt
return_valRR�R�R�R�((R�sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyt
_poll_imdsIs�

		
		





	


	
	

cCs@ytd|d�Wn$tk
r;tjddt�nXdS(s,Tells the fabric provisioning has completed sunknown-245sNError communicating with Azure fabric; You may experience.connectivity issues.texc_infoN(RR(R�R;R�Rv(R�R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��s
cCs�|s
tS|\}}}}t}|jd�tksItjj|�r�tjj|�s�tjd|�t	j
|djdtj�dt
���ntStS(s�Whether or not we should poll IMDS for reprovisioning data.
        Also sets a marker file to poll IMDS.

        The marker file is used for the following scenario: the VM boots into
        this polling loop, which we expect to be proceeding infinitely until
        the VM is picked. If for whatever reason the platform moves us to a
        new host (for instance a hardware issue), we need to keep polling.
        However, since the VM reports ready to the Fabric, we will not attach
        the ISO, thus cloud-init needs to have a way of knowing that it should
        jump back into the polling loop in order to retrieve the ovf_env.tPreprovisionedVms'Creating a marker file to poll imds: %ss{pid}: {time}
RR(R�R�R|RvR�R�R�R;R�RR!RLR"R(R�R�t_mdt
_userdata_rawRt_filesR�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��s	c
Csa|j�}tjdddddt��1t|�\}}}|||i|d6fSWdQXdS(s%Initiate the reprovisioning workflow.R�sreprovisioning-read-azure-ovfR�s$read azure ovf during reprovisioningR�sovf-env.xmlN(R.R
R�Rtread_azure_ovf(R�R&R�tudR((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��s	
cCs�|jdtkrP|j�|jjdd	�}ttd|jd|�}n	|j	}t
jd|jd�y
|�}Wn5tk
r�}t
d|�t
jddt�tSXtjt�tjt�|S(
s�Negotiate with fabric and return data from it.

           On success, returns a dictionary including 'public_keys'.
           On failure, returns False.
        RYR�tfallback_lease_filetpubkey_infos,negotiating with fabric via agent command %ssQError communicating with Azure fabric; You may experience connectivity issues: %ssNError communicating with Azure fabric; You may experience connectivity issues.R/N(R�tAGENT_START_BUILTINR�RR|R(RRReR�R;R<R�RR�RvR�Rtdel_fileRR�(R�R7t
metadata_funcRR�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR
�s,
				


cCs&td|d|jjtt��dS(NRt
preserve_ntfs(taddress_ephemeral_resizeR�R|tDS_CFG_KEY_PRESERVE_NTFSR�(R�RR((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytactivates	
cCs(|jjdi�jdi�jd�S(NR�tcomputetplatformFaultDomain(R�R|(R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytavailability_zones	cCsY|js|jtjkrR|jjd�r:|j}nd}t|�|_n|jS(s�Generate a network config like net.generate_fallback_network() with
           the following exceptions.

           1. Probe the drivers of the net-devices present and inject them in
              the network configuration under params: driver: <driver> value
           2. Generate a fallback network config that does not include any of
              the blacklisted devices.
        RfN(R�RR�R�R|R�R(tparse_network_config(R�tnc_src((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytnetwork_configs
cCs(|jjdi�jdi�jd�S(NR�R?tlocation(R�R|(R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytregion"s(N("t__name__t
__module__tdsnameR�R	RR�R�R�R�RR�R�R�R�R�R�R�R�R�RR(R�R
R.R�R�R�R
R>tpropertyRARDRF(((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR�s4			/	i	/			
	j
		
$icCs�x�dD]x}g}x_td|�D]N}||t|�}tjj|�r#|j|tjj|�f�q#q#W|r|SqWgS(Ns-parttpRBi(s-partRKRB(trangeRKR�R�RR�trealpath(tdevpathtmaxnumtsuffR�tpnumtppath((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyt_partitions_on_device's
&cCs;tjddt�}tjd|�tjj|�|kS(Ns	TYPE=ntfstno_cachesntfs_devices found = %s(Rtfind_devs_withRvR;R<R�R�RM(RNtntfs_devices((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyt_has_ntfs_filesystem4sc
Cs\|r)ddjt�tf}t|fStjj|�sItd|fStjd|tjj	|��t
|�}t|�dkr�td|fSt|�dkr�d|d	jg|D]}|d
^q��f}t|fSt|�dkr|d
\}}n|d\}}t|�s>d|||f}t|fSt
d��}d
|||f}tjdddddt���}	y)tj||dddidd6�}
WnTtjk
r}d|	_dt|�kr�t|dfSt|d||ffSX|
dkrHd|
|	_tjddjt�t�t|d|
fSWdQXt|dfS( s�Determine 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.s:config says to never destroy NTFS (%s.%s), skipping checksR!sdevice %s does not existsResolving realpath of %s -> %sisdevice %s was not partitionedis&device %s had 3 or more partitions: %sR8is5partition %s (%s) on device %s was not ntfs formattedcSsGtdg�}tgtj|�D]}|j�|kr"|^q"�S(Nsdataloss_warning_readme.txt(tsetR&R�tlistdirtlower(tmptignoredtf((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytcount_fileslss1partition %s (%s) on device %s was ntfs formattedR�smount-ntfs-and-countR�R�R�tntfstupdate_env_for_mounttCtLANGscannot mount ntfssunknown filesystem type 'ntfs's^ but this system cannot mount NTFS, assuming there are no important files. Formatting allowed.s but mount of %s failed: %ssmounted and counted %d filessxit looks like you're using NTFS on the ephemeral disk, to ensure that filesystem does not get wiped, set %s.%s in configs but had %d files on it.Ns3 and had no important files. Safe for reformatting.(R=R�R=R�R�R�RR;R<RMRSR&RWRR
R�RRR�R�R�RKRvR�(RNR;R�t
partitionsRKt	cand_partt	cand_pathR^tbmsgtevtt
file_countR�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytcan_dev_be_reformatted;sX
-

		
	ixcCsdd}tjdddddt��Ftj|gd|d|d	d
�}|rftjd||�dSWdQXt}d}|r�t	d}}nt
||�\}}tjd
||�|s�dSx�ddgD]�}d|}	d|	|f}
tj
j|	�rLy!tj|	�tjd|
�Wq\tk
rH}tjd|
|�q\Xq�tjd|
�q�WdS(Ng�������?R�swait-for-ephemeral-diskR�swait for ephemeral diskR�tmaxwaittnaplentlog_presAzure ephemeral disk: s6ephemeral device '%s' did not appear after %d seconds.sFirst instance boot.sreformattable=%s: %sRktmountss#/var/lib/cloud/instance/sem/config_sMarker "%s" for module "%s"s%s removed.s%s: remove failed! (%s)s%s did not exist.(R
R�RRR�R;R�R�R(RvRiR<R�R�RtunlinkR�(RNRjRR;RkR�tresultR�tmodtsempathRfR�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR<�s@	
		



c	
Cs|d}|d}|d}d|||f}tjj�}||d<||d<||d<|dkr�tj�rt}q�tjd�r�t}q�tj	d	�t
Sntj	d
|�t|tt
f�}tjdtj	dd
dtdtjdi|d6|d6t
d6|d6�tS(NR_R\R]s"hostname=%s policy=%s interface=%sR`told_hostnameR^tifups7Skipping network bounce: ifupdown utils aren't present.s"pubhname: publishing hostname [%s]R�R�spublishing hostnamet
get_uptimeR�tkwargsR�tshellRrtenv(R�tenvirontcopyRR�tBOUNCE_COMMAND_FREEBSDtwhichtBOUNCE_COMMAND_IFUPR;R<R�RsRtRuR�RvR9(	R`RR�R_R\R]R�RwRv((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��s0





		cCs=d}tjdd||gdtd|�\}}|j�S(NsHopenssl x509 -noout -pubkey < "$0" |ssh-keygen -i -m PKCS8 -f /dev/stdinRs-cRrR(RR9Rvtrstrip(tfnameRtpipelinetoutt_err((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytcrtfile_to_pubkey�scCsug}g}xI|D]A}y|jt|��Wqtjk
rS|j|�qXqW|rqtjd|�n|S(Ns-failed to convert the crt files to pubkey: %s(R�R�RR:R;R�(tflisttpubkeysterrorsR~((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��s
cCs�d�}|sdS|s"i}ntj||�xi|j�D][\}}tjj||�}d|kr~|||�}ntjd|d|dd�q?WdS(NcSs�yatj|�}x>|j�D]0}d|jkr|jtkrt|_qqWtj|�SWn"tk
r�tj	d|�|SXdS(s>Azure provides the UserPassword in plain text. So we redact ittUserPasswords#failed to redact userpassword in %sN(
tETt
fromstringtiterttagttexttDEF_PASSWD_REDACTIONttostringR�R;tcritical(tcntR~R�telem((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyt_redact_password�s
sovf-env.xmltfilenametcontenttmodei�(Rt
ensure_dirR1R�R�R=R!(tdatadirR�R�R�R�R�R~((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��s	
	cCsG|r6tjd|�tj|dt|t��n
tjd�dS(Nsinvoking agent: %sRvsnot invoking agent(R;R<RR9RsRt(R>((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR�s cCsJg}|j�s|Sx-|jD]"}||�r |j|�q q W|S(N(t
hasChildNodest
childNodesR�(tnodetfilter_funcR�tchild((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyt
find_childsc
Cs�t|d��}t|�dkr(gSt|�dkrStdt|���n|d}t|d��}t|�dkr�gSg}tjj}x�|D]�}|j�s�q�nidd6dd6dd	6}x�|jD]�}|j|ks�|j	rq�n|j	j
�}	|	|j�kr'q�nt|j�dks�|jdj|krXq�n|jdjj
�||	<q�W|j|�q�W|S(
NcSs
|jdkS(Nt
PublicKeys(t	localName(tn((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyt<lambda>6siis%Multiple 'PublicKeys'(%s) in SSH nodecSs
|jdkS(Nt	PublicKey(R�(R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR�>sRBR�R�R�(R�R&R�RtDocumentt	TEXT_NODER�R�tnodeTypeR�RZtkeyst	wholeTextRwR�(
tsshnodetresultstpubkeys_nodeR�R�t	text_nodetpk_nodetcurR�R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytload_azure_ovf_pubkeys)s8


c	CsSytj|�}Wn3tk
rH}d|}t|�t|��nXt|jd��}t|�dkrtd��nt|�dkr�tdt|���n|d}t|d��}t|�dkr�td��nt|�dkrtd	t|�d
f��n|d}|j	�s=td��nd}iid
6}	i}
d}d}d}
x?|jD]4}|j|j
ksr|jr�qrn|jj�}t}d}t|j�dkr�|jdj|j
kr�t}|jdj}ntg|jj�D]\}}||f^q�}|dksH|dkr�|jd�d%kr~tjdj|j���}q�|}qr|dkr�|}
qr|dkr�|}qr|dkr�||	d<qr|dkr5|jd�d&krtjdj|j���}n|}itj|di�t6|
d<qr|dkrTt|�|
d<qr|dkrvtj|�|
d<qr|rr||kr�||	|<q�||	d
|<qrqrWi}|
r�|
|d<n|r�t|d<t |kr�t!|�|d <|
d!<q�n|ri|d"6|
d#<nd|
kr6|r6t|
d<nt"|�|
d$<|	||
fS('NsInvalid ovf-env.xml: %scSs
|jdkS(NtProvisioningSection(R�(R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR�hsisNo ProvisioningSectionis$found '%d' ProvisioningSection itemscSs
|jdkS(Nt!LinuxProvisioningConfigurationSet(R�(R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR�rss$No LinuxProvisioningConfigurationSetsfound '%d' %ssR�s#no child nodes of configuration settseedfromt
azure_dataRBtuserdatat
customdatatencodingtbase64tusernametuserpasswordR`slocal-hostnametdscfgtdefaultRotsshR�t disablesshpasswordauthenticationt
ssh_pwauthR�tlock_passwdtpasswdtpasswordtdefault_usertsystem_infoR0(Nsbase64(Nsbase64(#RtparseStringR�RR�R�tdocumentElementR&R�R�R(R�R�R�R�RZR�RvR�tdictt
attributesR1R|R�t	b64decodeR=R%Rt	load_yamltDS_NAMER�R}R�tencrypt_passt"_extract_preprovisioned_vm_setting(R&tdomR�t	error_strR�tprovSectiont
lpcs_nodestlpcstmd_propsR�RR5R�R�R�R�tsimpleR�tktvtattrsR�tdefuser((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR4^s�

	
	

4!			
!#



cCs�t|jd��}|s.t|�dkr?tjd�tSt|dd��}|snt|�dkrtjd�tSt|dd��}|s�t|�dkr�tjd�tStj|djj	�S(sPRead the preprovision flag from the ovf. It should not
       exist unless true.cSs
|jdkS(NtPlatformSettingsSection(R�(R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��sis!PlatformSettingsSection not foundcSs
|jdkS(NtPlatformSettings(R�(R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��ssPlatformSettings not foundcSs
|jdkS(NR0(R�(R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��ssPreprovisionedVm not found(
R�R�R&R;R<R�Rttranslate_boolt
firstChildt	nodeValue(R�tplatform_settings_sectiontplatform_settingstpreprovisionedVm((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��s&


s$6$cCs tj||tjdd��S(Ntstrleni(tcryptRtrand_str(R�tsalt_id((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��scCsRy*t|��}|jd�tSWdQXWn!tk
rMtjd|�nXtS(s;Return boolean indicating path to cdrom device has content.iNscdrom (%s) is not configured(topentreadRvtIOErrorR;R<R�(t	cdrom_devtfp((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyt_check_freebsd_cdrom�s

cCsD|dkrdStj|dtdt�}tj|�j�}|S(sLReturn content random seed file if available, otherwise,
       return None.tquiettdecodeN(R(RRRvR�R�t	b64encodeR�(tsourceR�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��s
cCsmg}tj�r.d}t|�rY|gSn+x(dD] }|jtjd|��q5W|jdt�|S(Ns/dev/cd0tiso9660R�sTYPE=%streverse(R�sudf(RR�R�R�RUtsortRv(RER�tfstype((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR�s

cCs�tjj|d�}tjj|�s6td��nt|d��}|j�}WdQXt|�\}}}|||i|d6fS(Nsovf-env.xmlsNo ovf-env file foundtrb(R�R�R=R�R�R�R�R4(t
source_dirtovf_fileR�R&R�R5R((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR�scCsVtjdddddt��2}|tjkr|ridd6id6}tjd	�|d
}x�t|d�D]�\}}djd
|�}i|ddd6}it	d6|d6t
d6}x�d.D]�}	|j|	i�jdg�}
|	dkrd}n#d}|
r#t	|d<||d<nxy|
dD]m}||	ddjd|�}
|d}|jd�sxg|d<n|djdjd |d|
��q.Wq�W|rrd!j
tjd"|d#��}|jii|j�d$6d%6|d&6�||d|<qrqrWd'|_n7d(g}tjd)�tjd*|d+t	�}d,|_|SWd-QXd-S(/s`Convert imds_metadata dictionary to network v2 configuration.

    Parses network configuration from imds metadata if present or generate
    fallback network config excluding mlx4_core devices.

    @param: imds_metadata: Dict of content read from IMDS network service.
    @return: Dictionary containing network version 2 standard configuration.
    R�RBR�RBR�itversiont	ethernetss1Azure: generating network configuration from IMDSR�R\seth{idx}tidxiidsroute-metrictdhcp4sdhcp4-overridestdhcp6tipv4tipv6t	ipAddresst24t128sdhcp6-overridestsubnetitprefixtprivateIpAddresst	addressess
{ip}/{prefix}tipt:s..t
macAddresst
macaddresstmatchsset-namesnetwork config from imdst	mlx4_cores(Azure: generating fallback configurationtblacklist_driverst
config_driversnetwork config from fallbackN(R�R�(R
R�RRR�R;R<t	enumerateRLRvR�R|R�R=R#tfindallR�RZR�Rtgenerate_fallback_config(t
imds_metadataRgt	netconfigtnetwork_metadataR�tintftnicnamet
dhcp_overridet
dev_configt	addr_typeRtdefault_prefixtaddrt	netPrefixt	privateIptmact	blacklist((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyRB$sV		



	




		
		cCs�itjd6dd6td6|fd6}tj|�rDtj|�Sy'tt|��tj|�SWdQXWn$t	k
r�}t
d|��nXdS(sQuery Azure's network metadata service, returning a dictionary.

    If network is not up, setup ephemeral dhcp on fallback_nic to talk to the
    IMDS. For more info on IMDS:
        https://docs.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service

    @param fallback_nic: String. The name of the nic which requires active
        network in order to query IMDS.
    @param retries: The number of retries of the IMDS_URL.

    @return: A dict of instance metadata containing compute and network
        info.
    R�s/Crawl of Azure Instance Metadata Service (IMDS)R�R�R�Ns$exception while getting metadata: %s(R;R<t_get_metadata_from_imdsRR�RR�RRR�R(tfallback_nicR�RuR�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR�ds


c
Cs�td}idd6}y(t|dtd|d|dt�}Wn5tk
rv}d|}t|�tj|�iSXytj	t
|��SWn=tjj
k
r�}td	|�tjd
t
|��nXiS(Nsinstance?api-version=2017-12-01RRRRR�Rs#Ignoring IMDS instance metadata: %ssnon-json imds responses,Ignoring non-json IMDS instance metadata: %s(RR
R%RR�RR;R<Rt	load_jsonRKtjsontdecodertJSONDecodeErrorR�(R�R(RtresponseR�R�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR�s$




cCs�|st}nt}xt|D]l}tjj|�r|sVtjdtj�t	}ntjj
|�rxtj|�q�tj
|�qqWdS(s(Remove Azure-specific ubuntu network config for non-primary nics.

    @param paths: List of networking scripts or directories to remove when
        present.

    In certain supported ubuntu images, static udev rules or netplan yaml
    config is delivered in the base ubuntu image to support dhcp on any
    additional interfaces which get attached by a customer at some point
    after initial boot. Since the Azure datasource can now regenerate
    network configuration as metadata reports these new devices, we no longer
    want the udev rules or netplan's 90-hotplug-azure.yaml to configure
    networking on eth1 or greater as it might collide with cloud-init's
    configuration.

    Remove the any existing extended network scripts if the datasource is
    enabled to write network per-boot.
    s{Removing Ubuntu extended network scripts because cloud-init updates Azure network configuration on the following event: %s.N(tUBUNTU_EXTENDED_NETWORK_SCRIPTSR�R�R�RR;R�RR�RvtisdirRtdel_dirR9(R�tloggedR�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��s	

	cCs�tjdddddt��y}tjd�}|tkr@tSd|}tj|�||_	t
|�tjj
tjj|d��r�tStSWdQXdS(	NR�scheck-platform-viabilityR�sfound azure asset tagR�schassis-asset-tags(Non-Azure DMI asset tag '%s' discovered.sovf-env.xml(R
R�RRRtAZURE_CHASSIS_ASSET_TAGRvR;R<R�RR�R�RR=R�(R�Rgt	asset_tagR�((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��s	

	
!R�cBseZRS((RGRH(((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��sR�cBseZRS((RGRH(((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyR��scCstj|t�S(N(Rtlist_from_dependstdatasources(tdepends((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pytget_datasource_list�s(xR�t
contextlibR�t	functoolsRRR�tos.pathR#Rtxml.domRtxml.etree.ElementTreetetreetElementTreeR�t	cloudinitRtloggingRtcloudinit.eventRtcloudinit.net.dhcpRRtcloudinit.sources.helpersRtcloudinit.url_helperR	R
RRtcloudinit.reportingR
tcloudinit.sources.helpers.azureRRRRRRRRt	getLoggerRGR;R�R�tAGENT_STARTR8R|RztRESOURCE_DISK_PATHtDEFAULT_PRIMARY_NICt
LEASE_FILEt
DEFAULT_FSR%R�RtAGENT_SEED_DIRR%RtPLATFORM_ENTROPY_SOURCER!R.R2R7R(R@RCRFRGRWR�tres_diskR<RvR�R�R�R=tDEF_EPHEMERAL_LABELR�RxR[tcontextmanagerR�R�R�RSRWRiR�R<R�R�R�R�R�R�R�R4R�R�R�R�R�R�RBR�RR�R�R�R�R�tDataSourceAzureNettDEP_FILESYSTEMR(R*(((sE/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceAzure.pyt<module>s�:

										,


	



��
S,$
	
5h	@$