
    d>N                        d Z ddlZddlZddlmZ ddlmZ dZ G d de      Z	 e	       Z
e
fdZi d	d
dd
dd
dd
dd
dd
dd
dddddddd
dd
dd
dd
dd
dd
dd
d
d
d
ddd
ddd
dd
dZi dddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/dd0d1d2d3d4d5d6dd7d8d9dd:d;d<d=d>d?Zi d@dAdBdAdCdDdEdFdGdFdHdFdIdJdKdFdLdMdNddOddPdQdRdQdSdDdTdUdVdWdXdYdDdZd[d[d\Ze
fd]Zd^ Zd_ Zd` Ze
fdaZe
fdbZe
fdcZe
fddZe
fdeZe
fdfZe
fdgZe
fdhZe
fdiZe
fdjZe
fdkZe
fdlZe
fdmZe
fdnZ e
fdoZ!e
fdpZ"dq Z#e
fdrZ$e
fdsZ%e
fdtZ&e
fduZ'e
fdvZ(e
fdwZ)e
fdxZ*e
fdyZ+e
fdzZ,e
fd{Z-e
fd|Z.e
fd}Z/e
fd~Z0e
fdZ1e
fdZ2e
fdZ3e
fdZ4e
fdZ5e
fdZ6e
fdZ7e
fdZ8e
fdZ9e
fdZ:e
fdZ;e
fdZ<e
fdZ=e
fdZ>e
fdZ?e
fdZ@e
fdZAe
fdZBe
fdZCe
fdZDe
fdZEe
fdZFe
fdZGe
fdZHe
fdZIe
fdZJe
fdZKe
fdZLe
fdZMe
fdZNe
fdZOe
fdZPe
fdZQe
fdZRe
fdZSe
fdZTe
fdZUe
fdZVe
fdZWe
fdZXe
fdZYe
fdZZe
fdZ[e
fdZ\e
fdZ]e
fdZ^e
fdZ_e
fdZ`e
fdZae
fdZby)z1
Module conf loads and parses configuration file
    N)	read_file)AgentConfigErrordisable_agentc                   >    e Zd ZdZd Zd Zed        Zd Zd Z	d Z
y)	ConfigurationProviderz:
    Parse and store key:values in /etc/waagent.conf.
    c                 "    t               | _        y N)dictvalues)selfs    =/usr/lib/python3/dist-packages/azurelinuxagent/common/conf.py__init__zConfigurationProvider.__init__%   s    f    c                 t   |st        d      |j                  d      D ]  }|j                  d      rd|v s|j                  dd      }t        |      dk  r;|d   j	                         }|d   j                  d      d   j	                  d      j	                         }|d	k7  r|nd | j
                  |<    y )
Nz#Can't not parse empty configuration
#=      r   z" None)r   split
startswithlenstripr   )r   contentlinepartskeyvalues         r   loadzConfigurationProvider.load(   s    "#HIIMM$' 	FD??3'C4K

3*u:>Ahnn&as+A.44U;AAC,1VO5C 	Fr   c                 ,    t        | d      r |        S | S )N__call__)hasattr)defaults    r   _get_defaultz"ConfigurationProvider._get_default4   s    7J'9r   c                 b    | j                   j                  |      }||S | j                  |      S )z
        Retrieves a string parameter by key and returns its value. If not found returns the default value,
        or if the default value is a callable returns the result of invoking the callable.
        )r   getr%   r   r   default_valuevals       r   r'   zConfigurationProvider.get:   s0    
 kkooc"osK4+<+<]+KKr   c                     | j                   j                  |      }||j                         dk(  ry||j                         dk(  ry| j                  |      S )z
        Retrieves a switch parameter by key and returns its value as a boolean. If not found returns the default value,
        or if the default value is a callable returns the result of invoking the callable.
        yTnF)r   r'   lowerr%   r(   s       r   
