
    p
f_G                       d dl Z d dlZd dlZd dlZd dlZd dlZd dlZ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 d dlmZ d dlmZ d dlmZmZ d dlmZmZ d dlmZ d d	lmZmZmZmZ d d
l m!Z!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- d dl.m/Z/m0Z0 d dl1m2Z2m3Z3m4Z4m5Z5 d dl6m7Z7 d dlm8Z8 d dl9m:Z:m;Z; d dl<m=Z= d dl>m?Z? d dl@mAZA d dlBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZP d dlQmRZRmSZS d dlTmUZU d dlVmWZW d dlXmYZYmZZZm[Z[m\Z\m]Z] d dl^m_Z_ d dl`maZa dZbdZcd Zdd!Zed"Zfd#Zgd$Zhd#Zid"Zjd#Zkd!Zld%Zmd&Zng d'Zo G d( d)ep      Zq G d* d+ep      Zrd, Zs G d- d.ep      Zt G d/ d0ep      Zu G d1 d2ep      Zvy)3    N)datetime	timedelta)conf)logger)get_imds_client)fileutiltextutil)get_supported_feature_by_nameSupportedFeatureNames)CGroupConfigurator)	add_event0initialize_event_logger_vminfo_common_parametersWALAEventOperationEVENTS_DIRECTORY)UpdateErrorExitExceptionAgentUpgradeExitExceptionAgentMemoryExceededException)ustr)
get_osutilsystemd)PersistFirewallRulesHandler)GoalStateSource)HostPluginProtocolVmSettingsNotSupported)VMAgentUpdateStatusVMAgentUpdateStatusesExtHandlerPackageList	VERSION_0)get_protocol_util)	shellutil)StateArchiverAGENT_STATUS_FILE)FlexibleVersion)AddFirewallRules)CommandError)AGENT_LONG_NAME
AGENT_NAMEAGENT_DIR_PATTERNCURRENT_AGENTAGENT_VERSIONCURRENT_VERSIONDISTRO_NAMEDISTRO_VERSIONget_lis_versionhas_logrotatePY_VERSION_MAJORPY_VERSION_MINORPY_VERSION_MICROget_daemon_version)get_collect_logs_handleris_log_collection_allowed)$get_collect_telemetry_events_handler)get_env_handler)HandlerManifestExtHandlersHandlerlist_agent_lib_directoryExtensionStatusValueExtHandlerStatusValue)get_monitor_handler)!get_send_telemetry_events_handlerz
error.jsonzHandlerManifest.json	partitioni  i,     <   current_versioninitial_goal_state)z*.crtz*.p7mz*.pemz*.prvzovf-env.xmlc                   *    e Zd ZdZddZd Zd Zd Zy)ExtensionsSummarya  
    The extensions summary is a list of (extension name, extension status) tuples for the current goal state; it is
    used to report changes in the status of extensions and to keep track of when the goal state converges (i.e. when
    all extensions in the goal state reach a terminal state: success or error.)
    The summary is computed from the VmStatus reported to blob storage.
    Nc                 @   |g | _         d| _        y t        d |j                  j                        D cg c]  }|j
                  |j                  f c}| _         | j                   j                  d        t        d | j                   D              | _        y c c}w )NTc                 6    | j                   | j                   S | S N)extension_status)hs    ;/usr/lib/python3/dist-packages/azurelinuxagent/ga/update.py<lambda>z,ExtensionsSummary.__init__.<locals>.<lambda>o   s!    \]\n\n\zaFXFX   AB     c                     | d   S )Nr    )ss    rL   rM   z,ExtensionsSummary.__init__.<locals>.<lambda>p   s
    AaD rN   keyc              3      K   | ]G  \  }}|t         j                  t         j                  t        j                  t        j
                  fv  I y wrI   )r<   successerrorr=   ready	not_ready).0_statuss      rL   	<genexpr>z-ExtensionsSummary.__init__.<locals>.<genexpr>q   sm       !C  ir  ij  lr,@,H,HJ^JdJdf{  gB  gB  DY  Dc  Dc  ,d  "d  !Cs   AA)	summary	convergedmapvmAgentextensionHandlersnamer[   sortall)self	vm_statusos      rL   __init__zExtensionsSummary.__init__i   s    DL!DN 9<  =B  DM  DU  DU  Dg  Dg  9h  i1QVVQXX.  iDLLL.1   !C  vz  vB  vB  !C  CDN is   Bc                 4    | j                   |j                   k(  S rI   )r]   re   others     rL   __eq__zExtensionsSummary.__eq__s   s    ||u}},,rN   c                     | |k(   S rI   rP   rj   s     rL   __ne__zExtensionsSummary.__ne__v   s    EM""rN   c                 ,    t        | j                        S rI   )r   r]   re   s    rL   __str__zExtensionsSummary.__str__y   s    DLL!!rN   rI   )__name__
__module____qualname____doc__rh   rl   rn   rq   rP   rN   rL   rF   rF   b   s    C-#"rN   rF   c                       e Zd ZdZdZdZy)AgentUpgradeTypez3
    Enum for different modes of Agent Upgrade
    HotfixNormalN)rr   rs   rt   ru   rx   ry   rP   rN   rL   rw   rw   }   s     FFrN   rw   c                      t               S rI   )UpdateHandlerrP   rN   rL   get_update_handlerr|      s
    ?rN   c                   \   e Zd Z ed      Z e ej                               Zd ZdAdZ	dBdZ
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zed        Zed        Zd Zd Zd Zd Zd Zed        ZdAdZd Z ed        Z!e"fdZ#d Z$d  Z%d! Z&d" Z'd# Z(d$ Z)d% Z*d& Z+e,d'        Z-e-j\                  d(        Z-e,d)        Z/e,d*        Z0d+ Z1d, Z2e,d-        Z3d. Z4dAd/Z5e6d0fd1Z7d2 Z8ed3        Z9d4 Z:d5 Z;e<fd6Z=d7 Z>d8 Z?d9 Z@ed:        ZAed;        ZBd< ZCd= ZDed>        ZEd? ZFd@ ZGy)Cr{      )minutes)secondsc                 x   t               | _        t               | _        d| _        d | _        d | _        d | _        g | _        d | _	        d | _
        d| _        d | _        d | _        d | _        t        t!        j"                               j%                         | _        d| _        t*        j,                  | _        t*        j,                  | _        d | _        d| _        d| _        t*        j,                  | _        d | _        d | _        d | _        d | _         d| _!        tE               | _#        tH        jJ                  jM                  | jO                                | _(        tS        jT                         stV        | _,        y | jP                  rtS        jZ                         | _,        y tS        j\                         | _,        y )NTr   F)/r   osutilr    protocol_util_is_runninglast_attempt_time_last_hotfix_upgrade_time_last_normal_upgrade_timeagentschild_agentchild_launch_timechild_launch_attemptschild_processsignal_handler_last_telemetry_heartbeatstruuiduuid4upper_heartbeat_id_heartbeat_counterr   min_last_check_memory_usage%_check_memory_usage_last_error_report_vm_size(_heartbeat_update_goal_state_error_count_update_goal_state_error_count$_update_goal_state_last_error_report%_report_status_last_failed_goal_state_last_incarnation_last_extensions_gs_id_goal_state_supports_fast_trackrF   _extensions_summaryospathexists_initial_goal_state_file_path_is_initial_goal_stater   get_extensions_enabled%GOAL_STATE_PERIOD_EXTENSIONS_DISABLED_goal_state_periodget_initial_goal_state_periodget_goal_state_periodrp   s    rL   rh   zUpdateHandler.__init__   si    l.0 "&)-&)-&!%%&"!")-& .446"#(0%5=\\2  9:5./+4<LL1592 "& '+#$)!#4#6 *,''..9[9[9]*^&^#**,&KD#***.*L*L*N'*.*D*D*F'rN   Nc                    | j                   t        d      | j                  3t        j                  t        j                  | j
                        | _        t        j                         sdn| j                  t              }|]t        j                  dt               dj                  t        j                  d         }t!        j"                         }t        }t        }nXt        j                  d|j$                         |j'                         }|j)                         }|j$                  }|j*                  }|dj                  ||      }	 t-        j.                  |      }|d   j1                         d	k(  r$t        j2                  |d<   d
j5                  |      }| j7                  |       t9        j:                  ||t        j<                  t        j>                  t         j@                        | _         t        jB                  d||       d}d}	tE        jD                         }
tE        jD                         |
z
  tF        k  rRtE        jH                  |       	 | j                   jK                         }	|	ntE        jD                         |
z
  tF        k  rR|	|	dk  rdj                  ||      }t        j                  |       tO        tP        |tR        jT                  d|d       |	| j                   jW                         dkD  rsdj                  |||	      }t        jX                  |       nJdj                  |||	      }t        jX                  |       tO        tP        |tR        jT                  d|       d| _         y# tL        $ r d}	Y w xY w# t        $ r}| jZ                  rdj                  ||      }t        jX                  |       dj                  |t-        j\                  |            }tO        tP        |tR        jT                  d|       ||j_                  d|       Y d}~d| _         yd}~ww xY w)z
        This method is called from the daemon to find and launch the most
        current, downloaded agent.

        Note:
        - Most events should be tagged to the launched agent (agent_version)
        Nz=Illegal attempt to launch multiple goal state Agent processesdaemon_versionz-Installed Agent {0} is the most current agentzpython -u {0} -run-exthandlersr   z+Determined Agent {0} to be the latest agent{0} {1}python )cwdstdoutstderrenvz%Agent {0} launched with command '{1}'   z=Agent {0} launched with command '{1}' is successfully runningTF)versionop
is_successmessage	log_eventzOExtHandler process {0} launched with command '{1}' exited with return code: {2}zBAgent {0} launched with command '{1}' failed with return code: {2}r   r   r   r   z>Agent {0} launched with command '{1}' failed with exception: 
is_fatalreason)0r   	Exceptionr   signalSIGTERMforward_signalr   get_autoupdate_enabled$get_latest_agent_greater_than_daemonr,   r   infor*   formatsysargvr   getcwdrb   get_agent_cmdget_agent_dirr   r	   safe_shlex_splitlower
executablejoin_evaluate_agent_health
subprocessPopenr   r   environverbosetimeCHILD_HEALTH_INTERVALsleeppollOSErrorr   r(   r   Enablewaitwarn
is_runningformat_exceptionmark_failure)re   
child_argslatest_agent	agent_cmd	agent_dir
agent_nameagent_versioncmdspoll_intervalret
start_timemsgedetailed_messages                 rL   
run_latestzUpdateHandler.run_latest   s    )[\\&"(--@S@S"TD#'#>#>#@tdFoFo* Gp G,KKH-X8??LI		I&J+MKKFHYHYZ$224I$224I%**J(00M!!((J?IV	V ,,Y7DAw}}(*..QHHTN	''5!+!1!1zzzzJJ" D NNCZQZ[
 MCJ99;+/DD

=),,113C ? 99;+/DD {cQhV]] C ))00##% ;))..014pww&%! C( \bb C ))00$!0 "w  CR  	VX__ C #,#3#3C9R9RST9U#V ))00$,.  + --tDT-U!%	VsE   DN N 5!N C#N NN NN 	P=BP88P=c                 B	   	 t        j                  dt        t               t        j                  dt        t
               t        j                  dt        t        t               dj                  t        t
        t        | j                        j                  | j                  j                  t        t        t        t        j                         t!               t#               
      }t        j                  |       | j$                  j'                         }| j)                  |       t+        |       t-        t.        t0        j2                  |       ddlm}m}  ||      } |        dd	lm}  ||      }| j?                          | jA                          | jC                          | jE                          | jG                          | jI                          | jK                  |       | jM                  |jO                         
       | jQ                  |jO                         
       | jS                          | jU                          tW        | j$                        }	tY               t[               |	t]        |	      g}
t_               r|
ja                  tc                      | je                  |
       t        j                  d| jf                         | jh                  r| jk                  |       | jm                  |
       | jo                  ||       | jq                  |       | js                          tu        jv                  | jf                         | jh                  r| j                          t        j                  d       y# tx        $ rO}t-        t0        jz                  |j|                  d       t        j                  |j|                         Y d}~yd}~wt~        $ r)}t        j                  |j|                         Y d}~d}~wt        $ r}dj                  t        t        |            }| j                  |       t        j                  |       t        j                  t        j                  |             t        j                  d       Y d}~yd}~ww xY w)zV
        This is the main loop which watches for agent and extension updates.
        z"{0} (Goal State Agent version {1})zOS: {0} {1}zPython: {0}.{1}.{2}zDistro: {dist_name}-{dist_ver}; OSUtil: {util_name}; AgentService: {service_name}; Python: {py_major}.{py_minor}.{py_micro}; systemd: {systemd}; LISDrivers: {lis_ver}; logrotate: {has_logrotate};)
	dist_namedist_ver	util_nameservice_namepy_majorpy_minorpy_micror   lis_verr0   r   r   r   )get_exthandlers_handlermigrate_handler_state)get_remote_access_handler)dst_ipzmGoal State Period: {0} sec. This indicates how often the agent checks for new goal states and reports status.F)r   r   r   Nz$Agent {0} failed with exception: {1}r   r   )Jr   r   r'   r+   r-   r.   r1   r2   r3   r   typer   rr   r   r   
is_systemdr/   r0   r   get_protocol_initialize_goal_stater   r   r(   r   OSInfoazurelinuxagent.ga.exthandlersr   r   azurelinuxagent.ga.remoteaccessr   _ensure_no_orphans_emit_restart_event&_emit_changes_in_default_configuration_ensure_partition_assigned_ensure_readonly_files_ensure_cgroups_initialized5_ensure_extension_telemetry_state_configured_properly _ensure_firewall_rules_persistedget_endpoint,_add_accept_tcp_firewall_rule_if_not_enabled _reset_legacy_blacklisted_agents"_cleanup_legacy_goal_state_historyr?   r>   r8   r7   r6   appendr5   _start_threadsr   r   _check_daemon_running_check_threads_running_process_goal_state_send_heartbeat_telemetry_check_agent_memory_usager   r   r   AgentUpgrader   r   r   r*   r   _set_sentinelr   r	   r   r   exit	_shutdown)re   debugos_info_msgprotocolr   r   exthandlers_handlerr   remote_access_handlertelemetry_handlerall_thread_handlersexitExceptionrV   r   s                 rL   runzUpdateHandler.runD  s   
]	KK<o}]KK{NCKK-/?AQScd/
 06v)N"4;;/88!%!9!9-8H-w7I7I7K+-]_ 06 0  KK$ ))668H''1 =XF j%7%>%>T
 f"9("C!#Q$=h$G!##%$$&779++-''),,.FFxP119N9N9P1Q==XEZEZE\=]113335 !B$BTBT U#%!!45FG	# )*#**+C+EF  34KK  H  JN  Ja  Ja  b//**51++,?@(()<>ST..x8..0

4223 //, 	 ) 	.+88-BVBVbghKK,,-- 	.KK,,-- 	9@@PTUZP[\C3'KKKK11%89HHQK	s2   MN 	RAOR!PRBRRc                    | j                  |      s9t        j                  t        j                                | j                  |      s9t        j
                         stt        j                         }|]|j                  j                         j                  }|j                  |k  r)d|_        t        j                  d|j                  |       y y y y )NTz}The current Fabric goal state is older than the most recent FastTrack goal state; will skip it.
Fabric:    {0}
FastTrack: {1})_try_update_goal_stater   r   r   r   get_enable_fast_trackr   get_fast_track_timestampclientget_goal_stateextensions_goal_statecreated_on_timestampis_outdatedr   r   )re   r  last_fast_track_timestampegss       rL   r  z$UpdateHandler._initialize_goal_state  s     --h7JJt1134 --h7 ))+(:(S(S(U%(4oo446LL++.GG&*COKK  !b002KM H 5 ,rN   c                    | j                   Gt        |j                               }	 |j                         }|j                  | _         | j                   S | j                   S # t
        $ ra}dj                  t        j                  |            }t        j                  t        j                  dj                  |             Y d}~yd}~ww xY w)z
        Including VMSize is meant to capture the architecture of the VM (i.e. arm64 VMs will
        have arm64 included in their vmsize field and amd64 will have no architecture indicated).
        NzCAttempts to retrieve VM size information from IMDS are failing: {0}z[PERIODIC] {0}unknown)r   r   r  get_computevmSizer   r   r	   r   r   periodic_warnEVERY_SIX_HOURS)re   r  imds_client	imds_infor   err_msgs         rL   _get_vm_sizezUpdateHandler._get_vm_size  s    
 == )(*?*?*ABK!'335	 ) 0 0 }}t}}  !_ffgo  hA  hA  BC  hD  E$$V%;%;=M=T=TU\=]^ !s   !A   	C
)ACC
c                 *    t        j                         S rI   )platformmachinerp   s    rL   _get_vm_archzUpdateHandler._get_vm_arch  s    !!rN   c                 ^    |s+| j                   rt        dj                  t                    y y )Nz!Agent {0} is an orphan -- exiting)_is_orphanedr   r   r*   )re   r  s     rL   r  z#UpdateHandler._check_daemon_running  s+    ** C J J= YZZ +urN   c                 2    |D ]  }|j                           y rI   )r%  re   r#  thread_handlers      rL   r  zUpdateHandler._start_threads  s    1 	!N 	!rN   c                     |D ]f  }|j                         s|j                         r%t        j                  dj	                  |j                                      |j                          h y )Nz{0} thread died, restarting)
keep_aliveis_aliver   r   r   get_thread_namestartrB  s      rL   r  z$UpdateHandler._check_threads_running  sU    1 	'N((*>3J3J3L9@@A_A_Aabc$$&	'rN   c                 4   	 d}|j                   j                  | j                  |k\         |j                         | _        | j                  dkD  rdj                  | j                  j                  j                  | j                  j                  j                        }t        t        t        j                  t        d|d       t        j                   |       d| _        	 t#        j$                         xr( |j                   j'                         j)                         | _        y# t,        $ r
 d| _        Y yw xY w# t.        $ rP}| xj                  dz  c_        | xj0                  dz  c_        | j                  k  rpd	j                  t3        j4                  |            }t        j6                  |       t        t        j                  d|d
       t9        j:                         | _        n| j<                  t?        d      z   t9        j:                         kD  rot9        j:                         | _        dj                  t3        j4                  |            }t        j6                  |       t        t        j                  d|d
       Y d}~yd}~ww xY w)z
        Attempts to update the goal state and returns True on success or False on failure, sending telemetry events about the failures.
        rA   )silentr   zWFetching the goal state recovered from previous errors. Fetched {0} (certificates: {1})TFr   r   r   r   r   r   z"Error fetching the goal state: {0}r   r   r   r      hoursz-Fetching the goal state is still failing: {0}N) r*  update_goal_stater   r+  r   r   r,  idcertsr]   r   r(   r   FetchGoalStater,   r   r   r   r(  get_host_plugincheck_vm_settings_supportr   r   r   r   r	   r   rV   r   nowr   r   )re   r  max_errors_to_logr   r   s        rL   r'  z$UpdateHandler._try_update_goal_state  s(   !	 !OO--T5X5X\m5m-n'668D22Q6t{{$$::==t?O?O?U?U?]?]_*);)J)JTcpt  F  RW  XG$6732,0,F,F,H  -KX__MlMlMn  NI  NI  NK)( ' * 2,1)$ '2  	//14/99Q>9226GG?FFxG`G`abGcdW%/>>5Zamrs<DLLN9<<yq?QQT\T`T`Tbb@HD=NUUV^VoVopqVrsGLL)!3!B!Bu^eqvw	s8   C D= #AD' 'D:7D= 9D::D= =
JEJJc                 N     fd} fd} j                   t        j                         sy j                  |      rT j	                          j                         \  } |        n't        dj                  t                     |         j                          y)a  
        This function checks for new Agent updates and raises AgentUpgradeExitException if available.
        There are 2 different ways the agent checks for an update -
            1) Requested Version is specified in the Goal State.
                - In this case, the Agent will download the requested version and upgrade/downgrade instantly.
            2) No requested version.
                - In this case, the agent will periodically check (1 hr) for new agent versions in GA Manifest.
                - If available, it will download all versions > CURRENT_VERSION.
                - Depending on the highest version > CURRENT_VERSION,
                  the agent will update within 4 hrs (for a Hotfix update) or 24 hrs (for a Normal update)
        c                     j                         \  } }j                        }|t        j                  k(  r|n| }dj	                  |j
                  t        j                  |      j                  t        j                  j                              }t        t        t        j                  t         d|d       t        j"                  |       y )Nz<Discovered new {0} upgrade {1}; Will upgrade on or after {2}TFrK  )&_UpdateHandler__get_next_upgrade_times&_UpdateHandler__get_agent_upgrade_typerw   rx   r   rb   r   utcfromtimestampstrftimer   LoggerLogTimeFormatInUTCr   r(   r   r  r,   r   )next_normal_timenext_hotfix_timeupgrade_type	next_timemessage_available_agentre   s        rL   log_next_update_timez@UpdateHandler.__update_guest_agent.<locals>.log_next_update_time  s    151N1N1P..88IL,8<L<S<S,S(YiIU\\o22)))4==fmm>^>^_aH j%7%D%Dojn&%9KK!rN   c                  x   t         k  r]d} 	 t        d j                  D              }dj                  t               }t	        j
                  |       |j                  d|       nd} t        dj                  |             # t        $ r+ t	        j                  dj                  t                      Y Nw xY w)	N	downgradec              3   H   K   | ]  }|j                   t        k(  s|  y wrI   )r   r,   )rY   agents     rL   r\   zcUpdateHandler.__update_guest_agent.<locals>.handle_updates_for_requested_version.<locals>.<genexpr>0  s     (l55==\kKk(ls   ""zBlacklisting the agent {0} since a downgrade was requested in the GoalState, suggesting that we really don't want to execute any extensions using this versionTr   zRCould not find a matching agent with current version {0} to blacklist, skipping itupgradez?Exiting current process to {0} to the request Agent version {1})
r,   nextr   r   r   r   r   StopIterationr   r   )prefixcurrent_agentr   requested_versionre   s      rL   $handle_updates_for_requested_versionzPUpdateHandler.__update_guest_agent.<locals>.handle_updates_for_requested_version&  s     ?2$. %)(lDKK(l$lMnntnt*o,  KK$!..S.I #+QXXY_arsu u % .KKlss+-..s   AB 1B98B9NFz8Agent {0} is reverting to the installed agent -- exiting)
r   r   r   $_download_agent_if_upgrade_availabler   C_UpdateHandler__get_requested_version_and_agent_family_from_last_gsr   r   r*   *_UpdateHandler__upgrade_agent_if_permitted)re   r  rf  rq  rZ   re  rp  s   `    @@rL   __update_guest_agentz"UpdateHandler.__update_guest_agent  s    		"	u8 #4+F+F+H44X> #GGIO#'#]#]#_ q , 56 ( 0NUUVcdf f %&))+rN   c                 h    | j                   duxr# | j                   j                  | j                  k7  S )zd
        True if we are currently processing a new incarnation (i.e. WireServer goal state)
        N)r   incarnationr   rp   s    rL   _processing_new_incarnationz)UpdateHandler._processing_new_incarnationX  s2     t+f0@0@0L0LPTPfPf0ffrN   c                     | j                   j                  }| j                   duxr( |j                  | j                  k7  xr |j                   S )zQ
        True if we are currently processing a new extensions goal state
        N)r   r,  rQ  r   r.  )re   r0  s     rL   %_processing_new_extensions_goal_statez3UpdateHandler._processing_new_extensions_goal_state^  sI     44t+m$:U:U0Um^a^m^mZmmrN   c                 J   |j                   }| j                  |      s#| j                  |       | j                  |       y | j                  |       	 | j	                         r| j
                  j                  stdj                  | j
                        }t        j                  |       t        t        j                  |dd       | j                  r| j                  | j
                         t               | _        |j!                          t#        j$                         j'                  g        | j                  |       | j)                         r|j!                          | j	                         rt*        j-                          | j.                  A| j.                  j0                  | _        | j.                  j4                  j6                  | _        y y # | j.                  A| j.                  j0                  | _        | j.                  j4                  j6                  | _        w w xY w)NzhA new goal state was received, but not all the extensions in the previous goal state have completed: {0}F)r   r   r   r   )cgroup_metrics)r  r'  "_UpdateHandler__update_guest_agent_report_statusrz  r   r^   r   r   r   r   r   	GoalStater    _on_initial_goal_state_completedrF   r%  r   get_instancecheck_cgroupsrx  r{   _archive_goal_state_historyr   rw  r   r,  rQ  r   )re   r   r!  r  r   s        rL   r  z!UpdateHandler._process_goal_statee  s   &// **84%%h/ 34 	!!(+	X99;//99 I  P  P  QU  Qi  Qi  jGKK(!3!=!=w[`lqr22==d>V>VW+<+>(#'') #//1??r?R  34//1%))+ 99;99; +)-)9)9)E)E&.2.>.>.T.T.W.W+ ,t+)-)9)9)E)E&.2.>.>.T.T.W.W+ ,s   D2G AH"c                      	 t        t        j                               } | j                          y # t        $ r)}t        j                  dt        |             Y d }~y d }~ww xY w)Nz-Error cleaning up the goal state history: {0})r"   r   get_lib_dirarchiver   r   r   r   )archiver	exceptions     rL   r  z)UpdateHandler._archive_goal_state_history  sO    	Z$T%5%5%78H 	ZKKGiYY	Zs   -0 	A"AA"c                      	 t        j                          y # t        $ r)} t        j                  dt        |              Y d } ~ y d } ~ ww xY w)Nz(Error removing legacy history files: {0})r"   purge_legacy_goal_state_historyr   r   r   r   )r  s    rL   r  z0UpdateHandler._cleanup_legacy_goal_state_history  s<    	U99; 	UKKBDOTT	Us    	A	AA	c                 @   t        j                         syd}	 | j                         \  }}|9|r7t        j                  dj                  t        j                                      y|Ft        |k(  rt        j                  }d}nt        j                  }d}t        |j                  ||      }|S # t        $ rc}|rVdj                  t        j                  |            }t        j                   |       t#        t$        j&                  d|d       Y d}~|S d}~ww xY w)	z
        This function gets the VMAgent update status as per the last GoalState.
        Returns: None if the last GS does not ask for requested version else VMAgentUpdateStatus
        NzLUnable to report update status as no matching manifest found for family: {0}r   r   )expected_versionr[   codez[This error will only be logged once per goal state] Ran into error when trying to fetch updateStatus for the agent, skipping reporting update satus. Error: {0}FrL  )r   get_enable_ga_versioningrs  r   r   r   get_autoupdate_gafamilyr,   r   SuccessErrorr   requested_version_stringr   r	   r   r   r   r   r  )	re   goal_state_changedupdate_statusrp  manifestr[   r  rV   r9  s	            rL   __get_vmagent_update_statusz)UpdateHandler.__get_vmagent_update_status  s#   
 ,,.	r*.*d*d*f'x$6jqq0024 5 ,"&772::FD288FD 3XEfEfou9=!?   	r!H IO  IO#44U;I=  G$/<<X_kpq	rs    AB1 'AB1 1	D:ADDc                    | j                  | j                               }|j                  | j                         || j                        }|| j	                  |       | j
                  |j                  |      }| j
                  j                  |t               | j
                  j                  j                  r3|j                  j                  j                         j                          y y y y )N)r  vm_agent_update_statusvm_agent_supports_fast_track))_UpdateHandler__get_vmagent_update_statusrz  report_ext_handlers_statusr   _report_extensions_summaryr   "get_ext_handlers_status_debug_infosave_to_historyr#   r,  r.  r  r*  rT  clear_fast_track_state)re   r   r  rf   agent_statuss        rL   r~  zUpdateHandler._report_status  s    !%!A!A$BlBlBn!o'BB#IIK#9X\XqXq C s	  ++I6+2UUV_`  00?PQ##99EE'0077GGI``b F , !rN   c                 h   	 t        |      }| j                  |k7  r|| _        dj                  | j                        }t        j                  |       t        t        j                  |d       | j                  j                  rkdj                  |      }t        j                  |       t        t        j                  |d       | j                  r| j                  | j                         y y y y # t        $ r}| j                  | j                  j                  j                  k7  r| j                  j                  j                  | _        dj                  t!        j"                  |            }t        j$                  |       t        t        j                  d|       Y d }~y Y d }~y d }~ww xY w)NzExtension status: {0}T)r   r   r   zCAll extensions in the goal state have reached a terminal state: {0}z)Error logging the goal state summary: {0}Fr   r   r   )rF   r   r   r   r   r   r   r  r^   r   r  r   r   r   r,  rQ  r	   r   r   )re   rf   extensions_summaryr   rV   r   s         rL   r  z(UpdateHandler._report_extensions_summary  s_   	Z!29!=''+==+=(1889Q9QRG$/997W[\++55cjjk}~GKK(!3!=!=w[_`22==d>V>VW 3	 6 >  	Z99T=M=M=c=c=f=ff=A=M=M=c=c=f=f:BII(JcJcdiJjkC /99eUXYY	 g	Zs   C,C2 2	F1;B'F,,F1c                 H   t        j                  | j                         t        |             t	        j
                         rZ| j                  t	        j                         k7  r9t	        j                         | _        t        j                  d| j                         d| _
        y )NzCInitial goal state completed, switched the goal state period to {0}F)r   
write_filer   r   r   r   r   r   r   r   r   )re   r  s     rL   r  z.UpdateHandler._on_initial_goal_state_completed  sr    D>>@$GYBZ[&&(T-D-DHbHbHd-d&*&@&@&BD#KK]_c_v_vw&+#rN   c                 F   |t         j                  k(  r| j                          | j                  y t	        j
                  dt        || j                  | j                  j                  nt               | j                  j                  |       | j                  d t         j                  t         j                  fvr| j                  ||       y | j                  t         j                  u r8|t         j                  k(  r%| j                          t        j                  d       y )Nz'Agent {0} forwarding signal {1} to {2}
r   )r   r   r  r   r   r   r*   r   rb   send_signalr   SIG_IGNSIG_DFLr   r  )re   signumframes      rL   r   zUpdateHandler.forward_signal  s    V^^#NN%7%)%5%5%AD!!}		V 	&&v.tV^^V^^&LL.
 		   FNN2' rN   c                  T    t               } | t        t              k7  r| S t        d      S )Nz2.2.53)r4   r$   r   r   s    rL   __get_daemon_version_for_updatez-UpdateHandler.__get_daemon_version_for_update  s*    +-_Y77!! x((rN   c                    | j                          || j                         n|}| j                  D cg c]2  }|j                  r$|j                  t
        k7  r|j                  |kD  r|4 }}t        |      dk\  r|d   S dS c c}w )ap  
        If autoupdate is enabled, return the most current, downloaded,
        non-blacklisted agent which is not the current version (if any) and is greater than the `daemon_version`.
        Otherwise, return None (implying to use the installed agent).
        If `daemon_version` is None, we fetch it from the environment variable set by the DaemonHandler
        Nr   r   )_find_agents-_UpdateHandler__get_daemon_version_for_updater   is_availabler   r,   len)re   r   rj  available_agentss       rL   r   z2UpdateHandler.get_latest_agent_greater_than_daemon  s     	CQCY==?_m 04{{ ee$11 % @U]]UcEc " e e '**:&;q&@"JdJ	es   7Bc                    	 | j                   smdj                  t        j                  | j	                                     }t        j                  |       t        t        t        t        j                  d|       y # t        $ r Y y w xY w)Nz$Agent did not terminate cleanly: {0}Fr   )_is_clean_startr   r   	read_file_sentinel_file_pathr   r   r   r(   r,   r   Restartr   re   r   s     rL   r  z!UpdateHandler._emit_restart_event!  s}    	''=DD&&t'?'?'ABDC +)11$! 	  		s   A9A< <	BBc                  <   	 d dfd	} fd} | dt        j                         d        | dt        j                         d        |dt        j                                 |dt        j                                 |d	t        j
                                t        j                         r | d
t        j                                t        j
                         r | dt        j                                t        j                         r |dt        j                                t        j                         dk7  r* dj                  t        j                                      y y # t        $ r)}t        j                  dt        |             Y d }~y d }~ww xY w)Nc                 p    t        j                  d|        t        t        t        j
                  |        y )Nz******** {0} ********r   )r   r   r   r(   r   ConfigurationChanger   s    rL   r   zGUpdateHandler._emit_changes_in_default_configuration.<locals>.log_event5  s%    3S9*);)O)OY\]rN   c                 p    t        j                  |       }||k7  r dj                  | |||             y y )Nz6{0} changed from its default: {1}. New value: {2}. {3})r   get_int_default_valuer   )rb   currentr   defaultr   s       rL   log_if_int_changed_from_defaultz]UpdateHandler._emit_changes_in_default_configuration.<locals>.log_if_int_changed_from_default9  s>    44T:g%V]]^bdkmtv}~ &rN   c                 :    |s dj                  |              y y )Nz1{0} is set to False, not processing the operation)r   )rb   valuer   s     rL   log_if_op_disabledzPUpdateHandler._emit_changes_in_default_configuration.<locals>.log_if_op_disabled>  s     QXXY]^_ rN   zExtensions.GoalStatePeriodzChanging this value affects how often extensions are processed and status for the VM is reported. Too small a value may report the VM as unresponsivez!Extensions.InitialGoalStatePeriodzOS.EnableFirewallzExtensions.EnabledzAutoUpdate.EnabledzOS.EnableFirewallPeriodzAutoupdate.FrequencyzDebug.EnableFastTrackz/var/lib/waagentz)lib dir is in an unexpected location: {0}z+Failed to log changes in configuration: {0}) )r   r   r   enable_firewallr   r   get_enable_firewall_periodget_autoupdate_frequencyr(  r  r   r   r   r   r   )r  r  r   r   s      @rL   r  z4UpdateHandler._emit_changes_in_default_configuration2  sR   #	P^@
` ,,H$JdJdJf hi+,OQUQsQsQu hi2D4H4H4JK3T5P5P5RS3T5P5P5RS##%/0I4KjKjKlm**,/0FHeHeHgh))+"#:D<V<V<XY!%77ELLTM]M]M_`a 8  	PKKEtAwOO	Ps   E$E) )	F2FFc                 p   | j                         \  }}|D ]  }	 t        j                  |      }|}| j                  j	                  |      r|t
        z  }|dk  r@t        j                  dt        |       t        j                  |t        j                         nPt        j                  dt        |       t        j                  t
               | j                  j	                  |      rt        j                   |        y # t"        $ r*}t        j                  dt%        |             Y d }~d }~ww xY w)Nr   z*{0} forcibly terminated orphan process {1}z/{0} waiting for orphan process {1} to terminatez=Exception occurred waiting for orphan agent to terminate: {0})_write_pid_filer   r  r   check_pid_aliveORPHAN_POLL_INTERVALr   r   r*   r   killr   SIGKILLr   r   r   remover   r   )re   orphan_wait_interval	pid_filesignoredpid_filepidwait_intervalr   s           rL   r  z UpdateHandler._ensure_no_orphansY  s   !113	7! 	H((2 4kk11#6!%99M$)I)! V^^4KKJ% JJ34 kk11#6  		(#+	6 		  TG s   CD*D	D5D00D5c                 J   t         j                  j                  | j                        szt	        t        t        j                         j                  dz              }t        j                  | j                  |       t        t        t        t        j                  d|       yy)z
        Assign the VM to a partition (0 - 99). Downloaded updates may be configured
        to run on only some VMs; the assigned partition determines eligibility.
        i'  Tr   N)r   r   r   _partition_filer   intr   utcnowmicrosecondr   r  r   r(   r,   r   	Partition)re   r@   s     rL   r	  z(UpdateHandler._ensure_partition_assignedx  ss    
 ww~~d223S!2!>!>!FGHI 4 4i@'%//!# 4rN   c                     t         D ]p  }t        j                  t        j                  j                  t        j                         |            D ]&  }t        j                  |t        j                         ( r y rI   )READONLY_FILE_GLOBSglobiglobr   r   r   r   r  chmodstatS_IRUSR)re   gr   s      rL   r
  z$UpdateHandler._ensure_readonly_files  sS    $ 	-A

277<<0@0@0BA#FG -t||,-	-rN   c                 L    t        j                         }|j                          y rI   )r   r  
initialize)re   configurators     rL   r  z)UpdateHandler._ensure_cgroups_initialized  s    )668!rN   c                    |d| _         y| j                   #|j                  | j                   j                  k7  r|| _         d| _        d| _        | j                  t	        j                         | _        | xj                  dz  c_        t	        j                         | j                  z
  t
        k  rM| j                  t        k\  r:dj                  | j                   j                  t        t
              }t        |      y)z
        Evaluate the health of the selected agent: If it is restarting
        too frequently, raise an Exception to force blacklisting.
        Nr   r   z6Agent {0} restarted more than {1} times in {2} seconds)
