403Webshell
Server IP : 3.96.16.70  /  Your IP : 216.73.216.15
Web Server : Apache
System : Linux ip-172-31-26-103.ca-central-1.compute.internal 6.1.163-186.299.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Feb 24 16:35:42 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3.9/site-packages/cloudinit/sources/helpers/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3.9/site-packages/cloudinit/sources/helpers/__pycache__/azure.cpython-39.pyc
a

�½bf��@sbddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlmZddl
mZddlmZmZddlmZddlmZddlmZmZmZmZmZmZdd	lmZdd
lm Z e�!e"�Z#dZ$dZ%d
Z&dZ'dZ(dZ)dZ*ej+dddd�Z,dZ-dd�Z.dd�Z/e.dd��Z0e.dd��Z1dd�e2ej3d �d!d"�Z4d#d$�Z5e.e d%fd&d'��Z6e.d(d)��Z7ed*d+��Z8d,d-�Z9e.dd.�e2e:ee2ej;d/�d0d1��Z<e2e2e2e=d2�d3d4�Z>Gd5d6�d6�Z?Gd7d8�d8e@�ZAGd9d:�d:�ZBGd;d<�d<�ZCGd=d>�d>�ZDGd?d@�d@�ZEe.dIe2eee2ee2dA�dBdC��ZFe.dJe2ee2dD�dEdF��ZGdGdH�ZHdS)K�N)�contextmanager)�datetime)�ENOENT)�List�Optional)�ElementTree)�escape)�distros�subp�
temp_utils�
url_helper�util�version)�events)�CFG_BUILTINz
168.63.129.16�boot-telemetryzsystem-infoZ
diagnostic�
compressedi�z'/run/cloud-init/log_pushed_to_kvp_indexzazure-dsz initialize reporter for azure dsT)�name�descriptionZreporting_enabledz�The VM encountered an error during deployment. Please visit https://aka.ms/linuxprovisioningerror for more information on remediation.cs�fdd�}|S)NcsFtj�j�jtd���|i|��Wd�S1s80YdS)N�rr�parent)r�ReportEventStack�__name__�azure_ds_reporter)�args�kwargs��func��C/usr/lib/python3.9/site-packages/cloudinit/sources/helpers/azure.py�impl6s�z)azure_ds_telemetry_reporter.<locals>.implr)rr rrr�azure_ds_telemetry_reporter5sr!cCs\||krdSd
dd�}|�d�}d�||d�||d�||d�|d|d	g�}||kS)z�
    Azure stores the instance ID with an incorrect byte ordering for the
    first parts. This corrects the byte order such that it is consistent with
    that returned by the metadata service.
    F�cSs(dd�t�|d�D�}|��d�|�S)NcSsg|]}|�qSrr)�.0Zbyterrr�
<listcomp>K�z<is_byte_swapped.<locals>.swap_bytestring.<locals>.<listcomp>r"�)�textwrapZwrap�reverse�join)�s�width�ddrrr�swap_bytestringJsz(is_byte_swapped.<locals>.swap_bytestring�-r���)r")�splitr))Zprevious_idZ
current_idr-�partsZ
swapped_idrrr�is_byte_swappedAs




��
r4c
Cs:t��std��t�d�ztt���tt���}Wn.t	yd}ztd�|�WYd}~n
d}~00zTt
j
gd�dd�\}}d}|r�d|vr�|�d�d	}|s�td
��|t|�d}Wnft
jy�}ztd|�|�WYd}~n<d}~0t	�y }ztd
|�|�WYd}~n
d}~00zZt
j
gd�dd�\}}d}|�r\d|v�r\|�d�d	}|�sjtd��|t|�d}Wnht
j�y�}ztd|�|�WYd}~n<d}~0t	�y�}ztd|�|�WYd}~n
d}~00t
�tddt�|���dt�|���dt�|���dft
j�}t
�|�|S)z[Report timestamps related to kernel initialization and systemd
    activation of cloud-initz1distro not using systemd, skipping boot telemetryzCollecting boot telemetryz*Failed to determine kernel start timestampN)�	systemctl�show�-pZUserspaceTimestampMonotonicT)�capture�=r/z8Failed to parse UserspaceTimestampMonotonic from systemdi@Bz-Failed to get UserspaceTimestampMonotonic: %sz<Failed to parse UserspaceTimestampMonotonic from systemd: %s)r5r6zcloud-init-localr7ZInactiveExitTimestampMonotonicz;Failed to parse InactiveExitTimestampMonotonic from systemdz0Failed to get InactiveExitTimestampMonotonic: %sz?Failed to parse InactiveExitTimestampMonotonic from systemd: %srz5kernel_start=%s user_start=%s cloudinit_activation=%s�Z)r	Zuses_systemd�RuntimeError�LOG�debug�float�timer
