
    x[h'                         S SK r S SKrS SKJrJrJrJr  S SKJr  S SKJ	r
  S SKJr  S SKJrJr  \ R                   " \5      r " S S\R&                  5      rg)	    N)distroshelperssubputil)PackageList)	rhel_util)HostnameConf)
PER_ALWAYSPER_INSTANCEc                       \ rS rSrSrSrS/rSrSrSr	Sr
S	rS
SSSSSSS.S.0rS rS$S jrS\4S jrS%S jrS rSS.S jrS$S jrS rS rS rS  rS! r\S" 5       rS#rg)&Distro   z/etc/sysconfig/clockz/etc/HOSTNAMEservicez/etc/sysconfig/languagez/etc/sysconfig/network/configz/etc/hostnamez/etc/locale.confz/etc/localtime	sysconfigzetc/sysconfig/network/configsusez%(base)s/network/ifcfg-%(name)sz3etc/udev/rules.d/85-persistent-net-cloud-init.rulesz!%(base)s/network/ifroute-%(name)s)ipv4ipv6)controlflavoriface_templatesnetrules_pathroute_templatesc                     [         R                  R                  XX#5        [        R                  " U5      U l        SU l        S U l        SU l        SUS'   U R                  5       (       a  S/U l
        SUS'   g g )Nr   Fsshdssh_svcname	systemctlzsshd.service)r   r   __init__r   Runners_runnerosfamilyupdate_methodread_only_rootuses_systemdinit_cmd)selfnamecfgpathss       </usr/lib/python3/dist-packages/cloudinit/distros/opensuse.pyr   Distro.__init__/   sn    C7u-!##M(MDM!/C     Nc                     U R                  5       (       a  U(       d  U R                  nSU0nOU(       d  U R                  nSU0n[        R                  " X#5        g )NLANGRC_LANG)r#   systemd_locale_conf_fnlocale_conf_fnrhutilupdate_sysconfig_file)r%   localeout_fn
locale_cfgs       r)   apply_localeDistro.apply_locale:   sO    44 &)J,,#V,J$$V8r+   pkglistc                 &    U R                  SSUS9  g )Ninstallz--auto-agree-with-licenses)argspkgs)package_command)r%   r8   s     r)   install_packagesDistro.install_packagesE   s    8w 	 	
r+   c                    Uc  / nU R                  5         U R                  (       a&  U R                  S:X  d  [        R	                  S5        g U R                  S:X  a  SS/nO/ SQnUS:X  a  SnU(       d  U R                  S:X  a  US:X  a  Sn/ S	QnUS
:X  a  SS/nUR                  U5        U(       a'  [        U[        5      (       a  UR                  U5        O-U(       a&  [        U[        5      (       a  UR                  U5        [        R                  " SU5      nUR                  U5        [        R                  " USS9  U R                  S:X  a  [        R                  S5        g g )NtransactionalzUPackage operation requested but read only root without btrfs and transactional-updatazypper--non-interactive)transactional-updaterC   --drop-if-no-changepkgupgradeupdateup)rD   rC   rE   refreshz%s-%sF)capturez8To use/activate the installed packages reboot the system)_set_update_methodr"   r!   LOGerrorappend
isinstancestrlistextendr   expand_package_listr   info)r%   commandr;   r<   cmdr8   s         r)   r=   Distro.package_commandJ   sC   <D!t'9'9_'LII9  )01CC iG""o58#GC i01C

7 JtS))JJtjt,,JJt**7D9

7 			#u%0HHJ 1r+   c                 n   U R                  U5      nU R                  5       (       aA  [        R                  " U R                  5        [        R
                  " X R                  5        g S[        U5      0n[        R                  " U R                  U5        [        R                  " X R                  5        g )NTIMEZONE)_find_tz_filer#   r   del_filetz_local_fnsym_linkrQ   r1   r2   clock_conf_fncopy)r%   tztz_file	clock_cfgs       r)   set_timezoneDistro.set_timezone   s    $$R( MM$**+MM'#3#34 CGI ((););YGIIg//0r+   F)forcec                t    U R                   R                  SU R                  S/U(       a  [        O[        S9  g )Nzupdate-sourcesrJ   )freq)r   runr=   r
   r   )r%   rf   s     r)   update_package_sourcesDistro.update_package_sources   s1      K$,	 	 	
