+
    iyI                     P  a  R8 t>0 t R t^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
HtHt ^ RIHt ^ RIHt ^ RIHtHt ^ RIHtHtHtHtHt ^ RIHt ^ RIHt ^ R	IHt ^ R
I H!t!H"t" ^ RI#H$t$ ]$t%RRR]!.R]%R. /t&] ^ k RRRR.RR/t']! R4      t( ! R R4      t)]PT                  ! ]+4      t, ! R R]-4      t. ! R R]4      t/ ! R R]/4      t0 ! R  R!]/4      t1 ! R" R#]/4      t2R$ R% lt3R& R' lt4R( R) lt5R* t6R+ R, lt7R- t8R. R/ lt9R0 t:R1 R2 lt;R3 R4 lt<R5]03R6]13R7]233t=R# )9zGrowpart: Grow partitionsN)ABCabstractmethod)suppress)Path)OptionalTuple)	lifecycleperformancesubp
temp_utilsutil)Cloud)Config)
MetaSchema)ALL_DISTROSDistro)
PER_ALWAYSidcc_growpartdistros	frequencyactivate_by_schema_keysmodeautodevices/ignore_growroot_disabledFz/cc_growpart_keydatac                   &    ] tR t^/tRtRtRtRtRtR# )RESIZESKIPPEDCHANGEDNOCHANGEFAILED N)	__name__
__module____qualname____firstlineno__r   r    r!   r"   __static_attributes__r#       >/usr/lib/python3/dist-packages/cloudinit/config/cc_growpart.pyr   r   /   s    GGHFr)   r   c                       ] tR t^9tRtR# )ResizeFailedExceptionr#   N)r$   r%   r&   r'   r(   r#   r)   r*   r,   r,   9   s    r)   r,   c                   ^   a  ] tR t^=t o V 3R lR lt]V 3R lR l4       t]R 4       tRtV t	R# )Resizerc                    < V ^8  d   QhRS[ /# )   distro)r   )format__classdict__s   "r*   __annotate__Resizer.__annotate__>   s      v r)   c                    Wn         R # N_distro)selfr1   s   &&r*   __init__Resizer.__init__>   s    r)   c                &   < V ^8  d   QhRS[ RS[/# )r0   r   return)listbool)r2   r3   s   "r*   r4   r5   B   s    333$3r)   c                    R # r7   r#   r:   r   s   &&r*   	availableResizer.availableA   s    03r)   c                    R # r7   r#   )r:   diskdevpartnumpartdevfss   &&&&&r*   resizeResizer.resizeD   s    58r)   r8   N)
r$   r%   r&   r'   r;   r   rC   rJ   r(   __classdictcell__r3   s   @r*   r.   r.   =   s-       3 38 8r)   r.   c                   8   a  ] tR t^Ht o V 3R lR ltR tRtV tR# )ResizeGrowPartc                    < V ^8  d   QhRS[ /# r0   r   r?   )r2   r3   s   "r*   r4   ResizeGrowPart.__annotate__I        
 
 
r)   c                     \         P                   ! R R.RR/R7      P                  p\        P                  ! RV4      '       d   R#  R#   \         P                   d     R# i ; i)growpartz--helpLANGC
update_envz--update\s+TF)r
   stdoutresearchProcessExecutionError)r:   r   outs   && r*   rC   ResizeGrowPart.availableI   sh    	))X&FC=f  yy-- .
  )) 		s   AA
 
A#"A#c           	     n   \        W44      pV P                  P                  4       p\        P                  ! VR R7      ;_uu_ 4       p\
        P                  P                  VR4      pRRRV/p	\
        P                  P                  V4      '       g   \
        P                  ! VR4        \        P                  ! RRW.V	R7        \        P                  ! RY.T	R7        R