r   r   r   r   r   CHILD_LAUNCH_INTERVALCHILD_LAUNCH_RESTART_MAXr   rb   r   )re   r   r   s      rL   r   z$UpdateHandler._evaluate_agent_health  s    
 #D#|';';t?O?O?W?W'W+D%)D")*D&!!)%)YY[D"""a'"IIK$0005JJ..2JJKRR  %%(%'C C. rN   c                 f    | j                   D cg c]  }|j                  r| c}| _         y c c}w rI   )r   is_blacklisted)re   rj  s     rL   _filter_blacklisted_agentsz(UpdateHandler._filter_blacklisted_agents  s#    *.++RU=Q=QuRRs   ..c                     	 | j                  | j                                | j                          y# t        $ r)}t	        j
                  dt        |             Y d}~yd}~ww xY w)zD
        Load all non-blacklisted agents currently on disk.
        z0Exception occurred loading available agents: {0}N)_set_and_sort_agents_load_agentsr  r   r   r   r   re   r   s     rL   r  zUpdateHandler._find_agents  s^    	V%%d&7&7&9:++- 	  	VKKKTRSWUU	Vs   /2 	A$AA$c                    t        j                         }t        j                  j	                  |      }t        j                  j                  |      }t        j                  dj                  t        j                  |                  }|||fS )Nz	(\d+)_{0})
