
    d	{                        d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dl	m
Z
mZ d dlmZmZ d dlmZmZmZ d dlmZ d dlmZmZ d dlmZ d d	lmZmZ d d
lmZ d dlm Z m!Z!m"Z" d dl#m$Z$ d dl%m&Z&m'Z'm(Z( dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:d Z; G d! d"e<      Z= G d# d$e>      Z? G d% d&e?      Z@ G d' d(e<      ZA G d) d*e<      ZBy)+    N)loggerconf)
ErrorStateERROR_STATE_HOST_PLUGIN_FAILURE)WALAEventOperation	add_event)	HttpErrorProtocolErrorResourceGoneError)FlexibleVersion)ustr
httpclient)HealthService)VmSettingsParseErrorGoalStateSource)ExtensionsGoalStateFactory)restutiltextutiltimeutil)
remove_bom)
AGENT_NAMEAGENT_VERSIONPY_VERSION_MAJORi  zhttp://{0}:{1}/versionszhttp://{0}:{1}/vmSettingsz http://{0}:{1}/extensionArtifactzhttp://{0}:{1}/statuszhttp://{0}:{1}/vmAgentLogzhttp://{0}:{1}/healthz
2015-09-01zx-ms-client-namezx-ms-client-versionzx-ms-client-correlationidzx-ms-containeridzx-ms-vmagentlog-deploymentidzx-ms-versionzx-ms-host-config-namezx-ms-artifact-locationzx-ms-artifact-manifest-locationzx-ms-verify-from-artifacts-blobi  @ c                   F   e Zd ZdZ ej
                  d      Z ej
                  d      Zd Ze	d        Z
d Zd Zd Zd	 Zd
 Zd Zd Zd Zd dZd!dZd"dZe	d        Zd Zd dZd Zd Zd dZd Zd Zd Ze	d        Ze	d        Z e	d        Z!e	d        Z"d#dZ#y)$HostPluginProtocolF   )minutesc                 X   |t        d      d| _        d| _        d| _        || _        d| _        d| _        d| _        d| _        t        |      | _
        t        t              | _        t        t              | _        d| _        d| _        t#        d      | _        d| _        t(        j(                  j+                         | _        t/               | _        d| _        t4        j6                  j9                  | j;                               s]d| _        t(        j(                  j+                         | _        t=        j>                  t(        j(                  j@                        | _!        yd| _        t(        j(                  j+                         | _        tD        jG                         | _!        y)z
        NOTE: Before using the HostGAPlugin be sure to invoke GoalState.update_host_plugin_headers() to initialize
              the container id and role config name
        Nz#HostGAPlugin: Endpoint not providedF)min_timedeltaz0.0.0.0T)$r
   is_initializedis_availableapi_versionsendpointcontainer_iddeployment_idrole_config_namemanifest_urir   health_servicer   r   fetch_error_statestatus_error_statefetch_last_timestampstatus_last_timestampr   _version_supports_vm_settingsdatetimenow _supports_vm_settings_next_check_VmSettingsErrorReporter_vm_settings_error_reporter_cached_vm_settingsospathexists_get_fast_track_state_filer   create_timestampmin_fast_track_timestampr   get_fast_track_timestamp)selfr#   s     L/usr/lib/python3/dist-packages/azurelinuxagent/common/protocol/hostplugin.py__init__zHostPluginProtocol.__init__E   sU   
  EFF#!   ! $ +H5!+:Y!Z",;Z"[$(!%)"'	2%)"080A0A0E0E0G-+C+E(#'  ww~~d==?@).D&4<4E4E4I4I4KD1)1)B)B8CTCTCXCX)YD&)-D&4<4E4E4I4I4KD1);)T)T)VD&    c                 2    | | j                  d      d   S d S )N.r   )split)r&   s    r>   _extract_deployment_idz)HostPluginProtocol._extract_deployment_idi   s'     2B1M%%c*1-WSWWr@   c                 X    | j                   | j                         \  }}| j                   S )zO
        Returns True if the HostGAPlugin supports the vmSettings API.
        )r.   fetch_vm_settings)r=   _s     r>   check_vm_settings_supportz,HostPluginProtocol.check_vm_settings_supportn   s.    
 %%-))+DAq)))r@   c                     || _         y N)r$   )r=   new_container_ids     r>   update_container_idz&HostPluginProtocol.update_container_idw   
    ,r@   c                 >    || _         | j                  |      | _        y rJ   )r&   rD   r%   )r=   new_role_config_names     r>   update_role_config_namez*HostPluginProtocol.update_role_config_namez   s     4!889MNr@   c                     || _         y rJ   )r'   )r=   new_manifest_uris     r>   update_manifest_uriz&HostPluginProtocol.update_manifest_uri~   rM   r@   c                     | j                   sb| j                         | _        t        | j                  v | _        | j                  | _         t        t        j                  | j                         | j                  S )N)op
