
    p
fm*                        d dl Z d dlZd dlZd dlZd dlmc mZ d dlmc mc m	Z	 d dl
mZ d dlmZm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dj9                  ee      ZdZdj9                  e      Zdj9                  e      Z dj9                  e      Z! ejD                  e!      Z# ejD                  e!dz         Z$ ejD                  dj9                  e!            Z%dZ&dZ' ejD                  e'      Z( e       Z)e)d    Z*e)d   Z+e)d   Z,e)d   Z-ej\                  Z/ej\                  d    Z0ej\                  d   Z1ej\                  d   Z2d Z3d Z4d Z5 e3       \  Z6Z7d  Z8 e8       Z9y)!    N)FlexibleVersion)ustrget_linux_distribution"_AZURE_GUEST_AGENT_DAEMON_VERSION_c                 ~    t        | t              r| n
t        |       }t        |      t        j                  t
        <   y)z
    Sets the value of the _AZURE_GUEST_AGENT_DAEMON_VERSION_ environment variable.

    The given 'version' can be a FlexibleVersion or a string that can be parsed into a FlexibleVersion
    N)
isinstancer   r   osenviron__DAEMON_VERSION_ENV_VARIABLE)versionflexible_versions     @/usr/lib/python3/dist-packages/azurelinuxagent/common/version.pyset_daemon_versionr   #   s0     #-Wo"FwO\cLd045E0FBJJ,-    c                      t         t        j                  v r t        t        j                  t                  S t        d      S )a  
    Retrieves the value of the _AZURE_GUEST_AGENT_DAEMON_VERSION_ environment variable.
    The value indicates the version of the daemon that started the current agent process or, if the current
    process is the daemon, the version of the current process.
    If the variable is not set (because the agent is < 2.2.53, or the process was not started by the daemon and
    the process is not the daemon itself) the function returns "0.0.0.0"
    z0.0.0.0)r   r	   r
   r    r   r   get_daemon_versionr   -   s0     %

2rzz*GHII9%%r   c                     g d} t        j                  d      }t        j                  d      }t        dd      5 }|j                         }|D ]  }|j	                  |      }|j	                  |      }|r|j                  d      | d<   <|s?|j                  d      | d<   | d   dk(  rd	| d
<   d	| d<   f| d   dk(  rd| d
<   d| d<   y| d   dk(  sd| d
<   d| d<    	 ddd       | S # 1 sw Y   | S xY w)z
    Add this workaround for detecting F5 products because BIG-IP/IQ/etc do
    not show their version info in the /etc/product-version location. Instead,
    the version and product information is contained in the /VERSION file.
    )NNNNz^Version: (\d+\.\d+\.\d+)z^Product: ([\w-]+)z/VERSIONr      zBIG-IPbigipr      zBIG-IQbigiq	iWorkflow	iworkflowN)recompileopen	readlinesmatchgroup)result
f5_version
f5_productfhcontentlineversion_matchesproduct_matchess           r   get_f5_platformr+   :   s    &F89J12J	j#	 ,",,. 	,D(..t4O(..t4O+11!4q	 +11!4q	!9( 'F1I 'F1IAY(* 'F1I 'F1IAY+- +F1I +F1I	,,$ M%,$ Ms   AC'AC'C''C1c                  >   dx} x}}t        d      j                         j                         }t        d      5 }|D ]?  }|j                  d      \  }}}|j                         }|dk(  r|}0|dk(  r|} 8|dk(  s>|}A 	 d d d        d| d	z   |z   ||gS # 1 sw Y   xY w)
N /etc/cp-releasez/etc/cloud-versionz: releasetakebuildgaia.)r   readstrip	partition)	r0   r1   r/   	full_namefr(   k_vs	            r   get_checkpoint_platformr<   Y   s    D57&',,.446I	"	# 	q 	DnnT*GAq!	AI~fg		 D3J&;;	 	s   A B:BBc                  V   dt        j                         v r9t        j                  ddt	        t        j
                                     } d| ddg}ndt        j                         v r9t        j                  ddt	        t        j
                                     } d| ddg}ndt        j                         v rt        dd	      }nqd
t        j                         v r9t        j                  ddt	        t        j
                                     } d| ddg}n"	 t        t        j                               dgz   }t        j                  j                  d      r