r   get_agent_pid_file_pathr   r   dirnamebasenamerecompiler   escape)re   r  pid_dirpid_namepid_res        rL   _get_pid_partszUpdateHandler._get_pid_parts  se    //1''//(+77##H-L//		(0CDE&((rN   c                    | j                         \  }}t        j                  |      D cg c]4  }j                  |      st        j                  j                  ||      6 }}|j                  fd       |S c c}w )Nc                     t        j                  t        j                  j	                  |             j                  d            S Nr   )r  matchr   r   r  group)fr  s    rL   rM   z.UpdateHandler._get_pid_files.<locals>.<lambda>  s0    Sbgg6F6Fq6I)J)P)PQR)S%T rN   rR   )r  r   listdirr  r   r   rc   )re   r  r  r  r  r  s        @rL   _get_pid_fileszUpdateHandler._get_pid_files  si    $($7$7$9!679zz'7J^!fll[\oRWW\\'1-^	^TU _s   A?"A?c                     | j                   S rI   r   rp   s    rL   r   zUpdateHandler.is_running  s    rN   c                     || _         y rI   r  )re   r  s     rL   r   zUpdateHandler.is_running  s
     rN   c                 ^    t         j                  j                  | j                                S rI   )r   r   isfiler  rp   s    rL   r  zUpdateHandler._is_clean_start  s!    77>>$":":"<===rN   c                     t        j                         }|dv ryt         j                  j                  t	        j
                               syt        j                  t	        j
                               t        |      k7  S )N)r   NT)	r   getppidr   r  r   r  r   r  r   )re   