is_success)r    get_api_versionsr"   API_VERSIONr!   r   r   InitializeHostPluginr=   s    r>   ensure_initializedz%HostPluginProtocol.ensure_initialized   sc    "" $ 5 5 7D +t/@/@ @D"&"3"3D+@@!%!2!24   r@   c                     t         j                  | j                  t              }t	        j
                  d|       t        j                  |d      }t        j                  |      S )zb
        Call the /health endpoint
        :return: True if 200 received, False otherwise
        z'HostGAPlugin: Getting health from [{0}]r   )	max_retry)	URI_FORMAT_HEALTHformatr#   HOST_PLUGIN_PORTr   verboser   http_getrequest_succeeded)r=   urlresponses      r>   
get_healthzHostPluginProtocol.get_health   sO    
  &&t}}'79@#F$$SA6))(33r@   c                    t         j                  | j                  t              }t	        j
                  dj                  |             g }d}d}	 t        | j                  i}t        j                  ||      }t        j                  |      rPt        j                  |      }t	        j                  dj                  |             t        j                  |       }n&t        t        |j!                               d      }d}| j$                  j'                  ||	       |S # t"        $ r.}t	        j                  dj                  |             Y d }~Qd }~ww xY w)
Nz+HostGAPlugin: Getting API versions at [{0}] Fz*HostGAPlugin: Failed Get API versions: {0}utf-8encodingTz-HostGAPlugin: Exception Get API versions: {0}
is_healthyre   )URI_FORMAT_GET_API_VERSIONSr_   r#   r`   r   ra   _HEADER_CONTAINER_IDr$   r   rb   request_failedread_response_errorerrorrequest_failed_at_hostpluginr   r   readr	   r(   report_host_plugin_versions)r=   rd   
return_valerror_responserm   headersre   es           r>   rW   z#HostPluginProtocol.get_api_versions   s#   )001ACDs	%

	T+T->->?G((g6H&&x0!)!=!=h!GIPPQ_`a!)!F!Fx!PP
!*X]]_"=P
!
 	77:Xf7g  	TLLHOOPQRSS	Ts   B3D" "	E+$EEc                     t         j                  | j                  t              }t        t
        t        | j                  t        | j                  t        |i}||fS rJ   )URI_FORMAT_VM_SETTINGSr_   r#   r`   _HEADER_VERSIONrX   ro   r$   _HEADER_HOST_CONFIG_NAMEr&   _HEADER_CORRELATION_ID)r=   correlation_idrd   rx   s       r>   get_vm_settings_requestz*HostPluginProtocol.get_vm_settings_request   sN    $++DMM;KL [!2!2#T%:%:!>	
 G|r@   Nc                 X   | j                         st        d      t        j                  |      rt        d      t        j                  | j                  t              }t        t        t        | j                  t        | j                  t        |i}|r	d|t        <   |	||t         <   ||fS )Nz2HostGAPlugin: Host plugin channel is not availablez4HostGAPlugin: No extension artifact url was providedtrue)r[   r
   r   is_str_none_or_whitespace!URI_FORMAT_GET_EXTENSION_ARTIFACTr_   r#   r`   r|   rX   ro   r$   r}   r&   _HEADER_ARTIFACT_LOCATION"_HEADER_VERIFY_FROM_ARTIFACTS_BLOB"_HEADER_ARTIFACT_MANIFEST_LOCATION)r=   artifact_urluse_verify_headerartifact_manifest_urlrd   rx   s         r>   get_artifact_requestz'HostPluginProtocol.get_artifact_request   s    &&( TUU--l; VWW/66t}}FVW[#T%6%6')>)>(,	8
 :@G67 ,:OG67G|r@   c                 |   |t         j                  | j                  t              k7  ry | j	                  || j
                  | j                  t        j                        r^t        j                  j                         | _        | j
                  j                         du }| j                  j                  |||       y y )NF)rm   sourcere   )r   r_   r#   r`   should_reportr)   r+   r   FETCH_REPORTING_PERIODr/   utcnowis_triggeredr(   %report_host_plugin_extension_artifact)r=   urirm   r   re   health_signals         r>   report_fetch_healthz&HostPluginProtocol.report_fetch_health   s    3::4==JZ[[j"44"770GGI )1(9(9(@(@(BD% 22??AUJMEEQ^MSOW F YIr@   c                 *   | j                  || j                  | j                  t        j                        r]t
        j
                  j                         | _        | j                  j                         du }| j                  j                  ||       y y )NFrl   )