d|d<   d|d<   t        j                  j                  d      rd|d<   t        j                  j                  d      rd|d<   t        j                  j                  d      rd|d<   t        j                  j                  d      r
t               }t        j                  j                  d      r
t               }t        j                  j                  d      rg d}t        j                  j                  d      rd|d<   |d   j                  d      j                  d      j!                         |d<   |S # t        $ r g d}Y tw xY w) NFreeBSDz\-.*\Zr-   freebsdOpenBSDopenbsdLinuxr   alpinezNS-BSDnsbsd)UNKNOWNFFFFr-   r-   z/etc/oracle-releaseoracler   zOracle Linuxr   z/etc/euleros-releaseeulerosz/etc/UnionTech-releaseuosz/etc/mariner-releasemarinerz/shared/vadcr.   z/home/guestshell/azure)iosxecsr1000vr-   zCisco IOSXE Linuxz/etc/photon-releasephotonos" )platformsystemr   subr   r/   r   listdist	Exceptionr	   pathexistsr+   r<   r5   lower)r/   osinfos     r   
get_distrorZ   i   s   HOO%%&&BX-=-=-?(@AWb)4	hoo'	'&&BX-=-=-?(@AWb)4	HOO%	%'84	X__&	&&&BX-=-=-?(@A7B0	1(--/*bT1F 
ww~~+,q	"q		ww~~,-q		ww~~./q		ww~~,-q	 
ww~~n% "	ww~~'((*	ww~~./?	ww~~+,q	 q	$**3/557F1IME  	10F	1s   !J J('J(AbsentFailedc                  p    	 t        j                  g d      } | r| S t        S # t        $ r	 t        cY S w xY w)a  
    This uses the Linux kernel's 'modinfo' command to retrieve the
    "version" field for the "hv_vmbus" kernel module (the LIS
    drivers). This is the documented method to retrieve the LIS module
    version. Every Linux guest on Hyper-V will have this driver, but
    it may not be installed as a module (it could instead be built
    into the kernel). In that case, this will return "Absent" instead
    of the version, indicating the driver version can be deduced from
    the kernel version. It will only return "Failed" in the presence
    of an exception.

    This function is used to generate telemetry for the version of the
    LIS drivers installed on the VM. The function and associated
    telemetry can be removed after a few releases.
    )modinfoz-Fr   hv_vmbus)	shellutilrun_commandCOMMAND_ABSENTrU   COMMAND_FAILED)modinfo_outputs    r   get_lis_versionre      s@     "../WX!!   	s   # # 55c                      	 t        j                  ddg      j                  d      d   } | S # t         j                  $ r	 t        cY S t
        $ r	 t        cY S w xY w)N	logrotatez	--version
r   )r`   ra   splitCommandErrorrb   rU   rc   )logrotate_versions    r   has_logrotaterl      s`    %11;2LMSSTXYZ[\  !!   s   *- AAAWALinuxAgentzAzure Linux Agentz2.9.1.1z{0}-{1}z
The Azure Linux Agent supports the provisioning and running of Linux
VMs in the Azure cloud. This package should be installed on Linux disk
images that are built to run in the Azure environment.
z{0}-*z	{0}-*.zipz{0}-(.*)z\.zipz.*/{0}IAASz6.*/WALinuxAgent-(\d+.\d+.\d+[.\d+]*).*-run-exthandlersr   r   r   c                     t        j                         } t        j                         }|d   t         j                  j
                  k7  r|t         j                  j
                  z  }| t        |      d  j                  t         j                  j
                        d   }t        j                  |      }|r|j                  d      }nt        }t        }|t        |      fS )Nr   r   )r	   getcwdconfget_lib_dirrV   seplenri   AGENT_NAME_PATTERNr!   r"   AGENT_LONG_VERSIONAGENT_VERSIONr   )rV   lib_diragentr!   r   s        r   set_current_agentr{      s    99;D Gr{bggkk!277;;W%%bggkk215E$$U+E++a."/'***r   c                 x    t         j                  j                  |       } t        j                  t
        |       d uS N)r	   rV   basenamer   r!   AGENT_PKG_PATTERNrV   s    r   is_agent_packager     s-    77D!Dxx)40D88r   c                 x    t         j                  j                  |       } t        j                  t
        |       d uS r}   )r	   rV   r~   r   r!   rv   r   s    r   is_agent_pathr     s-    77D!Dxx*D1T99r   c                     d } t         j                  j                  d      r4t        j                  d      D cg c]  }|j	                         s| }}ng }|D ]t  }	 t        t         j                  j                  d|d      d      j                         }t        j                  |j                               }|r|j                  d      }  nv | t        } | S c c}w # t        $ r Y w xY w)Nz/proccmdlinerbr   )r	   rV   isdirlistdirisdigitr   joinr4   EXT_HANDLER_REGEXr!   decoder"   IOErrorCURRENT_VERSION)rz   pidpidspnamer!   s        r   set_goal_state_agentr     s    E	ww}}W!zz'2DckkmDD 	gsI>EJJLE%++ELLN;EA 	 }L E  		s   CCA/C  	C,+C,):r	   r   rP   sysazurelinuxagent.common.confcommonrr   &azurelinuxagent.common.utils.shellutilutilsr`   -azurelinuxagent.common.utils.flexible_versionr   azurelinuxagent.common.futurer   r   r   r   r   r+   r<   rZ   rb   rc   re   rl   
AGENT_NAMEAGENT_LONG_NAMErx   formatrw   AGENT_DESCRIPTIONAGENT_DIR_GLOBAGENT_PKG_GLOBAGENT_PATTERNr   rv   r   AGENT_DIR_PATTERNAGENT_EXECUTION_MODEEXT_HANDLER_PATTERNr   
__distro__DISTRO_NAMEDISTRO_VERSIONDISTRO_CODE_NAMEDISTRO_FULL_NAMEversion_info
PY_VERSIONPY_VERSION_MAJORPY_VERSION_MINORPY_VERSION_MICROr{   r   r   CURRENT_AGENTr   r   GOAL_STATE_AGENT_VERSIONr   r   r   <module>r      s  $ 
 	  
 * * : : I F D G
&>< 3j hh<	 
% %%j-@   
+##J/"":.RZZ. BJJ}X56 BJJx}=>   O BJJ23 \
mAa= a= 
##A& ##A& ##A& +9
:
 "3!4 ( 01 r   