parent_pids     rL   r@  zUpdateHandler._is_orphaned  sX    ZZ\
"ww~~d::<=!!$">">"@AT*EUUUrN   c                 @   t         j                  j                  t        j                         dj                  t                    }t        j                  |      D cg c]6  }t         j                  j                  |      rt        j                  |      8 c}S c c}w )N{0}-*)r   r   r   r   r  r   r(   r  r  isdir
GuestAgentfrom_installed_agent)re   r   r   s      rL   r  zUpdateHandler._load_agents  so    ww||D,,.z0JK!%D!1ORWW]]95M //	: O 	O Os   ;Bc                 R    t        t        j                  | j                              S rI   )r  r   r  r  rp   s    rL   
_partitionzUpdateHandler._partition  s    8%%d&:&:;<<rN   c                 n    t         j                  j                  t        j                         t
              S rI   )r   r   r   r   r  AGENT_PARTITION_FILErp   s    rL   r  zUpdateHandler._partition_file  s!    ww||D,,.0DEErN   c           	      l   t         j                  j                  t        j                         dj                  t                    }| j                  D cg c]  }|j                   }}t        |vr/t        j                  dt               |j                  t               t        j                  |      D ]  }	 t        j                   |d      }t#        j$                  |      }|t'        |j)                  d            |vrvt         j                  j+                  |      r,t        j,                  d|       t        j.                  |       n+t        j,                  d|       t1        j2                  |        yc c}w # t4        $ r*}t        j6                  d|t9        |             Y d}~d}~ww xY w)	z
        Remove from disk all directories and .zip files of unknown agents
        (without removing the current, running agent).
        r  zFRunning Agent {0} was not found in the agent manifest - adding to listzipNr   zPurging outdated Agent file {0}z$Purging outdated Agent directory {0}z!Purging {0} raised exception: {1})r   r   r   r   r  r   r(   r   r   r,   r   r   r  r  r  r   trim_extr)   r  r$   r   r  r   r  shutilrmtreer   r   r   )re   r   rj  known_versions