r   r*   r,   r   STATUS_REPORTING_PERIODr/   r   r   r(   report_host_plugin_status)r=   rm   re   r   s       r>   report_status_healthz'HostPluginProtocol.report_status_health   s    j"55"880HHJ *2):):)A)A)CD& 33@@BeKM99]CK : MJr@   c                     | r|j                          n|j                          |!t        j                  j                         |z
  }t        j                  j                         ||z   k\  S )a  
        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
        )resetincrr/   r   )rm   error_statelast_timestampperiods       r>   r   z HostPluginProtocol.should_report   s_      !%..557&@N  '')nv.EFFr@   c                 v   | j                         st        d      |t        d      t        j                  | j                  t
              }t        j                  ||| j                         dd      }t        j                  |      r/t        j                  |      }t        dj                  |            |S )z
        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
        +HostGAPlugin: HostGAPlugin is not availablezRHostGAPlugin: Invalid argument passed to upload VM logs. Content was not provided.T   )datarx   redact_datatimeoutz(HostGAPlugin: Upload VM logs failed: {0})r[   r
   URI_FORMAT_PUT_LOGr_   r#   r`   r   http_put_build_log_headersrp   rq   r	   )r=   contentrd   re   rw   s        r>   
put_vm_logzHostPluginProtocol.put_vm_log  s    
 &&( MNN? tuu ''7GH$$S*1-1-D-D-F15-/	1 ""8,%99(CNFMMn]^^r@   c                    | j                         st        d      ||j                  t        d      t        j                  d       |j
                  r|j
                  n|}|dk(  r| j                  ||       y| j                  ||       y)a  
        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
        r   Nz*HostGAPlugin: Status blob was not providedzHostGAPlugin: Posting VM status	BlockBlob)r[   r
   	vm_statusr   ra   type_put_block_blob_status_put_page_blob_status)r=   status_blobsas_urlconfig_blob_type	blob_types        r>   put_vm_statusz HostPluginProtocol.put_vm_status  s     &&( MNN+"7"7"? LMM89(3(8(8K$$>N	#''=&&w<r@   c                 P   t         j                  | j                  t              }t	        j
                  || j                  ||j                  t        |j                              t        |j                  d            | j                               }t	        j                  |      rXt	        j                  |      }t	        j                  |       }| j                  ||       t!        dj                  |            | j                  d       t#        j$                  d       y )	Nri   rj   r   rx   rl   z'HostGAPlugin: Put BlockBlob failed: {0}Trm   z,HostGAPlugin: Put BlockBlob status succeeded)URI_FORMAT_PUT_VM_STATUSr_   r#   r`   r   r   _build_status_dataget_block_blob_headerslenr   	bytearray_build_status_headersrp   rq   rs   r   r	   r   ra   )r=   r   r   rd   re   rw   rm   s          r>   r   z)HostPluginProtocol._put_block_blob_status.  s    &--dmm=MN$$S*.*A*A)0)4)K)KCP[P`P`La)b)2;3C3Cg)V+X .2-G-G-IK ""8,%99(CN%BB8LLJ%%n%UE#VN35 5 %%%6NNIJr@   c           
      p   t         j                  | j                  t              }t	        |j
                  d      }t        t        |      dz   dz        dz  }t	        |j
                  j                  |      d      }t        j                  || j                  ||j                  |            | j                               }t        j                  |      rXt        j                  |      }t        j                   |       }| j#                  ||       t%        dj                  |            | j#                  d	       t'        j(                  d
       |j+                  d      dk  rdj                  |      }ndj                  |      }d}	d}