get_switchz ConfigurationProvider.get_switchB   sQ    
 kkooc"?syy{c1_!3  //r   c                     	 t        | j                  j                  |            S # t        $ r | j	                  |      cY S t
        $ r | j	                  |      cY S w xY w)z
        Retrieves an int parameter by key and returns its value. If not found returns the default value,
        or if the default value is a callable returns the result of invoking the callable.
        )intr   r'   	TypeErrorr%   
ValueError)r   r   r)   s      r   get_intzConfigurationProvider.get_intN   sX    
	4t{{s+,, 	4$$]33 	4$$]33	4s   #& AAAN)__name__
__module____qualname____doc__r   r    staticmethodr%   r'   r/   r4    r   r   r   r       s6    
F  
L
0
4r   r   c                    t         j                  j                  |       dk(  rt        dj	                  |             	 t        |       }|j                  |       y# t        $ r }t        dj	                  | |            d}~ww xY w)z-
    Load conf file from: conf_file_path
    FzMissing configuration in {0}z!Failed to load conf file:{0}, {1}N)ospathisfiler   formatr   r    IOError)conf_file_pathconfr   errs       r   load_conf_from_filerD   ^   s     
ww~~n%. !#$*F>$:< 	<AN+		' A !#$*F>3$?A 	AAs   A 	B$A??BOS.AllowHTTPFOS.EnableFirewallOS.EnableFIPSOS.EnableRDMAOS.UpdateRdmaDriverOS.CheckRdmaDriverLogs.VerboseLogs.ConsoleTLogs.CollectExtensions.EnabledProvisioning.AllowResetSysUser%Provisioning.RegenerateSshHostKeyPairProvisioning.DeleteRootPasswordProvisioning.DecodeCustomDataProvisioning.ExecuteCustomDataProvisioning.MonitorHostNameDetectScvmmEnv)ResourceDisk.FormatResourceDisk.EnableSwap!ResourceDisk.EnableSwapEncryptionAutoUpdate.EnabledEnableOverProvisioningDebug.CgroupLogMetrics(Debug.CgroupDisableOnProcessCheckFailure&Debug.CgroupDisableOnQuotaCheckFailure!Debug.EnableAgentMemoryUsageCheckDebug.EnableFastTrackDebug.EnableGAVersioningLib.Dir/var/lib/waagentDVD.MountPoint/mnt/cdrom/securePid.File/var/run/waagent.pidExtension.LogDir/var/log/azureOS.OpensslPath/usr/bin/openssl	OS.SshDir/etc/ssh
OS.HomeDir/homeOS.PasswordPath/etc/shadowOS.SudoersDir/etc/sudoers.dOS.RootDeviceScsiTimeoutProvisioning.AgentautoProvisioning.SshHostKeyPairTypersaProvisioning.PasswordCryptId6HttpProxy.HostResourceDisk.MountPoint/mnt/resourceResourceDisk.MountOptionsResourceDisk.Filesystemext3Prod
2022-03-31.Microsoft.Azure.Monitor.AzureMonitorLinuxAgent)AutoUpdate.GAFamilyDebug.CgroupMonitorExpiryTime Debug.CgroupMonitorExtensionNameExtensions.GoalStatePeriod   !Extensions.InitialGoalStatePeriodOS.EnableFirewallPeriod,  !OS.RemovePersistentNetRulesPeriod   OS.RootDeviceScsiTimeoutPeriod!OS.MonitorDhcpClientRestartPeriodOS.SshClientAliveInterval   "Provisioning.MonitorHostNamePeriod$Provisioning.PasswordCryptSaltLength
   HttpProxy.PortResourceDisk.SwapSizeMBAutoupdate.Frequency  Logs.CollectPeriodDebug.CgroupCheckPeriodDebug.AgentCpuQuota2   $Debug.AgentCpuThrottledTimeThresholdx   Debug.AgentMemoryQuota  @8  Q )Debug.EtpCollectionPeriodDebug.AutoUpdateHotfixFrequencyDebug.AutoUpdateNormalFrequencyDebug.FirewallRulesLogPeriodc                     i }t         D ]  }| j                  |t         |         ||<     t        D ]  }| j                  |t        |         ||<     t        D ]  }| j                  |t        |         ||<     |S r	   )__SWITCH_OPTIONS__r/   __STRING_OPTIONS__r'   __INTEGER_OPTIONS__r4   )rB   optionsoptions      r   get_configurationr      s    G$ N//&2DV2LMN % G((6+=f+EFG & L,,v/B6/JKL Nr   c                 X    | t         v r	t         |    S t        dj                  |             Nz+{0} is not a valid configuration parameter.)r   r3   r?   r   s    r   get_default_valuer      -    ##!&))