R
R
4       T\        Y44      3#   \        P                   dR   p
T
P                  ^8w  d*   \        P                  ! \        R	TT4       \!        T
4      T
hYU3u R
p
?
uuR
R
R
4       # R
p
?
ii ; i  \        P                   d.   p
\        P                  ! \        RY4       \!        T
4      T
hR
p
?
ii ; i  + '       g   i     L; i)T)dir	needs_exerV   rW   rX   TMPDIRi  z	--dry-runrY   z&Failed growpart --dry-run for (%s, %s)NzFailed: growpart %s %s)get_sizer9   get_tmp_exec_pathr   tempdirospathjoinexistsmkdirr
   r^   	exit_coder   logexcLOGr,   )r:   rF   rG   rH   rI   beforetmp_dirtmpdgrowpart_tmpmy_enves   &&&&&      r*   rJ   ResizeGrowPart.resizeU   s_   '& ,,002Gt<<77<<j9Lc8\:F77>>,//u-(		g?%6		:w8VL- =6 -..# -- 	(;;!#KK@	 029''' =<	( -- 6C!97L+A.A56/ =<sU   A#F$*C6E6E<EEF$EF$F!4(FF!!F$$F4	r#   Nr$   r%   r&   r'   rC   rJ   r(   rL   rM   s   @r*   rO   rO   H   s     
 
!/ !/r)   rO   c                   <   a  ] tR t^yt o RtV 3R lR ltR tRtV tR# )ResizeGrowFSa  
Use FreeBSD ``growfs`` service to grow root partition to fill available
space, optionally adding a swap partition at the end.

Note that the service file warns us that it uses ``awk(1)``, and as
such requires ``/usr`` to be present. However, cloud-init is installed
into ``/usr/local``, so we should be fine.

We invoke the ``growfs`` with ``service growfs onestart``, so it
doesn't need to be enabled in ``rc.conf``.
c                    < V ^8  d   QhRS[ /# rQ   rR   )r2   r3   s   "r*   r4   ResizeGrowFS.__annotate__   s     G G Gr)   c                \    \         P                  P                  R4      ;'       d    VR.8H  # )z'growfs only works on the root partitionz/etc/rc.d/growfsr   )rh   ri   isfilerB   s   &&r*   rC   ResizeGrowFS.available   s%    ww~~01FFg#6FFr)   c                    \        W44      p V P                  P                  R RR7       T\        Y44      3#   \        P                   d-   p\
        P                  ! \        R4       \        T4      ThRp?ii ; i)onestartgrowfs)actionservicezFailed: service growfs onestartN)	re   r9   manage_servicer
   r^   r   rn   ro   r,   )r:   rF   rG   rH   rI   rp   ru   s   &&&&&  r*   rJ   ResizeGrowFS.resize   sn    '&	2LL''z8'L
 -..	 )) 	2KK>?'*1	2s   7 A8'A33A8r#   N)	r$   r%   r&   r'   __doc__rC   rJ   r(   rL   rM   s   @r*   ry   ry   y   s      
G G/ /r)   ry   c                   8   a  ] tR t^t o V 3R lR ltR tRtV tR# )ResizeGpartc                    < V ^8  d   QhRS[ /# rQ   rR   )r2   r3   s   "r*   r4   ResizeGpart.__annotate__   rT   r)   c                     \         P                   ! R R.RR/^ ^.R7      P                  p\        P                  ! RV4      '       d   R#  R#   \         P                   d     R# i ; i)gparthelprW   rX   )rZ   rcszgpart recover TF)r
   stderrr\   r]   r^   )r:   r   errs   && r*   rC   ResizeGpart.available   so    	))&!vsm!Qf  yy*C00 1
  )) 		s   AA A&%A&c                    \         P                   ! RRV.4       \        W44      p \         P                   ! RRRW!.4       T\        Y44      3#   \         P                   dD   pTP                  ^ 8w  d)   \        P                  ! \
        RT4       \        T4      Th Rp?LRp?ii ; i  \         P                   d.   p\        P                  ! \
        RY!4       \        T4      ThRp?ii ; i)a	  