|	t        |      k  r|	t-        t        |      |	z
  t.              z   }
t        |
|	z
  dz   dz        dz  }t	        |      }||	|
 |d|
|	z
   t        j                  || j                  ||j1                  |	|
      |      | j                               }t        j                  |      rZt        j                  |      }t        j                   |       }| j#                  ||       t%        dj                  |	|
|            |
}	|	t        |      k  ry y )Nri   rj   i  i   r   rl   z+HostGAPlugin: Failed PageBlob clean-up: {0}Tr   z)HostGAPlugin: PageBlob clean-up succeeded?r   z{0}?comp=pagez{0}&comp=pagez5HostGAPlugin Error: Put PageBlob bytes [{0},{1}]: {2})r   r_   r#   r`   r   r   intr   ljustr   r   r   get_page_blob_create_headersr   rp   rq   rs   r   r	   r   ra   countr:   MAXIMUM_PAGEBLOB_PAGE_SIZEget_page_blob_page_headers)r=   r   r   rd   statusstatus_sizere   rw   rm   startend	page_sizebufs                r>   r   z(HostPluginProtocol._put_page_blob_statusB  s   &--dmm=MN ;++g>3v;,34s:;++11+>Q $$S*.*A*A)0)4)Q)QR])^+` .2-G-G-I	K ""8,%99(CN%BB8LLJ%%n%UI#VN35 5 %%%6NNFG =="%,,W5G%,,W5Gc&k!#c&kE13MNNCS5[3.#56<II&C"("4C3;  ((.2.E.E-4-8-S-STY[^-_-0/2 261K1K1MOH &&x0!)!=!=h!G!)!F!Fx!PP
))Z.)Y%%+VE3%GI I
 E1 c&k!r@   c                     g }t        |j                               D ]  }|j                  |||   d        ||d}|| j                  |      |d<   t	        j
                  |d      S )N)
headerNameheaderValue)
requestUrirx   r   T)	sort_keys)iterkeysappend_base64_encodejsondumps)r=   r   blob_headersr   rx   namer   s          r>   r   z%HostPluginProtocol._build_status_data}  s{    **,- 	DNN"+D1 	 "
 "11':DOzz$$//r@   c                 ^    t         t        ddt        | j                  t        | j
                  iS )NzContent-typezapplication/json)r|   rX   ro   r$   r}   r&   rZ   s    r>   r   z(HostPluginProtocol._build_status_headers  s-    [. $"3"3$d&;&;	
 	
r@   c                     t         t        t        | j                  t        | j
                  t        t        t        t        t        t        t        j                               iS rJ   )r|   rX   ro   r$   _HEADER_DEPLOYMENT_IDr%   _HEADER_CLIENT_NAMEr   _HEADER_CLIENT_VERSIONr   r~   struuiduuid4rZ   s    r>   r   z%HostPluginProtocol._build_log_headers  sA    [ $"3"3!4#5#5"M"C

$5
 	
r@   c                 v    t        j                  t        |            }t        dkD  r|j	                  d      S |S )N   ri   )base64	b64encodebytesr   decode)r=   r   ss      r>   r   z!HostPluginProtocol._base64_encode  s2    U4[)a88G$$r@   c                  f    t         j                  j                  t        j                         d      S )Nzfast_track.json)r5   r6   joinr   get_lib_dir r@   r>   r8   z-HostPluginProtocol._get_fast_track_state_file  s#     ww||D,,.0ABBr@   c                 ,   	 t        t        j                         d      5 }t        j                  d| i|       d d d        y # 1 sw Y   y xY w# t
        $ r<}t        j                  dt        j                         t        |             Y d }~y d }~ww xY w)Nw	timestampz.Error updating the Fast Track state ({0}): {1})	openr   r8   r   dump	Exceptionr   warnr   )r   file_ry   s      r>   _save_fast_track_statez)HostPluginProtocol._save_fast_track_state  s    	D(CCEsK ;u		;	2E:; ; ; 	DKKHJ\JwJwJy{  AB  |C  D  D	Ds3   A AA AA A 	B2BBc                  H   	 t         j                  j                  t        j	                               r(t        j
                  t        j	                                y y # t        $ r<} t        j                  dt        j	                         t        |              Y d } ~ y d } ~ ww xY w)Nz:Error clearing the current state for Fast Track ({0}): {1})
r5   r6   r7   r   r8   remover   r   r   r   )ry   s    r>   clear_fast_track_statez)HostPluginProtocol.clear_fast_track_state  s    	!ww~~0KKMN		,GGIJ O 	!KKTVh  WD  WD  WFQ! !	!s   AA 	B!%2BB!c                  L   t         j                  j                  t        j	                               s-t        j                  t        j                  j                        S 	 t        t        j	                         d      5 } t        j                  |       d   cddd       S # 1 sw Y   nxY wnH# t        $ r<}t        j                  dt        j	                         t        |             Y d}~nd}~ww xY wt        j                  t        j                  j!                               S )z
        Returns the timestamp of the most recent FastTrack goal state retrieved by fetch_vm_settings(), or None if the most recent
        goal state was Fabric or fetch_vm_settings() has not been invoked.
        rr   NzvCan't retrieve the timestamp for the most recent Fast Track goal state ({0}), will assume the current time. Error: {1})r5   r6   r7   r   r8   r   r9   r/   r:   r   r   loadr   r   r   r   r   )r   ry   s     r>   r<   z+HostPluginProtocol.get_fast_track_timestamp  s     ww~~0KKMN,,X->->-B-BCC	N(CCEsK 5uyy'45 5 5 5 	NKK  Q&AACT!WN N	N (():):)A)A)CDDs0    B- >B 	B-  B)%B- -	C262C--C2c                 ~
     fd}fd}	  j                   s5 j                  t        j                  j                         kD  r