agent_pathrb   mr   s           rL   _purge_agentszUpdateHandler._purge_agents  sI   
 ww||D,,.z0JK59[[AE%--AA.0NNY! !!/2**T* 	WJW((U;%++D1=_QWWQZ%@%Vww~~j1$F
S		*-$KZXj1	W 	) B$  W@*dSTgVVWs   E;9B?F  	F3	 F..F3c                 V    |g }|| _         | j                   j                  d d       y )Nc                     | j                   S rI   )r   )rj  s    rL   rM   z4UpdateHandler._set_and_sort_agents.<locals>.<lambda>  s
    5== rN   T)rS   reverse)r   rc   )re   r   s     rL   r  z"UpdateHandler._set_and_sort_agents  s.    >F8$GrN   zUnknown causec                     	 t        j                  | j                         dj                  ||             y # t        $ r8}t        j                  d| j                         t        |             Y d }~y d }~ww xY w)Nz[{0}] [{1}]z(Exception writing sentinel file {0}: {1})r   r  r  r   r   r   r   r   )re   rj  r   r   s       rL   r  zUpdateHandler._set_sentinel  st    	((*$$UC02 	  	KK;((*A  		s   47 	A8 .A33A8c                 n    t         j                  j                  t        j                         t
              S rI   )r   r   r   r   r  AGENT_SENTINEL_FILErp   s    rL   r  z!UpdateHandler._sentinel_file_path  s!    ww||D,,.0CDDrN   c                  n    t         j                  j                  t        j                         t
              S rI   )r   r   r   r   r  INITIAL_GOAL_STATE_FILErP   rN   rL   r   z+UpdateHandler._initial_goal_state_file_path  s!    ww||D,,.0GHHrN   c                 >   d| _         t        j                  j                  | j	                               sy 	 t        j
                  | j	                                y # t        $ r8}t        j                  d| j	                         t        |             Y d }~y d }~ww xY w)NFz)Exception removing sentinel file {0}: {1})
r   r   r   r  r  r  r   r   r   r   r  s     rL   r  zUpdateHandler._shutdown!  s      ww~~d6689	IId..01 	  	KK<((*A  		s   #A 	B$.BBc                 ~   t        j                         }| j                  j                  j                  }|D cg c]-  }|j
                  |k(  st        |j                        dkD  s,|/ }}t        |      dk(  ryt        j                         r#|d   j                  r|d   j                  |d   fS d|d   fS c c}w )a8  
        Get the requested version and corresponding manifests from last GS if supported
        Returns: (Requested Version, Manifest) if supported and available
                 (None, None) if no manifests found in the last GS
                 (None, manifest) if not supported or not specified in GS
        r   )NNN)r   r  r   r,  agent_familiesrb   r  urisr  is_requested_version_specifiedrp  )re   family_namer(  r  s       rL   5__get_requested_version_and_agent_family_from_last_gszCUpdateHandler.__get_requested_version_and_agent_family_from_last_gs2  s     224))??NN%3aqvv7LQTUVU[U[Q\_`Q`!aa~!#((*~a/@/_/_!!$66q8III^A&&& bs   B:B:'B:c                 t    t         t        j                  fdfd} fd}t        j                         }d j                         	  j                  j                  j                   j                          j                         \  }|&t        j                  dj                  |             y	  |       s;yt#        j"                         }	 ||	      syt        j$                  d|       |	 _        	 t)               }
St         k(  rJg }d	j                        }t        j$                  |       t+        t,        t        j.                  d
|       nH j                  j1                  |j2                  |j4                        }|j6                  }
|
j8                  }Tt         k7  rK|
j8                  D ]  }t;        |j<                        k(  s|g} n dj                        } |       y j                  j                  j>                  t@        jB                  k(  }|D cg c]  }tD        jG                  |||       }} jI                  |D cg c]  }|jJ                  s| c}        jM                           jO                          tQ         jR                        dk(  ry: jR                  d   j<                  |k7  xr  jR                  d   j<                  kD  S  jR                  d   j<                  |kD  S # t        $ rN}dj                  t        j                   |            }r	 |       nt        j                  |       Y d}~yd}~ww xY wc c}w c c}w # t        $ r6}dj                  t        j                   |            } |       Y d}~yd}~ww xY w)a  
        This function downloads the new agent if an update is available.
        If a requested version is available in goal state, then only that version is downloaded (new-update model)
        Else, we periodically (1hr by default) checks if new Agent upgrade is available and download it on filesystem if available (old-update model)
        rtype: Boolean
        return: True if current agent is no longer available or an agent with a higher version number is available
        else False
        c                 X    t        j                  |        t        t        ||d| d       y )NFrK  )r   r   r   r(   )msg_version_r   s      rL   report_errorzHUpdateHandler._download_agent_if_upgrade_available.<locals>.report_errorL  s"    KKjReUYejkrN   c                      sydj                        } t        j                  |        t        t        t
        j                  d| d       k  r) dj                        t
        j                         yy)NFz;Found requested version in manifest: {0} for goal state {1}TrL  zXCan't process the upgrade as the requested version: {0} is < current daemon version: {1})r   )r   r   r   r   r(   r   r  )r/  r   goal_state_id
