
    d                         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mZmZ d dlmZmZ 	  G d de
      Zy)    N)ustr)DefaultOSUtilPRODUCT_ID_FILEDMIDECODE_CMDUUID_PATTERN)textutilfileutilc                   \     e Zd Z fdZed        Zd Z fdZd Zd Z	d Z
d Zd	 Z xZS )
IosxeOSUtilc                 *    t         t        |           y N)superr   __init__)self	__class__s    E/usr/lib/python3/dist-packages/azurelinuxagent/common/osutil/iosxe.pyr   zIosxeOSUtil.__init__)   s    k4)+    c                       y)Nz/usr/lib/systemd/system r   r   r   "get_systemd_unit_file_install_pathz.IosxeOSUtil.get_systemd_unit_file_install_path,   s    (r   c           	         dd|dg}	 t        j                  |       y# t        $ r]}t        j                  dj                  dj                  |      t        |                   t        j                  | |       Y d}~yd}~ww xY w)z
        Unlike redhat 6.x, redhat 7.x will set hostname via hostnamectl
        Due to a bug in systemd in Centos-7.0, if this call fails, fallback
        to hostname.
        hostnamectlzset-hostnamez--staticz1[{0}] failed with error: {1}, attempting fallback N)
	shellutilrun_command	Exceptionloggerwarnformatjoinr   r   set_hostname)r   hostnamehostnamectl_cmdes       r   r!   zIosxeOSUtil.set_hostname0   sv     ).(JO	7!!/2 	7KKKRRSVS[S[\kSlnrstnuvw&&tX66	7s    	BAA??Bc                 V    t        j                  d       t        t        |   |       y)zI
        Restart NetworkManager first before publishing hostname
        zservice NetworkManager restartN)r   runr   r   publish_hostname)r   r"   r   s     r   r'   zIosxeOSUtil.publish_hostname=   s!     	67k41(;r   c                 0    t        j                  dd      S )Nzsystemctl enable waagentFchk_errr   r&   r   s    r   register_agent_servicez"IosxeOSUtil.register_agent_serviceD   s    }}7GGr   c                 0    t        j                  dd      S )Nzsystemctl disable waagentFr)   r+   r,   s    r   unregister_agent_servicez$IosxeOSUtil.unregister_agent_serviceG   s    }}8%HHr   c                 2    t        j                  | ||       y r   )r   openssl_to_openssh)r   
input_fileoutput_files      r   r1   zIosxeOSUtil.openssl_to_opensshJ   s    ((z;Gr   c                      y)NFr   r,   s    r   is_dhcp_availablezIosxeOSUtil.is_dhcp_availableM   s    r   c                    t         j                  j                  t              rG	 t	        j
                  t              j                         }| j                  |j                               S t        j                  t              \  }}|dk7  st        j                  |      y| j                  |j                               S # t        $ r Y aw xY w)z
        Azure records a UUID as the instance ID
        First check /sys/class/dmi/id/product_uuid.
        If that is missing, then extracts from dmidecode
        If nothing works (for old VMs), return the empty string
        r    )ospathisfiler   r	   	read_filestrip_correct_instance_idIOErrorr   run_get_outputr   r   match)r   srcs      r   get_instance_idzIosxeOSUtil.get_instance_idP   s     77>>/*&&7==?00;; ((7A7l((+3((33  s   AC 	CC)__name__
__module____qualname__r   staticmethodr   r!   r'   r-   r/   r1   r5   rC   __classcell__)r   s   @r   r   r   (   sB    , ) )7<HIH4r   r   )r8   azurelinuxagent.common.loggercommonr   &azurelinuxagent.common.utils.shellutilutilsr   azurelinuxagent.common.futurer   %azurelinuxagent.common.osutil.defaultr   r   r   r   azurelinuxagent.common.utilsr   r	   r   r   r   r   <module>rP      s3   ( 
 . . : : . m m ;84- 84r   