r+   c                    U R                  5       (       a:  UR                  S5      (       a$  [        R                  " U5      R	                  5       $ U R                  5       (       a-  [
        R
                  " S/5      u  p4[        U5      (       a  U$ U$  U R                  U5      nUR                  nW(       d  U$ U$ ! [         a     Nf = f)N/previous-hostnamehostname)
r#   endswithr   load_text_filestripr   len_read_hostname_confrn   IOError)r%   filenamedefaultout_errconfrn   s          r)   _read_hostnameDistro._read_hostname   s    8#4#45I#J#J&&x06688  ))ZL1KS3xx
//9== O	  s   B; ;
CCc                     g)Nz	127.0.1.1 )r%   s    r)   _get_localhost_ipDistro._get_localhost_ip   s    r+   c                 d    [        [        R                  " U5      5      nUR                  5         U$ N)r	   r   rp   parse)r%   ru   ry   s      r)   rs   Distro._read_hostname_conf   s%    D//9:

r+   c                     U R                  5       (       a  U R                  nOU R                  nXR                  U5      4$ r   )r#   systemd_hostname_conf_fnhostname_conf_fnrz   )r%   host_fns     r)   _read_system_hostnameDistro._read_system_hostname   s;    33G++G,,W566r+   c                 &   U R                   Gc  [        R                  " S5      nSnU(       a  Uu  p2n[        R                  " S5      R	                  S5      nU HO  nUR                  U5      (       d  M  UR	                  5       nUS   U:w  a  M6  US   R                  S5      U l          O   UR                  5       S	:X  a,  [        R                  R                  S
5      (       a  SU l         gSU l         g[        R                  S5        SU l         gg)z7Decide if we want to use transactional-update or zypperN/ z/proc/mounts
      robtrfsz/usr/sbin/transactional-updaterA   rB   z7Could not determine filesystem type of '/' using zypper)r!   r   get_mount_inforp   split
startswithr"   lowerospathexistsrM   rU   )r%   resultfs_typedevpthmount_pointmountsmount
mount_infos           r)   rL   Distro._set_update_method   s    %((-FG17.+,,^<BB4H#E''//%*[[]
%a=K7$.8m.F.Ft.L+ $ ==?g-"''..43 3 *9D&)1D&M &."1 &r+   c                    [         R                  " U R                  SS5      nU R                  5       (       a-  UR	                  S5      (       a  [         R
                  " X!5        g U R                  5       (       aN  U(       a#  [        R                  " SS[        U5      /5        g [        R                  " SSS[        U5      /5        g S n U R                  U5      nU(       d  [        S5      nUR                  U5        [         R
                  " U[        U5      S	5        g ! [         a!    U(       a   NX[        R                  S5         g f = f)
Ncreate_hostname_fileTrm   hostnamectlzset-hostnamez--transientz7create_hostname_file is False; hostname file notcreatedr   i  )r   get_cfg_option_bool_cfgr#   ro   
write_filer   rQ   rs   rt   rM   rU   r	   set_hostname)r%   rn   ru   r   ry   s        r)   _write_hostnameDistro._write_hostname   s   #77II-t 
 8#4#45I#J#JOOH/  #		=.#h-HI		%&%H	 D //9 #B'h'OOHc$i7  'HH" s   D! !E4EEc                 .   U R                   (       dy  [        R                  " 5       S   nUS   n[        US   R	                  S5      S   5      nUS:  a  SU;  d  US:  a!  SU;   a  US:w  a  / SQU l         U R                   $ / S	QU l         U R                   $ )
z5The preferred ntp client is dependent on the version.distr   r   .   openSUSE*   )chronysystemd-timesyncdntp)r   r   r   )_preferred_ntp_clientsr   system_infointr   )r%   distro_infor&   	major_vers       r)   preferred_ntp_clientsDistro.preferred_ntp_clients  s    
 ****,V4Kq>DKN005a89I RJd$:RJ$$69?/+ ***/+ ***r+   )r   r   r$   r    r"   r!   r   )NN)__name__
__module____qualname____firstlineno__r_   r   r$   r0   network_conf_fnr   r/   r]   renderer_configsr   r6   r   r>   r=   rd   rj   rz   r~   rs   r   rL   r   propertyr   __static_attributes__r}   r+   r)   r   r      s    *M&{H.N5O./"K5@E <; 
	0	9
 

;z1  /4 
&
7.8$8L + +r+   r   )loggingr   	cloudinitr   r   r   r   cloudinit.distrosr   r   r1   "cloudinit.distros.parsers.hostnamer	   cloudinit.settingsr
   r   	getLoggerr   rM   r   r}   r+   r)   <module>r      sA     	 2 2 ) 1 ; 7!G+W^^ G+r+   