gs_updatedr1  rp  s    rL   "can_proceed_with_requested_versionz^UpdateHandler._download_agent_if_upgrade_available.<locals>.can_proceed_with_requested_versionP  s~     QWW!=2DKKj%7%D%DQU_cotu >1 nuu)>;?Q?^?^` rN   c                 r    j                   "j                   t        j                         z   }n| }|| kD  ryy)NFT)r   r   r  )now_next_attempt_timere   s     rL   agent_upgrade_time_elapsedzVUpdateHandler._download_agent_if_upgrade_available.<locals>.agent_upgrade_time_elapsedf  s=    %%1$($:$:T=Z=Z=\$\!$(! 4'rN   FNzWNo manifest links found for agent family: {0} for goal state {1}, skipping update checkz)Exception retrieving agent manifests: {0}zXNo requested version specified, checking for all versions for agent update (family: {0})z<The requested version is running as the current version: {0}Tr  zsNo matching package found in the agent manifest for requested version: {0} in goal state {1}, skipping agent update)r0  r   z,Exception downloading agents for update: {0})*r,   r   Downloadr   r  r  r   r,  rQ  rz  rs  r   r   r   r   r	   r   r   r   r   r   r   r(   r  fetch_agent_manifestrb   r)  pkg_listversionsr$   r   sourcer   	FastTrackr  from_agent_packager  r  r  r  r  r   )re   r  base_versionr5  r9  agent_family_nameagent_familyerrr   rV  r<  packages_to_downloadagent_manifestpkgis_fast_track_goal_stateagents_to_downloadrj  r   r3  r4  r1  rp  s   `                @@@@@rL   rr  z2UpdateHandler._download_agent_if_upgrade_availableB  s    )8<N<W<W 	l	 	,	 !88:
==?	 ,,BBEEMCCEJ.2.h.h.j+|#nuu)=:; 	 $ (57 ))+C-c2KKr)+%(D"A	 -.H
 !,1Bo1U')$T[[\mnC *);)H)HUYcfg!%!1!1!F!F|GXGXZfZkZk!l)22'/'8'8$ !,1Bo1U#,, 	!C&s{{37HH03u,		! P  W  W)=:C /@A  (,'7'7'M'M'T'TXgXqXq'q$ uI  "Jmp*"?"?XOg"h  "J  "J %%:L&cPUPbPbu&cd  ++- 4;;1$ , {{1~--=i$++a.BXBX[iBii {{1~--<<m  	>EEhF_F_`cFdeCS!s#	x "J 'd0  	AHHIbIbcfIghC	so   A*L CM8 "M8 5M8 7M.M8 &M38M3<?M8 <;M8 8M8 	M+AM&&M+.
M8 8	N7,N22N7c           	         | j                         }| j                         \  }}}t        |      dk  rd n|d   }|dnEt        |j	                  t
        j                  j                  |            j                  d            }t
        j                  j                  |dj                  |dz   |            }	 t        j                  |t        t        j                                      t        j                   dt"        t        t        j                                      ||fS # t$        $ r4}d }t        j&                  dt"        |t        |             Y d }~||fS d }~ww xY w)Nr   r   r   z{0}_{1}z{0} running as process {1}z6Expection writing goal state agent {0} pid to {1}: {2})r  r  r  r  r  r   r   r  r   r   r   r   r  r   getpidr   r   r*   r   r   )	re   r  r  r  r  previous_pid_file	pid_indexr  r   s	            rL   r  zUpdateHandler._write_pid_file  s-   '')	$($7$7$9!6$'	Na$7DYr] ( V\\"''"2"23D"EFLLQOP 	 77<<)9)9)a-)RS		$ryy{*;<KK5}d299;FWX (""  	HKKIQ	  (""	s   8A'D# #	E ,'EE c                 6   | j                   *t        j                         t        j                  z
  | _         t        j                         | j                   t        j                  z   k\  r0| j
                  j                  |j                               }t        j                         rdnd}| j                         }dj                  | j                  | j                  || j                  ||      }dj                  | j                  | j                  || j                  |      }t        t         t"        t$        j&                  d|d       t)        j*                  dt,        |       | xj                  dz  c_        d| _        t        j                         | _         y y )	Nr   r   z{0};{1};{2};{3};{4};{5}zf[DEBUG HeartbeatCounter: {0};HeartbeatId: {1};DroppedPackets: {2};UpdateGSErrors: {3};AutoUpdate: {4}]TF)rb   r   r   r   r   r   z<[HEARTBEAT] Agent {0} is running as the goal state agent {1})r   r   r  r{   TELEMETRY_HEARTBEAT_PERIODr   get_firewall_dropped_packetsr  r   r   r>  r   r   r   r   r   r(   r,   r   	HeartBeatr   r   r*   )re   r  dropped_packetsauto_update_enabledvmarchtelemetry_msgdebug_log_msgs          rL   r  z'UpdateHandler._send_heartbeat_telemetry  sT   ))1-5__->AiAi-iD*??!?!?-BjBj!jk"kkFFxG\G\G^_O'+'B'B'D!! &&(F5<<T=T=TVZVhVhjy9=9f9f9LfVMCCI6$JaJaJNJ\J\^mJNJwJwJ]D_  :CUC_C_lp+u>KKWYfhuv ##q(#<=D9-5__->D*1 lrN   c                    	 t        j                         r| j                  j                  r| j                  t
        j                  k(  s2t        j                         | j                  t        j                  z   k\  r<t        j                         | _        t        j                         j                          yyyy# t        $ rs}dj                  t        |            }t!        j"                  |       t%        t&        t(        j*                  d|       t-        dj                  t.                    d}~wt0        $ r}| j2                  t
        j                  k(  s.| j2                  t5        d      z   t        j6                         kD  rnt        j6                         | _        dj                  t        |            }t!        j8                  |       t%        t&        t(        j*                  d	|       Y d}~yY d}~yd}~ww xY w)
zz
        This checks the agent current memory usage and safely exit the process if agent reaches the memory limit
        z Check on agent memory usage:
{0}Tr  z,Agent {0} is reached memory limit -- exitingNrM  rN  zdError checking the agent's memory usage: {0} --- [NOTE: Will not log the same error for the 6 hours]F)r   #get_enable_agent_memory_usage_checkr   r^   r   r   r   r  r{   CHECK_MEMORY_USAGE_PERIODr   r  check_agent_memory_usager   r   r   r   r   r   r(   r   AgentMemoryr   r*   r   r   r   rV  r   re   r  r   s      rL   r  z'UpdateHandler._check_agent_memory_usage  s   	h779d>V>V>`>`00HLL@HOODUZ^ZwZw  {H  {b  {b  [b  Ec4<OO4ED1&335NNP Ec ?a9 , 	f5<<T)_MCKKj%7%C%CPT^ab N U UVc dee 	h99X\\IdNxNx  |E  LM  |N  ON  RZ  R^  R^  R`  N`=E\\^:|  D  D  EI  JS  ET  UC *);)G)GTYcfgg	 N`	hs&   B4B: :	H A.D11H =B4G;;H c           	      ^   t        t        j                        j                  }t	        d      D ]y  \  }}	 t        j                  |||       }	 |X|j                          |j                         }|r6t        j                  j                  |      st        j                  |d       { 	 |sit'        j&                  t        j                  j)                  t+        j,                         dt.                    }|D ]  }t1        j2                  |d        y y # t        $ r Y w xY w# t        $ r8}t        j                   dj#                  t%        |                   Y d }~4d }~ww xY w# t        $ r7}t        j                   d	j#                  t%        |                   Y d }~y d }~ww xY w)
NT)skip_agent_package)rb   r   r  i  )modezJUnable to re-create HandlerEnvironment file on service startup. Error: {0}*ignore_errorszKError when trying to delete existing Extension events directory. Error: {0})r
   r   ExtensionTelemetryPipelineis_supportedr;   r:   "get_ext_handler_instance_from_pathr   create_handler_envget_extension_events_dirr   r   r   r   mkdirr   r   r   r   r  r   r   get_ext_log_dirr   r  r  )	r  etp_enabledrb   r   handler_instance
events_dirr   extension_event_dirsext_dirs	            rL   r  zCUpdateHandler._ensure_extension_telemetry_state_configured_properly$  sp   34I4d4derr2dK 	JD$#5#X#X^b^bbj$l #/ %779!1!J!J!LJ"277>>*+E z>'	2	w (,yyd>R>R>TVY[k1l'm$3 ?GMM'>?	 )    `gghlmnhopr  	wKKellmqrsmtuvv	wsC   DAD(-A*E, 	D%$D%(	E)1-E$$E),	F,5-F''F,c                    t        j                         st        j                  d       y d}t        j                  d       	 t	        | t        j                               j                          d}d}t        j                  |       t        t        j                  ||d       y # t        $ r9}dj                  t        |            }t        j                  |       Y d }~[d }~ww xY w)	NzCNot setting up persistent firewall rules as OS.EnableFirewall=FalseFz,Starting setup for Persistent firewall rules)r   uidz,Persistent firewall rules setup successfullyTz2Unable to setup the persistent firewall rules: {0}rL  )r   r  r   r   r   r   getuidsetupr   r   r   rV   r   r   PersistFirewallRules)r   r   r   rV   s       rL   r  z.UpdateHandler._ensure_firewall_rules_persistedJ  s     ##%KK]^
BC	'v299;GMMO@CJKK
 	!66!			  	FMMdSXkZCLL	s   AB' '	C)0/C$$C)c                    t        j                         sy d }	 | j                  j                         }t	        j
                  t        j                  ||      } ||      st        j                  d       y t	        j                  t        j                  ||      } ||      sg	 t        j                  d       t	        j                  t        j                  ||      }t        j                  |       t        j                  d       y t        j                  d       y # t        $ rP}dj                  |j                  |j                   |j"                        }t        j$                  |       Y d }~y d }~ww xY w# t&        $ r9}dj                  t)        |            }t        j$                  |       Y d }~y d }~ww xY w)	Nc                 |    	 t        j                  |        y# t        $ r}|j                  dk7  r Y d }~yd }~ww xY w)NTr   F)r!   run_commandr&   