Zuptime�
ValueErrorr
r2ZProcessExecutionErrorr�ReportingEvent�BOOT_EVENT_TYPErZutcfromtimestampZ	isoformat�DEFAULT_EVENT_ORIGIN�report_event)Zkernel_start�e�out�_ZtsmZ
user_startZcloudinit_activation�evtrrr�get_boot_telemetry]s�
 �
������

���������
rIc
Csbt��}t�tddt��|d|d|dd|dd|dd|d	ftj�}t�|�|S)
z%Collect and report system informationzsystem informationztcloudinit_version=%s, kernel_version=%s, variant=%s, distro_name=%s, distro_version=%s, flavor=%s, python_version=%s�releaseZvariantZdistrr/r"Zpython)	r
Zsystem_inforrA�SYSTEMINFO_EVENT_TYPErZversion_stringrCrD)�inforHrrr�get_system_info�s$


���
rM��logger_func)�msg�returncCs6t|�r||�t�td|tj�}tj|dhd�|S)zReport a diagnostic eventzdiagnostic message�log�Zexcluded_handler_types)�callablerrA�DIAGNOSTIC_EVENT_TYPErCrD)rPrOrHrrr�report_diagnostic_event�s�rVcCsNt�t�|��}d|�d�d�}t�t|t�	|�tj
�}tj|hd�d�|S)zReport a compressed eventzgz+b64�ascii)�encoding�data>�printZwebhookrRrS)�base64Zencodebytes�zlib�compress�decoderrA�COMPRESSED_EVENT_TYPE�json�dumpsrCrD)Z
event_nameZ
event_contentZcompressed_dataZ
event_datarHrrr�report_compressed_event�s���rbZdef_log_filec
CsXt�}t�d�z�t|d��~}|�dtj�t|��t	|�}t
d�|��||�tjd�|�|tj�t
d|���t�tt|����Wd�n1s�0YWn:ty�}z"t
dt|�tjd�WYd}~n
d}~00t�d	�z$tjd
gddd
�\}}t
d
|�Wn<t�yR}z"t
dt|�tjd�WYd}~n
d}~00dS)azPush a portion of cloud-init.log file or the whole file to KVP
    based on the file size.
    The first time this function is called after VM boot, It will push the last
    n bytes of the log file such that n < MAX_LOG_TO_KVP_LENGTH
    If called again on the same boot, it continues from where it left off.
    In addition to cloud-init.log, dmesg log will also be collected.z"Dumping cloud-init.log file to KVP�rbrzMDumping last {0} bytes of cloud-init.log file to KVP starting from index: {1}rNzcloud-init.logNz#Exception when dumping log file: %szDumping dmesg log to KVPZdmesgFT)r^r8z$Exception when dumping dmesg log: %s)�%get_last_log_byte_pushed_to_kvp_indexr<r=�open�seek�os�SEEK_END�max�tell�MAX_LOG_TO_KVP_LENGTHrV�format�SEEK_SETrb�readr
Z
write_file�LOG_PUSHED_TO_KVP_INDEX_FILE�str�	Exception�repr�warningr
)�	file_nameZstart_index�fZ
seek_indexZexrFrGrrr�push_log_to_kvp�s:	
��6
�

�rvc
Cs�z<ttd��}t|���Wd�WS1s00YWn�ty�}z,|jtkrltdt|�t	j
d�WYd}~nzd}~0ty�}z"tdt|�t	j
d�WYd}~nBd}~0ty�}z"tdt|�t	j
d�WYd}~n
d}~00dS)N�rz0Reading LOG_PUSHED_TO_KVP_INDEX_FILE failed: %s.rNz2Invalid value in LOG_PUSHED_TO_KVP_INDEX_FILE: %s.z2Failed to get the last log byte pushed to KVP: %s.r)
rero�intrn�IOError�errnorrVrrr<rsr@rq)rurErrrrds(0

�
�
�rdc	cs@t��}t�tj�|��zdVWt�|�nt�|�0dS�N)rg�getcwd�chdir�path�
expanduser)ZnewdirZprevdirrrr�cd4s
r�cCsx|�dd�}t|�dkrdd}|�d�D] }t|�dkr>d|}||7}q&t�dt|�dd�d��}n
|�d	�}t�|�S)
N�\r&r1�:r/�0z>L��utf-8)	�replace�lenr2�struct�packrx�encode�socketZ	inet_ntoa)Zfallback_lease_valueZunescaped_valueZ
hex_stringZhex_pairZpacked_bytesrrr�get_ip_from_lease_value>s