GPT disks store metadata at the beginning (primary) and at the
end (secondary) of the disk. When launching an image with a
larger disk compared to the original image, the secondary copy
is lost. Thus, the metadata will be marked CORRUPT, and need to
be recovered.
r   recoverzFailed: gpart recover %sNrJ   z-izFailed: gpart resize -i %s %s)r
   r^   rm   r   rn   ro   r,   re   )r:   rF   rG   rH   rI   ru   rp   s   &&&&&  r*   rJ   ResizeGpart.resize   s    	6IIw	734 '&	2IIw$AB
 -.. )) 	6{{aC!;WE+A.A5  	6 )) 	2KK<gO'*1	2s.   A B) B&#9B!!B&)C+>(C&&C+r#   Nrw   rM   s   @r*   r   r      s     
 
/ /r)   r   c                H    V ^8  d   QhR\         R\        R\        R\        /# )r0   r   r1   r   r>   )strr   r?   r.   )r2   s   "r*   r4   r4      s(      # v   r)   c                    R pV R8X  dJ   \          F)  w  rEV! V4      pVP                  VR7      '       g   K'  Tp M	  V'       g   \        R4      h V# / p\          F	  w  rWV&   K  	  W9  d   \        RV ,          4      hWp,          ! V4      p
V
P                  VR7      '       d   T
pV'       g   \        RV ,          4      hV# )Nr   )r   zNo resizers availablezunknown resize mode %szmode %s not available)RESIZERSrC   
ValueError	TypeError)r   r1   r   resize_class_nameresizercurmmapkvmclasss   &&&        r*   resizer_factoryr      s    Lv~&NE&/C}}W}--"	 ' 455 $  DAG  4t;<<F#G,,!L4t;<<r)   c                :    V ^8  d   QhR\         \        ,          /# r0   r>   r   int)r2   s   "r*   r4   r4      s      hsm r)   c                    R p \         P                  ! V \         P                  4      p\         P                  ! V^ \         P                  4      V'       d   \         P
                  ! V4       # #   \         dX    TR8X  d-   \        T 4      u T'       d   \         P
                  ! T4       # #  T'       d   \         P
                  ! T4       R # R # i ; i  T'       d   \         P
                  ! T4       i i ; i)Nzfs)rh   openO_RDONLYlseekSEEK_ENDcloseFileNotFoundErrorget_zfs_size)filenamerI   fds   && r*   re   re      s    	B	WWXr{{+xxAr{{+ HHRL   ;)) HHRL  HHRL 
 HHRL s*   A
A. .CC ,C CC !C4c                :    V ^8  d   QhR\         \        ,          /# r   r   )r2   s   "r*   r4   r4      s      Xc] r)   c                    V P                  R 4      ^ ,          p \        P                  ! RRRRV.4      w  r#\        TP                  4       4      #   \        P                   d"   p\        P	                  RY4        Rp?R# Rp?ii ; i)r   zpoolgetz	-HpovaluesizezFailed: zpool get size %s: %sN)splitr
   r^   ro   debugr   strip)datasetr   r   _ru   s   &    r*   r   r      sr    MM#q!E))We[&%HI tzz| %% 		15<s   A B%BBc                    V P                  R 4      '       d   V R3# \        P                  ! V 4      pV'       g   \        R4      hV^ ,          pV^,          p\        P                  ! 4       pVR8X  dj   V'       gb   \        P
                  ! \        P                  ! 4       4      pVf5   \        P                  P                  V4      '       d   VR3# \        R4      hW#3# )/dev/Nz,Could not determine device of '%s' % dev_entz	/dev/rootz!Unable to find device '/dev/root')

startswithr   get_mount_infor   is_containerrootdev_from_cmdlineget_cmdlinerh   ri   rk   )deventresultdevrI   	containers   &    r*   
devent2devr      s    !!t|  (FGHH
)C	B!!#I k)''(8(8(:;;ww~~c"" Dy @AA7Nr)   c                $    V ^8  d   QhR\         /# r   )r@   )r2   s   "r*   r4   r4   	  s       r)   c                R   \         P                  ! R4      '       g   \        P                  R4       R#  \         P                   ! RRV .4       \        \         P                  4      ;_uu_ 4        \         P                   ! RRT.4       \        P                  R	T 4        RRR4       R
#   \         P                   dT   pTP
                  ^8X  d   \        P                  RT 4       M \        P                  RTP
                  4        Rp?R# Rp?ii ; i  + '       g   i     R# ; i)z