t	               |s j
                  dn j
                  j                  t        t        j                                j                  j                           j                        \  }}|d<   t        j                  ||ddd      }|j                  t         j"                  k(  r
t%               |j                  t         j&                  k(  r |        |j                  t         j(                  k(  r( j
                  df j                  j+                          S |j                  t         j,                  k7  rt        j.                  |      }|j                  t         j0                  k(  rd	j3                  |      } ||      }d
|j                  cxk  rdk  r8n n5 j                  j5                  |t6        j8                         t?        |      d|j                  cxk  rdk  r8n n5 j                  j5                  |t6        j:                         t?        |       j                  j5                  |t6        j<                         t?        |      |jA                         D ]  }|d   jC                         dk(  s|d   }	 n  |d      }
t?        |
      tE        |jG                         d      }tI        jJ                  |	|      }|jL                   jN                  k7  r]|jL                   _'        dj3                  |jL                        }
tQ        jR                  |
       tU        tV        jX                  |
d       |jL                  t[        d      k  r |        d _         | _        |j\                  t^        j`                  k(  r-|jb                   _2         jg                  |jb                         n ji                          |df j                  j+                          S # t>        t$        t        tj        f$ r  tl        $ r}to        |tp              rJdtE        |      v r= |d      }
 j                  j5                  |
t6        jr                         t?        |
       |dj3                  tu        jv                  |                  }
 j                  j5                  |
t6        jx                         t?        |
      d}~ww xY w#  j                  j+                          w xY w)a  
        Queries the vmSettings from the HostGAPlugin and returns an (ExtensionsGoalState, bool) tuple with the vmSettings and
        a boolean indicating if they are an updated (True) or a cached value (False).

        Raises
            * VmSettingsNotSupported if the HostGAPlugin does not support the vmSettings API
            * VmSettingsSupportStopped if the HostGAPlugin stopped supporting the vmSettings API
            * VmSettingsParseError if the HostGAPlugin returned invalid vmSettings (e.g. syntax error)
            * ResourceGoneError if the container ID and roleconfig name need to be refreshed
            * ProtocolError if the request fails for any other reason (e.g. not supported, time out, server error)
        c                  (   	  j                   r`t        j                  d       t        t        j
                  dj                   j                        dd       t         j                        t        j                  d j                         t        t        j
                  dj                   j                        d       t               # d _         t        j                  j                         t        j                  d	
      z    _        w xY w)Nz|The HostGAPlugin stopped supporting the vmSettings API. If there is a pending FastTrack goal state, it will not be executed.z,[VmSettingsSupportStopped] HostGAPlugin: {0}FrU   messagerV   	log_eventzMHostGAPlugin {0} does not support the vmSettings API. Will not use FastTrack.z*[VmSettingsNotSupported] HostGAPlugin: {0}TrU   r   rV      hours)r.   r   r   r   r   