r��rY)�url�headersrYrQc
Cs�d}d}d}d}td|d�D]�}z2tj||||d�}td||ftjd�|WSty�}	z:||dkr�td	|||	ftjd�||kr��WYd
}	~	n
d
}	~	00t�|�qt	d��d
S)zwReadurl wrapper for querying wireserver.

    Retries up to 40 minutes:
    240 attempts * (5s timeout + 5s sleep)
    ����r/)r�rYZtimeoutz@Successful HTTP request with Azure endpoint %s after %d attemptsrNrzOFailed HTTP request with Azure endpoint %s during attempt %d with exception: %sNz%Failed to return in http_with_retries)
�rangerZreadurlrVr<r=rqr?�sleepr;)
r�r�rYZmax_readurl_attemptsZreadurl_timeoutZsleep_duration_between_retriesZperiodic_logging_attemptsZattempt�retrErrr�http_with_retriesLs8	���
��r�)�username�hostname�
disableSshPwdrQcCs$t�d�}|j|||d�}|�d�S)Na.        <ns0:Environment xmlns:ns0="http://schemas.dmtf.org/ovf/environment/1"
         xmlns:ns1="http://schemas.microsoft.com/windowsazure"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <ns1:ProvisioningSection>
            <ns1:Version>1.0</ns1:Version>
            <ns1:LinuxProvisioningConfigurationSet>
              <ns1:ConfigurationSetType>LinuxProvisioningConfiguration
              </ns1:ConfigurationSetType>
              <ns1:UserName>{username}</ns1:UserName>
              <ns1:DisableSshPasswordAuthentication>{disableSshPwd}
              </ns1:DisableSshPasswordAuthentication>
              <ns1:HostName>{hostname}</ns1:HostName>
            </ns1:LinuxProvisioningConfigurationSet>
          </ns1:ProvisioningSection>
          <ns1:PlatformSettingsSection>
            <ns1:Version>1.0</ns1:Version>
            <ns1:PlatformSettings>
              <ns1:ProvisionGuestAgent>true</ns1:ProvisionGuestAgent>
            </ns1:PlatformSettings>
          </ns1:PlatformSettingsSection>
        </ns0:Environment>
        )r�r�r�r�)r'�dedentrlr�)r�r�r�ZOVF_ENV_TEMPLATEr�rrr�build_minimal_ovfws��r�c@sBeZdZddd�Zdd�Zd
ejd�dd	�Zdejd�dd�Zd
S)�AzureEndpointHttpClientZWALinuxAgentz
2012-11-30)zx-ms-agent-namezx-ms-versioncCsd|d�|_dS)NZDES_EDE3_CBC)zx-ms-cipher-namez!x-ms-guest-agent-public-x509-cert)�extra_secure_headers)�self�certificaterrr�__init__�s�z AzureEndpointHttpClient.__init__F�rQcCs,|j}|r |j��}|�|j�t||d�S)N)r�)r��copy�updater�r�)r�r��securer�rrr�get�s

zAzureEndpointHttpClient.getNcCs0|j}|dur"|j��}|�|�t|||d�S)N)rYr�)r�r�r�r�)r�r�rY�
extra_headersr�rrr�post�s


zAzureEndpointHttpClient.post)F)NN)	r�
__module__�__qualname__r�r�r�UrlResponser�r�rrrrr��s���r�c@seZdZdZdS)�InvalidGoalStateXMLExceptionz9Raised when GoalState XML is invalid or has missing data.N)rr�r��__doc__rrrrr��sr�c@s*eZdZdeeedd�dd�Zdd�ZdS)	�	GoalStateTN)�unparsed_xml�azure_endpoint_client�need_certificaterQc
Cs*||_zt�|�|_Wn:tjyP}z td|tjd��WYd}~n
d}~00|�d�|_	|�d�|_
|�d�|_dD]0}t||�durzd|}t|tjd�t
|��qzd|_|�d	�}|du�r&|�r&tjd
dtd��8|jj|d
d�j|_|jdu�rt
d��Wd�n1�s0YdS)ahParses a GoalState XML string and returns a GoalState object.

        @param unparsed_xml: string representing a GoalState XML.
        @param azure_endpoint_client: instance of AzureEndpointHttpClient.
        @param need_certificate: switch to know if certificates is needed.
        @return: GoalState object representing the GoalState XML string.
        z!Failed to parse GoalState XML: %srNNz./Container/ContainerIdz4./Container/RoleInstanceList/RoleInstance/InstanceIdz