Check if a device is an encrypted device. blockdev should have
a /dev/dm-* path whereas partition is something like /dev/sda1.

cryptsetupz6cryptsetup not found. Assuming no encrypted partitionsFstatusz#Determined that %s is not encryptedzZReceived unexpected exit code %s from cryptsetup status. Assuming no encrypted partitions.NisLukszDetermined that %s is encryptedT)r
   whichro   r   r^   rm   warningr   )blockdev	partitionru   s   && r*   is_encryptedr   	  s    
 ::l##		JK		<845 
$,,	-	-		<956		3X> 
.	- %% 	;;!II;XFKKG
 	 
.	- s$   B* /1D*D?ADDD&	c                 B   R RRV .p\         P                   ! V4      ^ ,          pVP                  R4      '       g   \        RV 24      h RVP                  R4      ^,          P                  R4      ^ ,           2#   \         d   p\        RT R	T R
24      ThRp?ii ; i)dmsetupdepsz--options=devnamez1 dependz5Expecting '1 dependencies' from 'dmsetup'. Received: r   z: ()zRan `z$`, but received unexpected stdout: ``N)r
   r   RuntimeErrorr   
IndexError)r   commanddepru   s   &   r*   get_underlying_partitionr   $  s    &"5x@Gyy!!$C >>*%%CC5I
 	
syy'*005a89:: G9@QG
	s   
0A; ;BBBc                F    V ^8  d   QhR\         \        \        3,          /# r   )r   r   )r2   s   "r*   r4   r4   5  s     6 6U38_ 6r)   c                   \         P                  4       '       g   \        P                  R3#  \        P
                  ! R\          24      ;_uu_ 4        \         P                  4       ;_uu_ 4       p\        P                  ! V4      pRRR4       RRR4       XR,          p\        P                  ! V4      pVR,          p \        P                  ! RRR	R
T .TR7        \        P                  ! RRRT\        T4      .4        \         P%                  4        \        P*                  RT  R23#   + '       g   i     L; i  + '       g   i     L; i  \         d   p\        R4      ThRp?ii ; i  \        P                   d!   p\         P#                  RT4        Rp?LRp?ii ; i  \         d    \&        P(                  ! \         R4        Li ; i   \        P                  ! RRRT\        T4      .4       M8  \        P                   d!   p\         P#                  RT4        Rp?MRp?ii ; i \         P%                  4        i   \         d    \&        P(                  ! \         R4        i i ; i; i)zUse 'cryptsetup resize' to resize LUKS volume.

The loaded keyfile is json formatted with 'key' and 'slot' keys.
key is base64 encoded. Example:
{"key":"XFmCwX2FHIQp0LBWaLEMiHIyfxt1SGm16VvUAVledlY=","slot":5}
zNo encryption keyfile foundzReading NkeyslotzZCould not load encryption key. This is expected if the volume has been previously resized.r   z
--key-file-rJ   )dataluksKillSlotz--batch-modez<Failed to kill luks slot after resizing encrypted volume: %sz8Failed to remove keyfile after resizing encrypted volumez'Successfully resized encrypted volume '')KEYDATA_PATHrk   r   r   r	   Timedr   jsonloadbase64	b64decode	Exceptionr   r
   r   r^   ro   r   unlinkr   rn   r    )r   r   fkeydatar   decoded_keyr   ru   s   &&      r*   resize_encryptedr   5  s#       =>>|n%
 