returncode)commandrD  s     rL   _execute_run_commandzXUpdateHandler._add_accept_tcp_firewall_rule_if_not_enabled.<locals>._execute_run_commandg  s?    %%g. >>Q& '	s    	;6;)r   zjDROP rule is not available which implies no firewall rules are set yet. Environment thread will set it up.zeFirewall rule to allow DNS TCP request to wireserver for a non root user unavailable. Setting it now.z]Succesfully added firewall rule to allow non root users to do a DNS TCP request to wireserverzxUnable to set the non root tcp access firewall rule :Run command execution for {0} failed with error:{1}.Return Code:{2}zpNot setting the firewall rule to allow DNS TCP request to wireserver for a non root user since it already existsz'Error while checking ip table rules:{0})r   r  r   get_firewall_will_waitr%   get_wire_non_root_drop_ruleCHECK_COMMANDr   r   get_accept_tcp_ruleINSERT_COMMANDr!   rv  r&   r   rx  r   rw  rV   r   r   )	re   r   ry  r   	drop_ruleaccept_tcp_rulerV   r   r   s	            rL   r  z:UpdateHandler._add_accept_tcp_firewall_rule_if_not_enabledb  s   ##%
		;;557D )DDEUEcEcekrvwI'	2   I  J #3"F"FGWGeGegmtx"y+O<* DE*:*N*NO_OnOnpv  ~B  +C!--o>{} KK KL ( *d#VEMM5<<AQAQR  S))	*  	;BB47KCLL	sJ   AE? 8.E? 'A%D# E? #	E<,AE72E? 7E<<E? ?	G/F<<Gc                     fd}t        j                           || j                  t        j                               } || j                  t        j
                               }||fS )zo
        Get the next upgrade times
        return: Next Normal Upgrade Time, Next Hotfix Upgrade Time
        c                     | S | |z   S rI   rP   )last_val	frequencyrV  s     rL   get_next_process_timezEUpdateHandler.__get_next_upgrade_times.<locals>.get_next_process_time  s    "*3D90DDrN   )r   r   r   get_hotfix_upgrade_frequencyr   get_normal_upgrade_frequency)re   r  ra  r`  rV  s       @rL   __get_next_upgrade_timesz&UpdateHandler.__get_next_upgrade_times  s\    	E iik01O1OQUQrQrQtu01O1OQUQrQrQtu!111rN   c                     | j                   j                  t        j                  k(  r7| j                   j                  t        j                  k(  rt        j
                  S t        j                  S rI   )r   majorr,   minorrw   rx   ry   )re  s    rL   __get_agent_upgrade_typez&UpdateHandler.__get_agent_upgrade_type  sP     ""((O,A,AAoF]F]FcFcgvg|g|F|#***&&&rN   c                    | j                         \  }}t        j                         }||kD  r||kD  ry||k  r|n| j                  | _        ||k  r|n| j                  | _        | j	                         }||j
                  t        k  rt        j                  d       y| j                  |      }dj                  ||j                        }|t        j                  k(  r||k  s|t        j                  k(  r||k  rt        |      yy)z
        Check every 4hrs for a Hotfix Upgrade and 24 hours for a Normal upgrade and upgrade the agent if available.
        raises: ExitException when a new upgrade is available in the relevant time window, else returns
        NzNo agent upgrade discoveredz8{0} Agent upgrade discovered, updating to {1} -- exiting)rZ  r   r   r   r   r   r,   r   r   r[  r   rb   rw   rx   ry   r   )re   r`  ra  rV  re  rb  upgrade_messages          rL   __upgrade_agent_if_permittedz*UpdateHandler.__upgrade_agent_if_permitted  s    .2-J-J-L**iikc!&6&< 1AC0GTMkMk&0@C0GTMkMk&CCE"o&=&=&PNN8944_ET[[\h\k\p\pr ,3338HC8O 0 7 77<LPS<S+O<< =T7rN   c                 6   	 | j                         D cg c])  }|j                  r|j                  j                  dk(  r|+ }}|D ]  }|j	                           y c c}w # t
        $ r.}t        j                  dj                  |             Y d }~y d }~ww xY w)Nr  z5Unable to reset legacy blacklisted agents due to: {0})	r  r  rV   r   clear_errorr   r   r   r   )re   rj  legacy_blacklisted_agentsrD  s       rL   r  z.UpdateHandler._reset_legacy_blacklisted_agents  s    
	]<@<M<M<O )\5).)=)=%++BTBTXZBZ */ )\% )\2 $!!#$)\  	]KKOVVWZ[\\	]s(   A! .AA! A! !	B*$BBrI   )F)Hrr   rs   rt   r   rO  r   get_cgroup_check_periodrY  rh   r   r%  r  r:  r>  r  r  r  r'  r}  rx  rz  r  staticmethodr  r  r  r~  r  r  r   r  r   r  r  ORPHAN_WAIT_INTERVALr  r	  r
  r  r   r  r  r  r  propertyr   setterr  r@  r  r  r  r  r  r*   r  r  r   r  rs  r,   rr  r  r  r  r  r  r  rZ  r[  rt  r  rP   rN   rL   r{   r{      sS   !*2!6 )2N$2N2N2P Q9GvzxeNM(&"[
!''RH,Tgn)XV Z Z U U"HcZ,,. ) )K$" $P $PL 7K >#-
"8S	)     ! ! > > V VO
= F F: #0_ 
E I I"'  KZ Un#0?<h* #w #wJ  .0d2 ' '=:]rN   r{   c                       e Zd Zd Zed        Zed        Zed        Zd Z	d Z
d Zd Zd	 Zd
 Zed        Zed        Zed        ZddZd Zd Zd Zd Zd Zy)r  c                 f   || _         || _        || _        d}|Ct        j                  |      }|t        dj                  |            |j                  d      }n| j                  |j                  }|t        dj                  |            t        |      | _        |dnd}t        j                  d| j                  |       t        | j                               | _        | j                  j!                          	 | j#                          | j%                          y# t&        $ r}	 t(        j*                  j-                  | j/                               r%t1        j2                  | j/                         d	       n:# t&        $ r.}	t        j4                  d
j                  |	             Y d}	~	nd}	~	ww xY wdj                  | j                        }
dj                  |
t7        j8                  |            }t;        t<        | j                  t>        j@                  d|       Y d}~yd}~ww xY w)a  
        If 'path' is given, the object is initialized to the version installed under that path.

        If 'pkg' is given, the version specified in the package information is downloaded and the object is
        initialized to that version.

        'is_fast_track_goal_state' and 'protocol' are used only when a package is downloaded.

        NOTE: Prefer using the from_installed_agent and from_agent_package methods instead of calling __init__ directly
        NzIllegal agent directory: {0}r   zIllegal agent version: {0}diskpackagezLoading Agent {0} from {1}Tra  z!Unable to delete Agent files: {0}z(Agent {0} install failed with exception:r   Fr   )!_is_fast_track_goal_staterG  	_protocolr)   r  r   r   r   r   r$   r   r   rb   GuestAgentErrorget_agent_error_filerV   load_ensure_downloaded_ensure_loadedr   r   r   r  r   r  r  r   r	   r   r   r(   r   Install)re   r   rG  r  rH  r   r  locationr   rD  r   detailed_msgs               rL   rh   zGuestAgent.__init__  s    *B&!!''-Ay!"A"H"H"NOOggajGXX!kkG?;BB7KLL&w/".7J4diiJ$T%>%>%@A


	&##%! 	&M77==!3!3!56MM$"4"4"6dK M?FFsKLLM=DD		C$++C1J1J11MNL%-- $& &	&s>    D" "
H0-AF ?H+ 	F7	$F2-H+2F77A/H++H0c                     t        | ddd      S )zb
        Creates an instance of GuestAgent using the agent installed in the given 'path'.
        NFr  )r   s    rL   r  zGuestAgent.from_installed_agent  s    
 $dE22rN   c                     t        d| ||      S )z
        Creates an instance of GuestAgent using the information provided in the 'package'; if that version of the agent is not installed it, it installs it.
        Nr  )r  r  rH  s      rL   r@  zGuestAgent.from_agent_package  s    
 $3KLLrN   c                 B    dj                  t        | j                        S )Nz{0}-{1})r   r(   r   rp   s    rL   rb   zGuestAgent.name  s    
DLL99rN   c                 6    | j                   j                         S rI   )r  get_enable_commandrp   s    rL   r   zGuestAgent.get_agent_cmd  s    }}//11rN   c                 z    t         j                  j                  t        j                         | j
                        S rI   )r   r   r   r   r  rb   rp   s    rL   r   zGuestAgent.get_agent_dir!  s$    ww||D,,.		::rN   c                     t         j                  j                  t        j                         | j
                  t              S rI   )r   r   r   r   r  rb   AGENT_ERROR_FILErp   s    rL   r  zGuestAgent.get_agent_error_file$  s'    ww||D,,.		;KLLrN   c                 f    t         j                  j                  | j                         t              S rI   )r   r   r   r   AGENT_MANIFEST_FILErp   s    rL   get_agent_manifest_pathz"GuestAgent.get_agent_manifest_path'  s!    ww||D..02EFFrN   c                     dj                  t        j                  j                  t        j                         | j
                        df      S )N.r  )r   r   r   r   r  rb   rp   s    rL   get_agent_pkg_pathzGuestAgent.get_agent_pkg_path*  s2    xxd&6&6&8$))DeLMMrN   c                 l    | j                   j                          | j                   j                          y rI   )rV   clearsaverp   s    rL   r  zGuestAgent.clear_error-  s     



rN   c                 8    | j                   xr | j                   S rI   )is_downloadedr  rp   s    rL   r  zGuestAgent.is_available1  s    !!=$*=*=&==rN   c                 N    | j                   d uxr | j                   j                  S rI   )rV   r  rp   s    rL   r  zGuestAgent.is_blacklisted5  s     zz%C$***C*CCrN   c                 x    | j                   xs- t        j                  j                  | j	                               S rI   )r  r   r   r  r  rp   s    rL   r  zGuestAgent.is_downloaded9  s.    "" >ww~~d::<=	>rN   c                 r   	 t         j                  j                  | j                               s#t        j                  | j                                | j
                  j                  ||       | j
                  j                          | j
                  j                  rYdj                  | j                        }t        j                  |       t        t        j                  d|d| j                          y y # t"        $ r4}t        j                  d| j                  t%        |             Y d }~y d }~ww xY w)Nr   z$Agent {0} is permanently blacklistedF)r   r   r   r   r   z+Agent {0} failed recording error state: {1})r   r   r  r   makedirsrV   r   r  r  r   rb   r   r   r   r   AgentBlacklistedr   r   r   )re   r   r   r   r   s        rL   r   zGuestAgent.mark_failure>  s    	\77==!3!3!56D..01JJ##Xf#EJJOOzz((=DDTYYOC /@@U\_kp"&,,0 )
  	\KKF		SWXYSZ[[	\s   C5C9 9	D6*D11D6c                    t        j                  d| j                         | j                  r!t        j                  d| j                         y | j                  $t        dj                  | j                              | j                          dj                  | j                        }t        j                  |       t        t        | j                  t        j                  d|       y )Nz Ensuring Agent {0} is downloadedz7Agent {0} was previously downloaded - skipping downloadz.Agent {0} is missing package and download URIsz!Agent {0} downloaded successfullyTr   )r   r   rb   r  rG  r   r   	_downloadr   r(   r   r   r  r  s     rL   r  zGuestAgent._ensure_downloadedL  s    :DIIFNNUW[W`W`a88OVV		   	299$))DsLL!))	rN   c                 D    | j                          | j                          y rI   )_load_manifest_load_errorrp   s    rL   r  zGuestAgent._ensure_loadedb  s    rN   c                    	 | j                   j                  j                  d| j                  j                  | j                         | j                         | j                         y # t        $ r[}dj                  | j                  t        |            }t        t        t        j                  t         d|       t#        |      d }~ww xY w)Nzagent package)use_verify_headerz!Unable to download Agent {0}: {1}F)r   r   r   r   )r  r*  download_zip_packagerG  r)  r  r   r  r   r   rb   r   r   r(   r   r:  r,   r   r\  s      rL   r  zGuestAgent._downloadf  s    
	#NN!!66W[WnWnWprv  sE  sE  sG  [_  [y  [y6  z 	#5<<TYYYXC%..'  c""	#s   A$A' '	C0ACCc                 ^   	 t        | j                               | _        | j                  j                          t	        j
                  d| j                  t        | j                               y # t        $ r4}t	        j                  d| j                  t        |             Y d }~y d }~ww xY w)NzAgent {0} error state: {1}z)Agent {0} failed loading error state: {1})
r  r  rV   r  r   r   rb   r   r   r   r  s     rL   r  zGuestAgent._load_errors  sz    	Z()B)B)DEDJJJOONN8$))T$**EUV 	ZKKDdiiQUVWQXYY	Zs   A,A/ /	B,8*B''B,c           	      N   | j                         }t        j                  j                  |      s+dj	                  | j
                  t              }t        |      t        |d      5 }	 t        j                  |      }t        |      t        u r?t        |      dk  r+dj	                  | j
                  t              }t        |      |d   }n|}d d d        	 t!              | _        t        | j"                  j%                               dk  rt        d      	 t'        j(                  d| j
                  | j                                t'        j(                  d	| j
                  t        t        | j"                  j*                               y # t        $ r:}dj	                  | j
                  t        t        |            }t        |      d }~ww xY w# 1 sw Y   xY w# t        $ r:}dj	                  | j
                  t        t        |            }t        |      d }~ww xY w)
Nz!Agent {0} is missing the {1} filerz#Agent {0} has a malformed {1} ({2})r   zAgent {0} has an empty {1}z&Manifest is missing the enable commandz!Agent {0} has an illegal {1}: {2}z"Agent {0} loaded manifest from {1}z&Successfully loaded Agent {0} {1}: {2})r  r   r   r  r   rb   r  r   openjsonr  r   r   r   listr  r9   r  r  r   r   data)re   r   r   manifest_file	manifestsr   r  s          rL   r  zGuestAgent._load_manifest{  s   ++-ww~~d#6==diiI\]Cc""$_ 	%' IIm4	 I$&y>Q&7>>tyyJ]^C%c**$Q<$	%		#+H5DM4==3356!; IJJ < 	1II((*	, 	@yy*DMM../	1 	=  '<CCDIIObdhijdkl!#&&'	% 	%$  	#6==		#QC c""	#sJ   'G)F>AGAG! 	G5GGGG!	H$*5HH$NFr  )rr   rs   rt   rh   r  r  r@  r  rb   r   r   r  r  r  r  r  r  r  r   r  r  r  r  r  rP   rN   rL   r  r    s    3&j 3 3 M M : :2;MGN > > D D > >\,#Z'rN   r  c                   N    e Zd Zd ZddZd Zed        Zd Zd Z	d Z
d Zd	 Zy
)r  c                     d| _         d| _        |t        d      || _        d| _        d| _        | j                          y )N        FzGuestAgentError requires a pathr   r  )last_failure	was_fatalr   r   failure_countr   r  )re   r   s     rL   rh   zGuestAgentError.__init__  sD    <@AA	

rN   c                 |    t        j                          | _        | xj                  dz  c_        || _        || _        y r  )r   r  r  r  r   )re   r   r   s      rL   r   zGuestAgentError.mark_failure  s2     IIKa!rN   c                 <    d| _         d| _        d| _        d| _        y )Nr  r   Fr  r  r  r  r   rp   s    rL   r  zGuestAgentError.clear  s#    rN   c                 D    | j                   xs | j                  t        k\  S rI   )r  r  MAX_FAILURErp   s    rL   r  zGuestAgentError.is_blacklisted  s    ~~B!3!3{!BBrN   c           	          | j                   nt        j                   j                  | j                         rE	 t        | j                   d      5 }| j	                  t        j                  |             d d d        y y # 1 sw Y   y xY w# t        $ r|}t        j                  dj                  | j                   t        j                  |                   	 t        j                  | j                          n# t        $ r Y nw xY wY d }~y d }~ww xY w)Nr  zYRan into error when trying to load error file {0}, deleting it to clean state. Error: {1})r   r   r  r  	from_jsonr  r  r   r   r   r   r	   r   r  )re   r  rV   s      rL   r  zGuestAgentError.load  s    99 RWW^^DII%>$))S) 1QNN499Q<01 	1 	  
 ovv		8#<#<U#CEFIIdii(   	
sZ   B %A<2B <BB B 	DADC43D4	D =D?D  DDc                 0   t         j                  j                  t         j                  j                  | j                              rDt	        | j                  d      5 }t        j                  | j                         |       d d d        y y # 1 sw Y   y xY w)Nw)r   r   r  r  r  r  dumpto_json)re   r  s     rL   r  zGuestAgentError.save  s]    77==34dii% -		$,,.!,--s   %BBc                 Z   t        | j                  |j                  dd            | _        t        | j                  |j                  dd            | _        | j                  xs |j                  dd      | _        |j                  dd      }|dk7  r|| _        y | j
                  | _        y )	Nr  r  r  r   r  Fr   r  )maxr  getr  r  r   )re   r  r   s      rL   r  zGuestAgentError.from_json  s     1 1488OS3QR !3!3TXX>NPQ5RSH488L%+H)R( &"f 37++rN   c                 v    | j                   | j                  | j                  t        | j                        d}|S )Nr  )r  r  r  r   r   )re   r  s     rL   r  zGuestAgentError.to_json  s5    !.."00..DKK(	
 rN   c                 z    dj                  | j                  | j                  | j                  | j                        S )Nz?Last Failure: {0}, Total Failures: {1}, Fatal: {2}, Reason: {3})r   r  r  r  r   rp   s    rL   rq   zGuestAgentError.__str__  s5    PWWNNKK	 	rN   Nr  )rr   rs   rt   rh   r   r  r  r  r  r  r  r  rq   rP   rN   rL   r  r    s@    
 C C$rN   r  )wr  r  r   r<  r  r  r   r  r   r   r   r   r   r   azurelinuxagent.commonr   r   $azurelinuxagent.common.protocol.imdsr   azurelinuxagent.common.utilsr   r	   .azurelinuxagent.common.agent_supported_featurer
   r   )azurelinuxagent.common.cgroupconfiguratorr   azurelinuxagent.common.eventr   r   r   r    azurelinuxagent.common.exceptionr   r   r   r   azurelinuxagent.common.futurer   azurelinuxagent.common.osutilr   r   -azurelinuxagent.common.persist_firewall_rulesr   *azurelinuxagent.common.protocol.goal_stater   *azurelinuxagent.common.protocol.hostpluginr   r   'azurelinuxagent.common.protocol.restapir   r   r   r   $azurelinuxagent.common.protocol.utilr    r!   $azurelinuxagent.common.utils.archiver"   r#   -azurelinuxagent.common.utils.flexible_versionr$   (azurelinuxagent.common.utils.networkutilr%   &azurelinuxagent.common.utils.shellutilr&   azurelinuxagent.common.versionr'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   azurelinuxagent.ga.collect_logsr5   r6   +azurelinuxagent.ga.collect_telemetry_eventsr7   azurelinuxagent.ga.envr8   r  r9   r:   r;   r<   r=   azurelinuxagent.ga.monitorr>   (azurelinuxagent.ga.send_telemetry_eventsr?   r  r  r  r   r  r  CHILD_POLL_INTERVALr  r   r  r  r#  r%  r  objectrF   rw   r|   r{   r  r  rP   rN   rL   <module>r     sW  &   	  	     
   ( ' ) @ ; o H) ) A  A . = U F a  B 2 Q I E ?\ \ \ \ ` \ 20 0 : V , "     (. %  ' 
 /  " "6v J]F J]Z*L L^Mf MrN   