./Incarnation)�container_id�instance_id�incarnationzMissing %s in GoalState XMLzD./Container/RoleInstanceList/RoleInstance/Configuration/Certificateszget-certificates-xmlzget certificates xmlrT)r�z/Azure endpoint returned empty certificates xml.)r�r�
fromstring�rootZ
ParseErrorrVr<rs�_text_from_xpathr�r�r��getattrr��certificates_xmlrrrr��contents)r�r�r�r�rE�attrrPr�rrrr��sH
��
���
�zGoalState.__init__cCs|j�|�}|dur|jSdSr{)r��find�text)r�ZxpathZelementrrrr��szGoalState._text_from_xpath)T)rr�r�rpr��boolr�r�rrrrr��s��7r�c@s�eZdZddd�Zdd�Zdd�Zedd	��Zejd
d	��Ze	dd��Z
ee	d
d���Ze	dd��Z
e	dd��Ze	dd��Ze	dd��ZdS)�OpenSSLManagerzTransportPrivate.pemzTransportCert.pem)�private_keyr�cCst��|_d|_|��dSr{)rZmkdtemp�tmpdir�_certificate�generate_certificate�r�rrrr�s
zOpenSSLManager.__init__cCst�|j�dSr{)r
Zdel_dirr�r�rrr�clean_upszOpenSSLManager.clean_upcCs|jSr{�r�r�rrrr�	szOpenSSLManager.certificatecCs
||_dSr{r�)r��valuerrrr�
scCs�t�d�|jdur"t�d�dSt|j��tt�ddddddd	d
ddd
|jdd|jdg�d}t|jd�D]}d|vrr||��7}qr||_Wd�n1s�0Yt�d�dS)Nz7Generating certificate for communication with fabric...zCertificate already generated.�opensslZreqz-x509z-nodesz-subjz/CN=LinuxTransportz-daysZ32768z-newkeyzrsa:2048z-keyoutr�z-outr�r&ZCERTIFICATEzNew certificate generated.)	r<r=r�r�r�r
�certificate_namesre�rstrip)r�r��linerrrr�s8


��$z#OpenSSLManager.generate_certificatecCs"ddd|g}tj||d�\}}|S)Nr�Zx509z-nooutr�)r
)�actionZcert�cmd�resultrGrrr�_run_x509_action1szOpenSSLManager._run_x509_actioncCs*|�d|�}gd�}tj||d�\}}|S)Nz-pubkey)z
ssh-keygenz-iz-mZPKCS8z-fz
/dev/stdinr�)r�r
)r�r�Zpub_keyZ
keygen_cmd�ssh_keyrGrrr�_get_ssh_key_from_cert8sz%OpenSSLManager._get_ssh_key_from_certcCs6|�d|�}|�d�}||dd��d�}d�|�S)aopenssl x509 formats fingerprints as so:
        'SHA1 Fingerprint=07:3E:19:D1:4D:1C:79:92:24:C6:A0:FD:8D:DA:        B6:A8:BF:27:D4:73
'

        Azure control plane passes that fingerprint as so:
        '073E19D14D1C799224C6A0FD8DDAB6A8BF27D473'
        z-fingerprintr9r/���r�r&)r�r�r2r))r�r�Zraw_fp�eq�octetsrrr�_get_fingerprint_from_cert?s	