!iilG 
 en&&s+v		<hA	

	II ""I	! 	
1(1= O 
 
  6
 	, )) 	KKN 	  	KKO	#	II ""I )) 	KKN 	
	! 	KKO	s   %E E 0D-	E 0E  G $E2 F* -D=8E  E	E E/E**E/2F'F""F'*&GGI7$G=<I7=H2H-(I7-H22I76I
I7&I41I73I44I7c                 Z   . p V P                  W#WE4      w  rxWx8X  d.   VP                  V\        P                  R V: RV: R234       V# Ve   VfD   Rp	Ve   Vf   RV: RV: R2p	M	RV,          p	VP                  V\        P                  V	34       V# Rp	Ve   Vf   RV: RV: RV: R	V: 2p	MRV: RV: R	V: 2p	VP                  V\        P                  V	34        V#   \
         d:   p
TP                  T\        P                  R
T: RT: RT
: 234        Rp
?
T# Rp
?
ii ; i)zno change necessary (z, r   N z	changed (z) size, new size is unknownz&changed (%s) size, new size is unknownz) from z to zfailed to resize: disk=z, ptnum=z: )rJ   appendr   r!   r    r,   r"   )r   r   diskptnumr   rI   infooldnewmsgru   s   &&&&&&     r*   _call_resizerr   n  s3   D(
>>$x<:KKOO6:EBL K? [CKCEM
 ?IKK56, K) CEM	 7?SIKK56 K ! 
=A5!L	
 	
 K
s&   AC& A	C& AC& &D*1.D%%D*c                0    V ^8  d   QhR\         R\        /# )r0   r   r1   )r.   r   )r2   s   "r*   r4   r4     s     q qG qf qr)   c           	      J   \         P                   ! V4      p. pV'       Ed   VP                  ^ 4      pRpRp \        V4      w  rx\        P                  RT4       TR8X  d-   \        T \        4      '       d   T\        YYVYx4      ,          pKu   \        P                  ! T4      p
\        P                  ! T
P                   4      '       gS   \        P"                  ! T
P                   4      '       g-   TP	                  T\
        P                  RT,          34       EK  TP%                  T4      pT'       d    \'        T4      p\)        Y4      '       df   Y Uu. uF  q^ ,          NK  	  up9  d(   TP+                  ^ T4       TP+                  ^ T4       EK}  \-        Y|4      w  rTP	                  TTT34       M'TP	                  T\
        P                  RT R	234        EK   TP3                  T4      w  rVT\        YYVYx4      ,          pEK  V#   \         d6   p	TP	                  T\
        P                  RT	,          34        Rp	?	EK1  Rp	?	ii ; i  \         d7   p	TP	                  T\
        P                  RT: RT	: 234        Rp	?	EKu  Rp	?	ii ; iu upi   \.         d3   p	TP	                  T\
        P0                  R
T RT	 234        Rp	?	LRp	?	ii ; i  \4        \        3 d7   p	TP	                  T\
        P                  RT: RT	: 234        Rp	?	EK  Rp	?	ii ; i)    Nzunable to convert to device: %szgrowpart found fs=%sr   z	stat of 'z
