
    x[h*              
       z   % S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSK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  SS	KJr  S
rS\/\/ S.r\\S'   \R2                  " \5      rS rS rS rS rS r S r!S r"S r#S\4S\4S\4S\4S\ 4S\!4S\"4/r$S\#0r%S\\&   4S jr'S r(S  r)S!\&S"\S#\S$\*SS4
S% jr+S& r,g)'z:Resizefs: cloud-config module which resizes the filesystem    N)Optional)	lifecyclesubputil)Cloud)Config)
MetaSchema)ALL_DISTROS)
PER_ALWAYSnoblockcc_resizefs)iddistros	frequencyactivate_by_schema_keysmetac                 6   [         R                  " U 5      (       d2  [        R                  R	                  SU -  5      (       a  SSSSSU -  /nOSSSSU /n[
        R                  R                  S5      n[
        R                  R                  [        R                  " SS/5      R                  R                  S5      S	   R                  S
5      S   R                  5       5      nXC:  a&  UR                  S5      nUR                  US-   S5        [        U5      $ )Nz%s/.snapshotsbtrfs
filesystemresizemaxz5.10z	--version
r   v   z	--enqueue)r   mount_is_read_writeospathisdirr   Versionfrom_strr   stdoutsplitstripindexinserttuple)mount_pointdevpthcmdbtrfs_with_queuesystem_btrfs_veridxs         >/usr/lib/python3/dist-packages/cloudinit/config/cc_resizefs.py_resize_btrfsr/   %   s     ##K00RWW]]+%6 6 k)
 h{C
 !((11&9 ((11		7K()	dA		sB	 
	 +ii!

37K(:    c                 
    SU4$ )N	resize2fs r(   r)   s     r.   _resize_extr5   I   s      r0   c                 
    SU 4$ )N
xfs_growfsr3   r4   s     r.   _resize_xfsr8   M   s    +&&r0   c                     SSU 4$ )Ngrowfsz-yr3   r4   s     r.   _resize_ufsr;   Q   s    dK((r0   c                     SSSX4$ )Nzpoolonlinez-er3   r4   s     r.   _resize_zfsr?   U   s    Xt[99r0   c                     SSU 4$ )Nhammer2r:   r3   r4   s     r.   _resize_hammer2rB   Y   s    x--r0   c                     SSSU4$ )zSingle device resizebcachefsdevicer   r3   r4   s     r.   _resize_bcachefsrF   ]   s    (F33r0   c                     SnSn [         R                   " SSU/5        g! [         R                   a;  nUR                  R                  U5      (       a  X4R                  ;   a   S nAgUeS nAff = f)Nzgrowfs: requested sizez.is not larger than the current filesystem sizer:   z-NTF)r   ProcessExecutionErrorstderr
startswith)r(   r)   
skip_startskip_containes        r.   _can_skip_resize_ufsrN   b   si     *JCL		8T6*+  %% 88z**|xx/GGs     A//A*(A**A/r   extxfsufszfsrA   rD   returnc                    [         R                  " 5       (       a  [        R                  O[        R                  n[
        R                  R                  S5      (       d  [        R                  S5        g  [        R                  " SSU /5      u  p#U(       a  [        R                  SUU 5        g  SnUR                  S5       HZ  n[        R                  " XE5      (       d  M   X;  d  M'  S	U;  d  M/  UR                  5       S
   n[        R                  SX5        Us  $    U" SXU5        g ! [        R                   a  nU" SX5         S nAg S nAff = f)Nz/dev/zfsz"Cannot get zpool info, no /dev/zfsr=   statusz0zpool status returned error: [%s] for zpool [%s]z$Unable to get zpool status of %s: %sz.*(ONLINE).*r   stater   zfound zpool "%s" on disk %sz'No zpool found: [%s]: out: [%s] err: %s)r   is_containerLOGdebugwarningr   r   existsr   inforH   r#   research)r=   log_warnzpoolstatuserrrlinedisks          r.   get_device_info_from_zpoolre      s    --//syyS[[H77>>*%%		6799gx%?@HHB
   	A!!$'99Q%"3t8K::<?DII3UAK	 (
 15s  %% 7Ds   69D- -E	EEc                     U R                  5       n[        R                  5        H%  u  pEUR                  U5      (       d  M  U" X5      s  $    g)NF)lowerRESIZE_FS_PRECHECK_CMDSitemsrJ   )fs_typeresize_whatr)   	fstype_lcifuncs         r.   can_skip_resizero      sC    I*002"",, 3 r0   c                    [         R                  " 5       nU S:X  a  [        R                  R	                  U 5      (       d_  U(       dX  [         R
                  " [         R                  " 5       5      n U c  [        R                  S5        g[        R                  SU 5        U S:X  a  [        R                  SX5        gU R                  S5      (       a  [        R                  S5        U $ U R                  S	5      (       dQ  [        R                  R	                  U 5      (       d-  S	U R                  S
5      -   n[        R                  SU U5        Un  [        R                  " U 5      n[        R                   " UR"                  5      (       d\  [        R$                  " UR"                  5      (       d7  U(       a  [        R                  SU U5        g[        R                  SU U5        gU $ ! [         a~  nU(       a6  UR                  [        R                  :X  a  [        R                  SU U5        O7UR                  [        R                  :X  a  [        R                  SX5        OUe SnAgSnAff = f)a  Return updated devpath if the devpath is a writable block device.

@param devpath: Requested path to the root device we want to resize.
@param info: String representing information about the requested device.
@param log: Logger to which logs will be added upon error.

@returns devpath or updated devpath per kernel command line if the device
    path is a writable block device, returns None otherwise.
z	/dev/rootNz!Unable to find device '/dev/root'z.Converted /dev/root to '%s' per kernel cmdlineoverlayrootz)Not attempting to resize devpath '%s': %szgpt/z#We have a gpt label - just go aheadz/dev//z:'%s' doesn't appear to be a valid device path. Trying '%s'z9Device '%s' did not exist in container. cannot resize: %sz,Device '%s' did not exist. cannot resize: %sz>device '%s' not a block device in container. cannot resize: %sz1device '%s' not a block device. cannot resize: %s)r   rW   r   r   r[   rootdev_from_cmdlineget_cmdlinerX   rZ   rY   rJ   lstripstatOSErrorerrnoENOENTS_ISBLKst_modeS_ISCHR)devpathr\   	containerfulldevpathstatretexcs         r.   maybe_get_writable_device_pathr      s    !!#I 	;w''++D,<,<,>??KK;<		BGL-		=wM
 &!!		78 g&&rww~~g/F/Fs 33		H	

 '''"  <<((goo1N1NII%	  KKC
 N=  ell2IIK
 YY%,,&KK> Is   G* *
I24A4I--I2namecfgcloudargsc                    U(       a  US   nO[         R                  " USS5      n[         R                  " U[        /S9(       d  [        R                  SU 5        g Sn[         R                  " U[        5      nU(       d  [        R                  SU5        g Uu  pxn	US:X  a)  UR                  S5      S   n
[        U
5      nU(       d  g U
nS	U< S
U	< SU< 3n[        R                  SU5        [        X{5      nU(       d  g S n[        XU5      (       a  [        R                  SX5        g UR                  5       n[         H  u  pUR                  U5      (       d  M  Un  O   U(       d  [        R                  SUU5        g U" XW5      n[        R                  SXXSR                  U5      5        U[        :X  a  [         R                   " ["        U5        O[#        U5        SnU[        :X  a  Sn[        R                  SUX5        g )Nr   resize_rootfsT)addonsz+Skipping module named %s, resizing disabledrr   z)Could not determine filesystem type of %srR   zdev=z mnt_point=z path=zresize_info: %sz%Skip resize filesystem type %s for %sz.Not resizing unknown filesystem type %s for %szResizing %s (%s) using %s ResizedzResizing (via forking)z$%s root filesystem (type=%s, val=%s))r   get_cfg_option_strtranslate_boolNOBLOCKrX   rY   get_mount_inforZ   r#   re   r   ro   rg   RESIZE_FS_PREFIXES_CMDSrJ   joinfork_cb	do_resize)r   r   r   r   resize_rootrk   resultr)   rj   r(   r=   r\   resizerrl   pfixroot_cmd
resize_cmdactions                     r.   handler      s   1g--c?DI{G9=		?F K  c2F?M%+"Vk %S!!$+E2,2KMDII&+F9FGwV44		3W	
 	I1%%G 2
 <	

 	-JII#[388J;O g 		

 	*Fg)II.r0   c                      [         R                   " U 5        g ! [         R                   a    [        R                  " [        SU 5        e f = f)Nz$Failed to resize filesystem (cmd=%s))r   rH   r   logexcrX   )r   s    r.   r   r   K  s<    		*%% C?Ls	    2A)-__doc__rx   loggingr   r]   rv   typingr   	cloudinitr   r   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar	   cloudinit.distrosr
   cloudinit.settingsr   r   r   __annotations__	getLogger__name__rX   r/   r5   r8   r;   r?   rB   rF   rN   r   rh   strre   ro   r   listr   r   r3   r0   r.   <module>r      s1   A   	 	   + + ! # . ) )
 }!	j  !!H!'):.4
. m
K
K
K
K !"  !"67 # <M`M M6 M% Mt M M`r0   