BII&Q
RRr   c                 j    | t         v rt        t         |          S t        dj                  |             r   )r   r1   r3   r?   r   s    r   get_int_default_valuer      s3    $$&v.//
BII&Q
RRr   c                 X    | t         v r	t         |    S t        dj                  |             r   )r   r3   r?   r   s    r   get_switch_default_valuer      r   r   c                 &    | j                  dd      S )NrF   Fr/   rB   s    r   enable_firewallr      s    ??.66r   c                 &    | j                  dd      S )Nr   r   r4   r   s    r   get_enable_firewall_periodr      s    <<1377r   c                 &    | j                  dd      S )Nr   r   r   r   s    r   &get_remove_persistent_net_rules_periodr          <<;R@@r   c                 &    | j                  dd      S )Nr   r   r   r   s    r   &get_monitor_dhcp_client_restart_periodr      r   r   c                 v    | j                  dd      xs& | j                  dd      xs | j                  dd      S )NrH   FrI   rJ   r   r   s    r   enable_rdmar      s=    ???E2 8??0%88??/78r   c                 &    | j                  dd      S )NrI   Fr   r   s    r   enable_rdma_updater          ??0%88r   c                 &    | j                  dd      S )NrJ   Tr   r   s    r   enable_check_rdma_driverr          ??/66r   c                 &    | j                  dd      S )NrK   Fr   r   s    r   get_logs_verboser         ??>511r   c                 &    | j                  dd      S )NrL   Tr   r   s    r   get_logs_consoler         ??>400r   c                 &    | j                  dd      S )NrM   Tr   r   s    r   get_collect_logsr     r   r   c                 &    | j                  dd      S )Nr   r   r   r   s    r   get_collect_logs_periodr     s    <<,d33r   c                 &    | j                  dd      S )Nra   rb   r'   r   s    r   get_lib_dirr     s    88I122r   c                 T    t         j                  j                  t        |       d      S )Npublished_hostname)r<   r=   joinr   r   s    r   get_published_hostnamer     s    77<<D)+?@@r   c                 &    | j                  dd      S )Nrc   rd   r   r   s    r   get_dvd_mount_pointr     s    88$&9::r   c                 &    | j                  dd      S )Nre   rf   r   r   s    r   get_agent_pid_file_pathr   !  s    88J 677r   c                 &    | j                  dd      S )Nrg   rh   r   r   s    r   get_ext_log_dirr   %  s    88&(899r   c                       y)Nz/var/log/waagent.logr:   r:   r   r   get_agent_log_filer   )  s    !r   c                 &    | j                  dd      S )NrG   Fr   r   s    r   get_fips_enabledr   -  s    ???E22r   c                 &    | j                  dd      S )Nri   rj   r   r   s    r   get_openssl_cmdr   1  s    88$&899r   c                 &    | j                  dd      S )Nr   r   r   r   s    r   get_ssh_client_alive_intervalr   5  s    88/55r   c                 &    | j                  dd      S )Nrk   rl   r   r   s    r   get_ssh_dirr   9  s    88K,,r   c                 &    | j                  dd      S )Nrm   rn   r   r   s    r   get_home_dirr   =  s    88L'**r   c                 &    | j                  dd      S )Nro   rp   r   r   s    r   get_passwd_file_pathr   A  s    88%}55r   c                 &    | j                  dd      S )Nrq   rr   r   r   s    r   get_sudoers_dirr   E  s    88O%566r   c                 T    t         j                  j                  t        |       d      S )Nsshd_configr<   r=   r   r   r   s    r   get_sshd_conf_file_pathr   I  s    77<<D)=99r   c                 T    t         j                  j                  t        |       d      S )Nzssh_host_*key*r   r   s    r   get_ssh_key_globr   M  s    77<<D)+;<<r   c                     t         j                  j                  t        |       dj	                  t        |                   S )Nzssh_host_{0}_keyr<   r=   r   r   r?   get_ssh_host_keypair_typer   s    r   get_ssh_key_private_pathr   Q  s4    77<<D)!!";D"ABD Dr   c                     t         j                  j                  t        |       dj	                  t        |                   S )Nzssh_host_{0}_key.pubr   r   s    r   get_ssh_key_public_pathr   V  s4    77<<D)%%&?&EFH Hr   c                 &    | j                  dd       S )Nrs   r   r   s    r   get_root_device_scsi_timeoutr   [  s    88.55r   c                 &    | j                  dd      S )Nr   r   r   r   s    r   #get_root_device_scsi_timeout_periodr   _  s    <<8"==r   c                 8    | j                  dd      }|dk(  r	 y|S )Nrv   rw   ru   r   )rB   keypair_types     r   r   r   c  s+    88=uELv	 r   c                 &    | j                  dd      S )Nrv   rw   r   r   s    r   get_ssh_host_keypair_moder  n  s    885u==r   c                 &    | j                  dd      S )NrN   Tr   r   s    r   get_extensions_enabledr  r  r   r   c                 &    | j                  dd      S )Nr   r   r   r   s    r   get_goal_state_periodr  v  s    <<4a88r   c                 0      j                  d fd      S )Nr   c                      t               S )Nr   )r  r   s   r   <lambda>z/get_initial_goal_state_period.<locals>.<lambda>{  s    ShnrSs r   )r)   r   r   s   `r   get_initial_goal_state_periodr  z  s    <<;Ks<ttr   c                 &    | j                  dd      S )NrO   Fr   r   s    r   get_allow_reset_sys_userr  ~      ??;UCCr   c                 &    | j                  dd      S )NrP   Fr   r   s    r   get_regenerate_ssh_host_keyr    s    ??BEJJr   c                 &    | j                  dd      S )NrQ   Fr   r   s    r   get_delete_root_passwordr    s    ??<eDDr   c                 &    | j                  dd      S )NrR   Fr   r   s    r   get_decode_customdatar    s    ??:EBBr   c                 &    | j                  dd      S )NrS   Fr   r   s    r   get_execute_customdatar    r  r   c                 &    | j                  dd      S )Nrx   ry   r   r   s    r   get_password_cryptidr    s    882C88r   c                 &    | j                  dd      S )Nrt   ru   r   r   s    r   get_provisioning_agentr    s    88(&11r   c                     t        |       dv S )a'  
    Provisioning (as far as waagent is concerned) is enabled if either the
    agent is set to 'auto' or 'waagent'. This wraps logic that was introduced
    for flexible provisioning agent configuration and detection. The replaces
    the older bool setting to turn provisioning on or off.
    )ru   waagent)r  r   s    r   get_provision_enabledr    s     "$'+>>>r   c                 &    | j                  dd      S )Nr   r   r   r   s    r   get_password_crypt_salt_lenr     s    <<>CCr   c                 &    | j                  dd      S )NrT   Fr   r   s    r   get_monitor_hostnamer"    s    ??95AAr   c                 &    | j                  dd      S )Nr   r   r   r   s    r   get_monitor_hostname_periodr$    s    <<<bAAr   c                 &    | j                  dd       S )Nrz   r   r   s    r   get_httpproxy_hostr&    s    88$d++r   c                 &    | j                  dd       S )Nr   r   r   s    r   get_httpproxy_portr(    s    <<($//r   c                 &    | j                  dd      S )NrU   Fr   r   s    r   get_detect_scvmm_envr*    s    ??+U33r   c                 &    | j                  dd      S )NrV   Fr   r   s    r   get_resourcedisk_formatr,    r   r   c                 &    | j                  dd      S )NrW   Fr   r   s    r   get_resourcedisk_enable_swapr.    s    ??4e<<r   c                 &    | j                  dd      S )NrX   Fr   r   s    r   'get_resourcedisk_enable_swap_encryptionr0    s    ??>FFr   c                 &    | j                  dd      S )Nr{   r|   r   r   s    r   get_resourcedisk_mountpointr2    s    88-??r   c                 &    | j                  dd       S )Nr}   r   r   s    r   get_resourcedisk_mountoptionsr4    s    88/66r   c                 &    | j                  dd      S )Nr~   r   r   r   s    r   get_resourcedisk_filesystemr6    s    88-v66r   c                 &    | j                  dd      S )Nr   r   r   r   s    r   get_resourcedisk_swap_size_mbr8    s    <<1155r   c                 &    | j                  dd      S )Nr   r   r   r   s    r   get_autoupdate_gafamilyr:    s    88)622r   c                 &    | j                  dd      S )NrY   Tr   r   s    r   get_autoupdate_enabledr<    r   r   c                 &    | j                  dd      S )Nr   r   r   r   s    r   get_autoupdate_frequencyr>    s    <<.55r   c                 &    | j                  dd      S )NrZ   Tr   r   s    r   get_enable_overprovisioningr@    s    ??3T::r   c                 &    | j                  dd      S )NrE   Fr   r   s    r   get_allow_httprB    r   r   c                 \    t         j                  j                  t        |       t              S r	   )r<   r=   r   r   DISABLE_AGENT_FILEr   s    r   get_disable_agent_file_pathrE    s    77<<D)+=>>r   c                 &    | j                  dd      S )NzCGroups.EnabledTr   r   s    r   get_cgroups_enabledrG    s    ??,d33r   c                 &    | j                  dd      S )Nz#Monitor.NetworkConfigurationChangesFr   r   s    r   )get_monitor_network_configuration_changesrI    s    ??@%HHr   c                 &    | j                  dd      S )z
    How often to perform checks on cgroups (are the processes in the cgroups as expected,
    has the agent exceeded its quota, etc)

    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r   r   r   r   s    r   get_cgroup_check_periodrK    s     <<1377r   c                 &    | j                  dd      S )z
    If True, resource usage metrics are written to the local log

    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r[   Fr   r   s    r   get_cgroup_log_metricsrM    s     ??3U;;r   c                 &    | j                  dd      S )z
    If True, cgroups will be disabled if the process check fails

    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r\   Tr   r   s    r   +get_cgroup_disable_on_process_check_failurerO    s     ??EtLLr   c                 &    | j                  dd      S )z
    If True, cgroups will be disabled if the CPU quota check fails

    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r]   Tr   r   s    r   )get_cgroup_disable_on_quota_check_failurerQ    s     ??CTJJr   c                 &    | j                  dd      S )z
    CPU quota for the agent as a percentage of 1 CPU (100% == 1 CPU)

    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r   r   r   r   s    r   get_agent_cpu_quotarS    s     <<-r22r   c                 &    | j                  dd      S )z
    Throttled time threshold for agent cpu in seconds.

    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r   r   r   r   s    r   &get_agent_cpu_throttled_time_thresholdrU  '  s     <<>DDr   c                 &    | j                  dd      S )z
    Memory quota for the agent in bytes.

    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r   r   r   r   s    r   get_agent_memory_quotarW  0  s     <<0.AAr   c                 &    | j                  dd      S )z
    If True, Agent checks it's Memory usage.

    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r^   Fr   r   s    r   #get_enable_agent_memory_usage_checkrY  9  s     ??>FFr   c                 &    | j                  dd      S )z
    cgroups monitoring for pilot extensions disabled after expiry time

    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r   r   r   r   s    r   get_cgroup_monitor_expiry_timer[  B  s     883\BBr   c                 &    | j                  dd      S )z
    cgroups monitoring extension name

    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r   r   r   r   s    r   !get_cgroup_monitor_extension_namer]  K  s     8868hiir   c                 &    | j                  dd      S )z
    If True, the agent use FastTrack when retrieving goal states

    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r_   Tr   r   s    r   get_enable_fast_trackr_  T  s     ??2D99r   c                 &    | j                  dd      S )z
    Determines the frequency to perform ETP collection on extensions telemetry events.
    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r   r   r   r   s    r   get_etp_collection_periodra  ]  s    
 <<3S99r   c                 &    | j                  dd      S )z
    Determines the frequency to check for Hotfix upgrades (<Patch>.<Build> version changed in new upgrades).
    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r   r   r   r   s    r   get_hotfix_upgrade_frequencyrc  e  s    
 <<9;GGr   c                 &    | j                  dd      S )z
    Determines the frequency to check for Normal upgrades (<Major>.<Minor> version changed in new upgrades).
    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r   r   r   r   s    r   get_normal_upgrade_frequencyre  m  s    
 <<9<HHr   c                 &    | j                  dd      S )z
    If True, the agent uses GA Versioning for auto-updating the agent vs automatically auto-updating to the highest version.

    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r`   Fr   r   s    r   get_enable_ga_versioningrg  u  s     ??5u==r   c                 &    | j                  dd      S )z
    Determine the frequency to perform the periodic operation of logging firewall rules.

    NOTE: This option is experimental and may be removed in later versions of the Agent.
    r   r   r   r   s    r   get_firewall_rules_log_periodri  ~  s     <<6>>r   )cr8   r<   os.path%azurelinuxagent.common.utils.fileutilr    azurelinuxagent.common.exceptionr   rD  objectr   __conf__rD   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r   r"  r$  r&  r(  r*  r,  r.  r0  r2  r4  r6  r8  r:  r<  r>  r@  rB  rE  rG  rI  rK  rM  rO  rQ  rS  rU  rW  rY  r[  r]  r_  ra  rc  re  rg  ri  r:   r   r   <module>ro     sV  ( 
  ; =$ 84F 84v !" .6 A!E!! U! U	!
 5! %! E! D! D! $! %e! ,U! &u! $U! %e!  #E!!" e#!$ !$)."
 $04.2).! %A! H!) & (	
 (  ' } %  & &u #C d    !" v#$ "%1(X) 0 !' s (	
 %b (   )" +B d q D $$ s%& 2'( +C)* n+, "%',',$)3 : $ SSS " 7 %- 8 19 A 19 A  8 % 9 #+ 7 # 2 # 1 # 1 "* 4  3 !) A
 & ; "* 8 " :" # 3 " : (0 6  -  + ' 6 " 7 "* : # = #+ D
 "* H
 '/ 6 .6 > $,  $, > !) 7  ( 9 (0 u #+ D &. K #+ E  ( C !) D ' 9 !) 2  ( ? &. D ' B &. B % , % 0 ' 4 "* 9 '/ = 2: G &. @ (0 7 &. 7 (0 6 "* 3 !) 7 #+ 6 &. ; ! 2 &. ? & 4 4< I "* 8 !) < 6> M 4< K & 3 19 E !) B .6 G )1 C -5 j  ( : $, : '/ H '/ I #+ > (0 ?r   