z)OpenSSLManager._get_fingerprint_from_certcCs�t�|��d�}|j}ddddd|�d�g}t|j��8tjdjfi|j	��d	d
�
|�d�\}}Wd�n1st0Y|S)
z�Decrypt the certificates XML document using the our private key;
        return the list of certs and private keys contained in the doc.
        z.//DatasMIME-Version: 1.0s<Content-Disposition: attachment; filename="Certificates.p7m"s?Content-Type: application/x-pkcs7-mime; name="Certificates.p7m"s!Content-Transfer-Encoding: base64r%r�zuopenssl cms -decrypt -in /dev/stdin -inkey {private_key} -recip {certificate} | openssl pkcs12 -nodes -password pass:T�
)�shellrYN)rr�r�r�r�r�r�r
rlr�r))r�r��tagZcertificates_content�linesrFrGrrr�_decrypt_certs_from_xmlMs$���(z&OpenSSLManager._decrypt_certs_from_xmlc	Csv|�|�}g}i}|��D]V}|�|�t�d|�r:g}qt�d|�rd�|�}|�|�}|�|�}|||<g}q|S)z�Given the Certificates XML document, return a dictionary of
        fingerprints and associated SSH keys derived from the certs.z[-]+END .*?KEY[-]+$z[-]+END .*?CERTIFICATE[-]+$�
)r��
splitlines�append�re�matchr)r�r�)	r�r�rF�current�keysr�r�r��fingerprintrrr�parse_certificatesfs




z!OpenSSLManager.parse_certificatesN)rr�r�r�r�r��propertyr��setterr!r��staticmethodr�r�r�r�r�rrrrr��s,�






r�c@s�eZdZe�d�Ze�d�ZdZdZdZ	dZ
eee
dd�d	d
�Zedd�dd
��Zee
dd�dd��Zde
e
e
e
e
d�dd�Zee
dd�dd��ZdS)�GoalStateHealthReportera�        <?xml version="1.0" encoding="utf-8"?>
        <Health xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <GoalStateIncarnation>{incarnation}</GoalStateIncarnation>
          <Container>
            <ContainerId>{container_id}</ContainerId>
            <RoleInstanceList>
              <Role>
                <InstanceId>{instance_id}</InstanceId>
                <Health>
                  <State>{health_status}</State>
                  {health_detail_subsection}
                </Health>
              </Role>
            </RoleInstanceList>
          </Container>
        </Health>
        z�        <Details>
          <SubStatus>{health_substatus}</SubStatus>
          <Description>{health_description}</Description>
        </Details>
        ZReadyZNotReadyZProvisioningFailediN)�
goal_stater��endpointrQcCs||_||_||_dS)a?Creates instance that will report provisioning status to an endpoint

        @param goal_state: An instance of class GoalState that contains
            goal state info such as incarnation, container id, and instance id.
            These 3 values are needed when reporting the provisioning status
            to Azure
        @param azure_endpoint_client: Instance of class AzureEndpointHttpClient
        @param endpoint: Endpoint (string) where the provisioning status report
            will be sent to
        @return: Instance of class GoalStateHealthReporter
        N)�_goal_state�_azure_endpoint_client�	_endpoint)r�r�r�r�rrrr��sz GoalStateHealthReporter.__init__r�c
Cs�|j|jj|jj|jj|jd�}t�d�z|j|d�Wn8t	yr}z t
d|tjd��WYd}~n
d}~00t�d�dS)N)r�r�r��statusz Reporting ready to Azure fabric.��documentz#exception while reporting ready: %srNzReported ready to Azure fabric.)
�build_reportr�r�r�r��PROVISIONING_SUCCESS_STATUSr<r=�_post_health_reportrqrV�errorrL)r�r�rErrr�send_ready_signal�s �
�z)GoalStateHealthReporter.send_ready_signal�rrQc
Cs�|j|jj|jj|jj|j|j|d�}z|j|d�Wn<tyr}z$d|}t	|t
jd��WYd}~n
d}~00t
�d�dS)N)r�r�r�r��	substatusrr�z%exception while reporting failure: %srNz!Reported failure to Azure fabric.)
r�r�r�r�r��PROVISIONING_NOT_READY_STATUS�PROVISIONING_FAILURE_SUBSTATUSr�rqrVr<r�rs)r�rr�rErPrrr�send_failure_signal�s�z+GoalStateHealthReporter.send_failure_signal)r�r�r�r�rQc	Cs\d}|dur.|jjt|�t|d|j��d�}|jjtt|��t|�t|�t|�|d�}|S)Nr&)Zhealth_substatusZhealth_description)r�r�r�Z
health_statusZhealth_detail_subsection)�%HEALTH_DETAIL_SUBSECTION_XML_TEMPLATErlr�"HEALTH_REPORT_DESCRIPTION_TRIM_LEN�HEALTH_REPORT_XML_TEMPLATErp)	r�r�r�r�r�r�rZ
health_detailZ
health_reportrrrr��s 	��
�z$GoalStateHealthReporter.build_report)r�rQcCsJt�t�d�t�d�d�|j�}|jj||ddid�t�d�dS)Nrz&Sending health report to Azure fabric.zhttp://{}/machine?comp=healthzContent-Typeztext/xml; charset=utf-8)rYr�z/Successfully sent health report to Azure fabric)	rvr?r�r<r=rlr�r�r�)r�r�r�rrrr��s