VmSettingsr_   r-   VmSettingsSupportStoppedr;   infoVmSettingsNotSupportedr/   r0   	timedeltar1   rZ   s   r>   raise_not_supportedzAHostPluginProtocol.fetch_vm_settings.<locals>.raise_not_supported  s   n-- KK  !_  `!3!>!>HvH}H}  C  L  L  IM  Z_  kp  q243M3MNNKK oquq~q~!3!>!>HtH{H{  }A  }J  }J  IK  X\  ]022-2*8@8I8I8M8M8ORZRdRdklRm8m5s   CC ADc                 *    dj                  |       S )Nz3GET vmSettings [correlation ID: {0} eTag: {1}]: {2})r_   )msgr   etags    r>   format_messagez<HostPluginProtocol.fetch_vm_settings.<locals>.format_message  s    HOOP^`dfijjr@   Nzif-none-matchFr   T)rx   	use_proxyr]   return_raw_responsez$[Internal error in HostGAPlugin] {0}i  i  i  iW  r   r  z7The vmSettings response does not include an Etag headerri   rj   zHostGAPlugin version: {0}r  z	1.0.8.133z	timed outTimeoutzRequest failed: {0})=r.   r1   r/   r0   r  r4   r  r   r   r   r3   report_requestr   r   rb   r   r   GONEr   	NOT_FOUNDNOT_MODIFIEDreport_summaryOKrq   BAD_GATEWAYr_   report_error_VmSettingsErrorClientErrorServerErrorr	   r
   
getheaderslowerr   rt   r   create_from_vm_settingshost_ga_plugin_versionr-   r   r  r   r   
HostPluginr   r   r   	FastTrackcreated_on_timestampr;   r   r   r   r   
isinstanceIOErrorr  r   format_exceptionRequestFailed)r=   force_updater
  r  rd   rx   re   error_descriptionhresponse_etagr   response_contentvm_settings	exceptionr   r  s   `             @@r>   rF   z$HostPluginProtocol.fetch_vm_settings  sU   	n 	kY	> --$2W2WZbZkZkZoZoZq2q,..'4+C+C+K4QUQiQiQnQnD .N,,;;=77GLC+/(((gZ[quvH*//1'))*"6"66#%*"9"99//6B ,,;;= *--/$,$@$@$J! ??j&<&<<(N(U(UVg(h%$23D$E!(//0S044AABSUeUqUqr $$566 HOO2s244AABSUeUqUqr $$566 44AABSUeUoUop#$566((* -Q4::<6)$%aDM-
 ))bc#G,,#HMMOgF4LL]\ln|}K 11T]]B + B B5<<[=_=_`G$/::GX\] 11OK4PP#%)-D&'2D$!!_%>%>>-8-M-M*++K,L,LM++-$ ,,;;= 02HJ^_ 	 	))W-+i2P(300==gGWG_G_`  (( ))>)E)EhF_F_`iFj)kl00==gGWGeGef((	) ,,;;=s3   EP= 3E!P= EP= ="TB9TTT   T<rJ   )Trh   rh   )rh   )F)$__name__
__module____qualname__is_default_channelr/   r	  r   r   r?   staticmethodrD   rH   rL   rP   rS   r[   rf   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   r8   r   r   r<   rF   r   r@   r>   r   r   ?   s!   /X//:0h00;"WH X X*-O-!	44
*YM G G.0=*K(9v0 

 C C D D ! ! E E x>r@   r   c                       e Zd ZdZy)r  zM
    Indicates that the HostGAPlugin does not support the vmSettings API
    N)r/  r0  r1  __doc__r   r@   r>   r  r  G  s    r@   r  c                   "     e Zd ZdZ fdZ xZS )r  z
    Indicates that the HostGAPlugin supported the vmSettings API in previous calls, but now it does not support it for current call.
    This can happen, for example, if the VM is migrated across nodes with different HostGAPlugin versions.
    c                 8    t         t        |           || _        y rJ   )superr  r?   r   )r=   r   	__class__s     r>   r?   z!VmSettingsSupportStopped.__init__R  s    &68"r@   )r/  r0  r1  r5  r?   __classcell__)r9  s   @r>   r  r  M  s    # #r@   r  c                        e Zd ZdZdZdZdZdZy)r  r  r	   r'  r  r  N)r/  r0  r1  r  r	   r'  r  r  r   r@   r>   r  r  W  s    "K I$M"KGr@   r  c                   T    e Zd ZdZ ej
                  d      Zd Zd Zd Z	d Z