' failed: zdevice '%s' not a block devicezResizing mapped device (z!) skipped as it is not encrypted.zResizing encrypted device (z
) failed: zdevice_part_info()copypopr   r   r   r   r   ro   r   
isinstancery   r   rh   statOSErrorS_ISBLKst_modeS_ISCHRget_mapped_devicer   r   insertr   r   r"   device_part_infor   )r   r   r1   r   r   r   r   r   rI   ru   statretunderlying_blockdevr   xr   messages   &&&             r*   resize_devicesr    s   ii GD
'Q
	%f-LH 			("- ;:g|<<M'4MMD
	ggh'G ||GOO,,T\\OO6
 6
 KKNN4x? $66x@%4X>	 3?? t(<t!1t(<<  q&1q)4 &6x&KOFKK""# KK""NN6xj A6 6$ 
	 11(;KD 	gtHIIKK  	KKNN59 	,  	KKNN191= 	8 )=4  5hZz!M  :& 	KKNN9A1E 	s}   H I 7 J J(+J !J 8&J #K I)I

IJ*JJJ K&(KKL",*LL"c          
      L    V ^8  d   QhR\         R\        R\        R\        RR/# )r0   namecfgcloudargsr>   N)r   r   r   r?   )r2   s   "r*   r4   r4     s/     09 09 096 09% 09t 09 09r)   c                    R V9  d$   \         P                  R\        4       \        VR &   VP                  R 4      p\	        V\
        4      '       g   \         P                  R4       R# VP                  RR4      p\        P                  ! V4      '       d=   VR8w  d   \        P                  ! RV R2R	R
R7       \         P                  RV4       R# \        P                  ! VP                  RR4      4      '       dR   \        P                  P                  R4      '       d-   \         P                  R4       \         P                  R4       R# \        P                  ! VRR.4      p\        V4      '       g   \         P                  R4       R#  \!        WRP"                  VR7      p\(        P*                  ! R4      ;_uu_ 4        \-        YvTP"                  4      p	RRR4       X	 FJ  w  rpT\.        P0                  8X  d   \         P3                  RY4       K3  \         P                  RYT4       KL  	  R#   \$        \&        3 d+   p\         P                  RYX4       TR8w  d   Th Rp?R# Rp?ii ; i  + '       g   i     L; i)rV   z.No 'growpart' entry in cfg.  Using default: %sz#'growpart' in config was not a dictNr   r   offz"Growpart's 'mode' key with value 'r   z22.2zUse 'off' instead.)
deprecateddeprecated_versionextra_messagezgrowpart disabled: mode=%sr   Fz/etc/growroot-disabledz0growpart disabled: /etc/growroot-disabled existsz&use ignore_growroot_disabled to ignorer   r   zgrowpart: empty device list)r1   r   z,growpart unable to find resizer for '%s': %szResizing devicesz'%s' resized: %sz'%s' %s: %s)ro   r   DEFAULT_CONFIGr   r   dictr   r   is_falser   	deprecaterh   ri   r}   get_cfg_option_listlenr   r1   r   r   r	   r   r  r   r    r   )r  r  r  r  mycfgr   r   r   ru   resizedentryr   r   s   &&&&         r*   handler!    s   		<n	
 )JGGJEeT""9:99VV$D}}T5=?vQG#)2
 			.5}}UYY95ABB77>>233IIHIII>?&&ui#?Gw<<		/0!$||WM 
		-	.	. 5<<@ 
/%sV^^#HH'4IImUC8	 & 	" 		@$J6>G	 
/	.s$   H8 I68I3	I..I36J	rV   r   r   c                @    V ^8  d   Qh/ ^ \         9   d
   \        ;R&   # )r0   meta)__conditional_annotations__r   )r2   s   "r*   r4   r4      s      . j /  r)   )?r$  r   r   r   r   loggingrh   os.pathr\   r  abcr   r   
contextlibr   pathlibr   typingr   r   	cloudinitr   r	   r
   r   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.distrosr   r   cloudinit.settingsr   r   r#  r  r   r   	getLoggerr$   ro   r   r,   r.   rO   ry   r   r   re   r   r   r   r   r   r   r  r!  r   r4   )r$  s   @r*   <module>r2     sD         	  	  #   " D D ! # . 1 )	-}r	  Fu *+  !	I 	9c 9./W ./b/7 /8#/' #/L<06"6r+\qh09h  |kr)   