�z+GoalStateHealthReporter._post_health_report)NN)rr�r�r'r�r�r�r�r�r�r�r�r�rpr�r!r�r�r�r�rrrrr�{s<��	���r�c@s�eZdZed�dd�Zdd�Zedd�dd	��Zedee	ed�d
d��Z
eedd�d
d��Zeee
d�dd��Zeed�dd��Zeeee
d�dd��Zee
eed�dd��Zeeeed�dd��ZdS)�WALinuxAgentShim�r�cCs||_d|_d|_dSr{)r��openssl_managerr�)r�r�rrrr�szWALinuxAgentShim.__init__cCs|jdur|j��dSr{)r�r�r�rrrr�"s
zWALinuxAgentShim.clean_upNr�c
CsXzt�d�t�d|g�Wn6tyR}ztd|tjd�WYd}~n
d}~00dS)NzEjecting the provisioning isoZejectz(Failed ejecting the provisioning iso: %srN)r<r=r
rqrV)r��iso_devrErrr�	eject_iso&s
�zWALinuxAgentShim.eject_isocCs�d}|jdur&|dur&t�|_|jj}|jdur:t|�|_|j|dud�}d}|durb|�||�}t||j|j�}|dur�|�	|�|�
�|S)a�Gets the VM's GoalState from Azure, uses the GoalState information
        to report ready/send the ready signal/provisioning complete signal to
        Azure, and then uses pubkey_info to filter and obtain the user's
        pubkeys from the GoalState.

        @param pubkey_info: List of pubkey values and fingerprints which are
            used to filter and obtain the user's pubkey values from the
            GoalState.
        @return: The list of user's authorized pubkey values.
        N�r�)r�r�r�r�r��_fetch_goal_state_from_azure�_get_user_pubkeysr�r�rr�)r��pubkey_infor�Zhttp_client_certificater��ssh_keys�health_reporterrrr�"register_with_azure_and_fetch_data1s*
��
�
z3WALinuxAgentShim.register_with_azure_and_fetch_datar�cCs@|jdurtd�|_|jdd�}t||j|j�}|j|d�dS)z�Gets the VM's GoalState from Azure, uses the GoalState information
        to report failure/send provisioning failure signal to Azure.

        @param: user visible error description of provisioning failure.
        NFr�r)r�r�rr�r�r�)r�rr�rrrr�&register_with_azure_and_report_failureWs


�z7WALinuxAgentShim.register_with_azure_and_report_failure)r�rQcCs|��}|�||�S)aFetches the GoalState XML from the Azure endpoint, parses the XML,
        and returns a GoalState object.

        @param need_certificate: switch to know if certificates is needed.
        @return: GoalState object representing the GoalState XML
        )�"_get_raw_goal_state_xml_from_azure�_parse_raw_goal_state_xml)r�r��unparsed_goal_state_xmlrrrrfs
�z-WALinuxAgentShim._fetch_goal_state_from_azurec
Cs�t�d�d�|j�}z@tjddtd��|j�|�}Wd�n1sJ0YWn8t	y�}z t
d|tjd��WYd}~n
d}~00t�d	�|j
S)
z�Fetches the GoalState XML from the Azure endpoint and returns
        the XML as a string.

        @return: GoalState XML string
        zRegistering with Azure...z!http://{}/machine/?comp=goalstatezgoalstate-retrievalzretrieve goalstaterNz9failed to register with Azure and fetch GoalState XML: %srNz#Successfully fetched GoalState XML.)r<rLrlr�rrrr�r�rqrVrsr=r�)r�r�ZresponserErrrr