d Zy	)
r2      r   r  c                 $    | j                          y rJ   )_resetrZ   s    r>   r?   z!_VmSettingsErrorReporter.__init__c  s    r@   c                     d| _         d| _        d| _        d| _        d| _        d| _        d| _        t        j                  j                         t        j                  z   | _        y )Nr   )_request_count_error_count_client_error_count_http_error_count_request_failure_count_server_error_count_timeout_countr/   r0   r2   _Period_next_periodrZ   s    r>   r?  z_VmSettingsErrorReporter._resetf  s]    #$ !"&'##$ $--1136N6V6VVr@   c                 .    | xj                   dz  c_         y )Nr   )rA  rZ   s    r>   r  z'_VmSettingsErrorReporter.report_requestp  s    q r@   c                 \   | xj                   dz  c_         | j                   t        j                  k  r-t        t        j
                  dj                  ||      dd       |t        j                  k(  r| xj                  dz  c_	        y |t        j                  k(  r| xj                  dz  c_        y |t        j                  k(  r| xj                  dz  c_        y |t        j                  k(  r| xj                  dz  c_        y |t        j                   k(  r| xj"                  dz  c_        y y )Nr   z	[{0}] {1}TFr   )rB  r2   
_MaxErrorsr   r   r  r_   r  r  rC  r	   rD  r'  rE  r  rF  r  rG  )r=   rr   categorys      r>   r  z%_VmSettingsErrorReporter.report_errors  s    Q 8 C CC+66@R@RS[]b@cpt  AF  G'333$$)$)333""a'")777''1,')555$$)$)1111$ 2r@   c                    t         j                   j                         | j                  k\  r| j                  | j                  | j
                  | j                  | j                  | j                  d}t        j                  |      }t        t        j                  |dd       | j                  dkD  rt        j                  d|       | j!                          y y )N)requestserrorsserverErrorsclientErrorstimeoutsfailedRequestsTFr   r   z[VmSettingsSummary] {0})r/   r0   rI  rA  rB  rF  rC  rG  rE  r   r   r   r   VmSettingsSummaryr   r  r?  )r=   summaryr   s      r>   r  z'_VmSettingsErrorReporter.report_summary  s      "d&7&77"&"5"5"&"3"3"&":":"&":":"&"5"5"&"="=G jj)G+==w[_kpq  1$5w?KKM 8r@   N)r/  r0  r1  rL  r/   r	  rH  r?   r?  r  r  r  r   r@   r>   r2   r2   _  s3    J h  q)GW!%"r@   r2   )Cr   r/   r   os.pathr5   r   azurelinuxagent.commonr   r   !azurelinuxagent.common.errorstater   r   azurelinuxagent.common.eventr   r    azurelinuxagent.common.exceptionr	   r
   r   -azurelinuxagent.common.utils.flexible_versionr   azurelinuxagent.common.futurer   r   -azurelinuxagent.common.protocol.healthservicer   5azurelinuxagent.common.protocol.extensions_goal_stater   r   =azurelinuxagent.common.protocol.extensions_goal_state_factoryr   azurelinuxagent.common.utilsr   r   r   %azurelinuxagent.common.utils.textutilr   azurelinuxagent.common.versionr   r   r   r`   rn   r{   r   r   r   r^   rX   r   r   r~   ro   r   r|   r}   r   r   r   r   objectr   	TypeErrorr  r  r  r2   r   r@   r>   <module>rf     s   &      / Y F X X I : G g d E E < V V 7 4 $F !2 0 + ( . 4 ) 6  2 4 %F "%F ", E> E>PY #5 #v 4v 4r@   