MOON
Server: Apache
System: Linux vps.erhabenn.com.br 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User: machen (1008)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyo
�
d�bc@stddlZddlZddlZddlZddlmZddlmZmZddl	m
Z
mZddlm
Z
mZddlmZddlmZddlmZdd	lmZdd
lmZddlmZmZmZdZd
ZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,d"Z-de.fd ��YZ/dS(#i����N(tlogger(t
ErrorStatetERROR_STATE_HOST_PLUGIN_FAILURE(tWALAEventOperationt	add_event(t	HttpErrort
ProtocolError(tustr(t
HealthService(trestutil(ttextutil(t
remove_bom(t
AGENT_NAMEt
AGENT_VERSIONtPY_VERSION_MAJORishttp://{0}:{1}/versionsshttp://{0}:{1}/vmSettingss http://{0}:{1}/extensionArtifactshttp://{0}:{1}/statusshttp://{0}:{1}/vmAgentLogshttp://{0}:{1}/healths
2015-09-01sx-ms-client-namesx-ms-client-versionsx-ms-client-correlationidsx-ms-containeridsx-ms-vmagentlog-deploymentidsx-ms-versionsx-ms-host-config-namesx-ms-artifact-locationsx-ms-artifact-manifest-locationiitHostPluginProtocolcBseZeZejdd�Zejdd�Zd�Ze	d��Z
d�Zd�Zd�Z
d�Zd�Zd	�Zd
�Zdd�Zeddd
�Zdd�Ze	d��Zd�Zdd�Zd�Zd�Zdd�Zd�Zd�Zd�ZRS(tminutesicCs�|dkrtd��nt|_t|_d|_||_||_|j|�|_	||_
d|_t|�|_
tdt�|_tdt�|_d|_d|_dS(Ns#HostGAPlugin: Endpoint not providedt
min_timedelta(tNoneRtFalsetis_initializedtis_availabletapi_versionstendpointtcontainer_idt_extract_deployment_idt
deployment_idtrole_config_nametmanifest_uriRthealth_serviceRRtfetch_error_statetstatus_error_statetfetch_last_timestamptstatus_last_timestamp(tselfRRR((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyt__init__Bs								cCs!|dk	r|jd�dSdS(Nt.i(Rtsplit(R((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyRSscCs
||_dS(N(R(R"tnew_container_id((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pytupdate_container_idXscCs||_|j|�|_dS(N(RRR(R"tnew_role_config_name((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pytupdate_role_config_name[s	cCs
||_dS(N(R(R"tnew_manifest_uri((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pytupdate_manifest_uri_scCsY|jsR|j�|_t|jk|_|j|_tdtjd|j�n|jS(Ntopt
is_success(Rtget_api_versionsRtAPI_VERSIONRRRtInitializeHostPlugin(R"((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pytensure_initializedbs	
cCsGtj|jt�}tjd|�tj|dd�}tj|�S(sb
        Call the /health endpoint
        :return: True if 200 received, False otherwise
        s'HostGAPlugin: Getting health from [{0}]t	max_retryi(	tURI_FORMAT_HEALTHtformatRtHOST_PLUGIN_PORTRtverboseR	thttp_gettrequest_succeeded(R"turltresponse((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyt
get_healthks
	cCstj|jt�}tjdj|��g}d}t}y�i|jt6}t	j
||�}t	j|�r�t	j|�}tj
dj|��t	j|�}n$tt|j��dd�}t}Wn)tk
r�}tj
dj|��nX|jjd|d|�|S(	Ns+HostGAPlugin: Getting API versions at [{0}]ts*HostGAPlugin: Failed Get API versions: {0}tencodingsutf-8s-HostGAPlugin: Exception Get API versions: {0}t
is_healthyR:(tURI_FORMAT_GET_API_VERSIONSR4RR5RR6RRt_HEADER_CONTAINER_IDR	R7trequest_failedtread_response_errorterrortrequest_failed_at_hostpluginRRtreadtTrueRRtreport_host_plugin_versions(R"R9t
return_valterror_responseR>theadersR:te((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyR.vs(	

cCsGtj|jt�}itt6|jt6|jt	6|t
6}||fS(N(tURI_FORMAT_VM_SETTINGSR4RR5R/t_HEADER_VERSIONRR@Rt_HEADER_HOST_CONFIG_NAMEt_HEADER_CORRELATION_ID(R"tcorrelation_idR9RJ((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pytget_vm_settings_request�s


cCs�|j�std��ntj|�r9td��ntj|jt�}itt	6|j
t6|jt
6|t6}|dk	r�||t<n||fS(Ns2HostGAPlugin: Host plugin channel is not availables4HostGAPlugin: No extension artifact url was provided(R1RR
tis_str_none_or_whitespacet!URI_FORMAT_GET_EXTENSION_ARTIFACTR4RR5R/RMRR@RRNt_HEADER_ARTIFACT_LOCATIONRt"_HEADER_ARTIFACT_MANIFEST_LOCATION(R"tartifact_urltartifact_manifest_urlR9RJ((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pytget_artifact_request�s	




R<cCs�|tj|jt�krdS|j||j|jtj�r�t	j	j
�|_|jj�tk}|j
jd|d|d|�ndS(NR>tsourceR:(RSR4RR5t
should_reportRR RtFETCH_REPORTING_PERIODtdatetimetutcnowtis_triggeredRRt%report_host_plugin_extension_artifact(R"turiR>RYR:t
health_signal((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pytreport_fetch_health�s	cCsh|j||j|jtj�rdtjj�|_|jj�tk}|j	j
d|d|�ndS(NR>R:(RZRR!RtSTATUS_REPORTING_PERIODR\R]R^RRtreport_host_plugin_status(R"R>R:Ra((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pytreport_status_health�s	cCsV|r|j�n
|j�|dkr?tjj�|}ntjj�||kS(s�
        Determine whether a health signal should be reported
        :param is_healthy: whether the current measurement is healthy
        :param error_state: the error state which is tracking time since failure
        :param last_timestamp: the last measurement time stamp
        :param period: the reporting period
        :return: True if the signal should be reported, False otherwise
        N(tresettincrRR\R](R>terror_statetlast_timestamptperiod((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyRZ�s

cCs�|j�std��n|dkr6td��ntj|jt�}tj|d|d|j	�dt
�}tj|�r�tj|�}t
dj|���n|S(s�
        Try to upload VM logs, a compressed zip file, via the host plugin /vmAgentLog channel.
        :param content: the binary content of the zip file to upload
        s+HostGAPlugin: HostGAPlugin is not availablesRHostGAPlugin: Invalid argument passed to upload VM logs. Content was not provided.tdataRJtredact_datas(HostGAPlugin: Upload VM logs failed: {0}N(R1RRtURI_FORMAT_PUT_LOGR4RR5R	thttp_putt_build_log_headersRFRARBR(R"tcontentR9R:RI((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyt
put_vm_log�s	cCs�|j�std��n|dks6|jdkrEtd��ntjd�|jrd|jn|}|dkr�|j||�n|j||�dS(s
        Try to upload the VM status via the host plugin /status channel
        :param sas_url: the blob SAS url to pass to the host plugin
        :param config_blob_type: the blob type from the extension config
        :type status_blob: StatusBlob
        s+HostGAPlugin: HostGAPlugin is not availables*HostGAPlugin: Status blob was not providedsHostGAPlugin: Posting VM statust	BlockBlobN(	R1RRt	vm_statusRR6ttypet_put_block_blob_statust_put_page_blob_status(R"tstatus_blobtsas_urltconfig_blob_typet	blob_type((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyt
put_vm_status�s
c
Cs�tj|jt�}tj|d|j||jt|j	��t
|j	dd��d|j��}tj|�r�tj
|�}tj|�}|jd|d|�tdj|���n|jdt�tjd�dS(	NRkR=sutf-8RJR>R:s'HostGAPlugin: Put BlockBlob failed: {0}s,HostGAPlugin: Put BlockBlob status succeeded(tURI_FORMAT_PUT_VM_STATUSR4RR5R	Rnt_build_status_datatget_block_blob_headerstlenRkt	bytearrayt_build_status_headersRARBRDReRRFRR6(R"RxRwR9R:RIR>((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyRus	c
Csutj|jt�}t|jdd�}tt|�dd�d}t|jj|�dd�}t	j
|d|j||j|��d|j
��}t	j|�r�t	j|�}t	j|�}|jd|d|�td	j|���n|jdt�tjd
�|jd�dkr<d
j|�}ndj|�}d}	d}
x|	t|�krp|	tt|�|	t�}
t|
|	dd�d}t|�}||	|
!|d|
|	+t	j
|d|j||j|	|
�|�d|j
��}t	j|�rgt	j|�}t	j|�}|jd|d|�tdj|	|
|���n|
}	qZWdS(NR=sutf-8i�iRkRJR>R:s+HostGAPlugin: Failed PageBlob clean-up: {0}s)HostGAPlugin: PageBlob clean-up succeededt?is
{0}?comp=pages
{0}&comp=pages5HostGAPlugin Error: Put PageBlob bytes [{0},{1}]: {2}(R|R4RR5R�RktintRtljustR	RnR}tget_page_blob_create_headersR�RARBRDReRRFRR6tcounttmintMAXIMUM_PAGEBLOB_PAGE_SIZEtget_page_blob_page_headers(
R"RxRwR9tstatuststatus_sizeR:RIR>tstarttendt	page_sizetbuf((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyRv sR	
	cCs�g}x9t|j��D]%}|ji|d6||d6�qWi|d6|d6}|dk	rx|j|�|d<ntj|dt�S(Nt
headerNametheaderValuet
requestUriRJRpt	sort_keys(titertkeystappendRt_base64_encodetjsontdumpsRF(R"Rxtblob_headersRpRJtnameRk((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyR}[s	
cCs&itt6dd6|jt6|jt6S(Nsapplication/jsonsContent-type(R/RMRR@RRN(R"((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyR�ks

cCs@itt6|jt6|jt6tt6tt	6t
tj��t
6S(N(R/RMRR@Rt_HEADER_DEPLOYMENT_IDRt_HEADER_CLIENT_NAMER
t_HEADER_CLIENT_VERSIONtstrtuuidtuuid4RO(R"((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyRoss

cCs2tjt|��}tdkr.|jd�S|S(Nisutf-8(tbase64t	b64encodetbytesRtdecode(R"Rkts((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyR�}s
N( t__name__t
__module__Rtis_default_channelR\t	timedeltaR[RcR#tstaticmethodRR'R)R+R1R;R.RQRRXRFRbReRZRqR{RuRvR}R�RoR�(((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyR<s0									
			;		
ii@(0R�R\R�R�tazurelinuxagent.commonRt!azurelinuxagent.common.errorstateRRtazurelinuxagent.common.eventRRt azurelinuxagent.common.exceptionRRtazurelinuxagent.common.futureRt-azurelinuxagent.common.protocol.healthserviceRtazurelinuxagent.common.utilsR	R
t%azurelinuxagent.common.utils.textutilRtazurelinuxagent.common.versionRR
RR5R?RLRSR|RmR3R/R�R�ROR@R�RMRNRTRUR�tobjectR(((sN/usr/lib/python2.7/site-packages/azurelinuxagent/common/protocol/hostplugin.pyt<module>s@