us&
�.��
z3WALinuxAgentShim._get_raw_goal_state_xml_from_azure)rr�rQc
Cs�zt||j|�}Wn8tyJ}z td|tjd��WYd}~n
d}~00d�d|jd|jd|j	g�}t|tj
d�|S)aParses a GoalState XML string and returns a GoalState object.

        @param unparsed_goal_state_xml: GoalState XML string
        @param need_certificate: switch to know if certificates is needed.
        @return: GoalState object representing the GoalState XML
        z"Error processing GoalState XML: %srNNz, zGoalState XML container id: %szGoalState XML instance id: %szGoalState XML incarnation: %s)r�r�rqrVr<rsr)r�r�r�r=)r�rr�r�rErPrrrr�s(
����z*WALinuxAgentShim._parse_raw_goal_state_xml)r�rrQcCsHg}|jdurD|durD|jdurDt�d�|j�|j�}|�||�}|S)a�Gets and filters the VM admin user's authorized pubkeys.

        The admin user in this case is the username specified as "admin"
        when deploying VMs on Azure.
        See https://docs.microsoft.com/en-us/cli/azure/vm#az-vm-create.
        cloud-init expects a straightforward array of keys to be dropped
        into the admin user's authorized_keys file. Azure control plane exposes
        multiple public keys to the VM via wireserver. Select just the
        admin user's key(s) and return them, ignoring any other certs.

        @param goal_state: GoalState object. The GoalState object contains
            a certificate XML, which contains both the VM user's authorized
            pubkeys and other non-user pubkeys, which are used for
            MSI and protected extension handling.
        @param pubkey_info: List of VM user pubkey dicts that were previously
            obtained from provisioning data.
            Each pubkey dict in this list can either have the format
            pubkey['value'] or pubkey['fingerprint'].
            Each pubkey['fingerprint'] in the list is used to filter
            and obtain the actual pubkey value from the GoalState
            certificates XML.
            Each pubkey['value'] requires no further processing and is
            immediately added to the return list.
        @return: A list of the VM user's authorized pubkey values.
        Nz/Certificate XML found; parsing out public keys.)r�r�r<r=r��_filter_pubkeys)r�r�rr�keys_by_fingerprintrrrr�s���
�z"WALinuxAgentShim._get_user_pubkeys)rrrQcCs|g}|D]n}d|vr,|dr,|�|d�qd|vrj|drj|d}||vr\|�||�qvt�d|�qt�d|�q|S)a8Filter and return only the user's actual pubkeys.

        @param keys_by_fingerprint: pubkey fingerprint -> pubkey value dict
            that was obtained from GoalState Certificates XML. May contain
            non-user pubkeys.
        @param pubkey_info: List of VM user pubkeys. Pubkey values are added
            to the return list without further processing. Pubkey fingerprints
            are used to filter and obtain the actual pubkey values from
            keys_by_fingerprint.
        @return: A list of the VM user's authorized pubkey values.
        r�r�zIovf-env.xml specified PublicKey fingerprint %s not found in goalstate XMLzFovf-env.xml specified PublicKey with neither value nor fingerprint: %s)r�r<rs)rrr�Zpubkeyr�rrrr
�s"
��z WALinuxAgentShim._filter_pubkeys)NN)rr�r�rpr�r�r!rrrrr	r�r�rr
r�listrr��dictr
rrrrr�s6
�
�%���)r�)r�rr�cCs2t|d�}z|j||d�W|��S|��0dS)Nr�)rr�)r�rr�)r�rr��shimrrr�get_metadata_from_fabric�s
��r)r�rcCs:t|d�}|st}z|j|d�W|��n
|��0dS)Nr�r)r��+DEFAULT_REPORT_FAILURE_USER_VISIBLE_MESSAGEr	r�)r�rrrrr�report_failure_to_fabrics
rcCs(td|tjd�td|tjd�dS)Nzdhclient output stream: %srNzdhclient error stream: %s)rVr<r=)rF�errrrr�dhcp_log_cbs
�
�r)NN)N)Ir[r`Zloggingrgr�r�r�r'r?r\�
contextlibrrrzr�typingrrZ	xml.etreerZxml.sax.saxutilsrZ	cloudinitr	r
rrr
rZcloudinit.reportingrZcloudinit.settingsrZ	getLoggerrr<ZDEFAULT_WIRESERVER_ENDPOINTrBrKrUr_rkrorrrr!r4rIrMrprArVrbrvrdr�r�rr�r��bytesr�r�rqr�r�r�r�r�rrrrrrr�<module>s� 
��
S
��(

	�
�+�"?"d�
�

Youez - 2016 - github.com/yon3zu
LinuXploit