flZ UdZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z m Z ddl m Z ddlmZddlmZddlmZmZddlmZmZmZdd lmZdd lmZdd lmZmZdd l m!Z!m"Z"dd l#m$Z$dZ%e$Z&ddde%e!ge&ededggdZ'ee(d<ee'ZddgddZ)edZ*GddZ+ejXe-Z.de/de"de0fd Z1Gd!d"e2Z3Gd#d$e Z4Gd%d&e4Z5Gd'd(e4Z6Gd)d*e4Z7d+ee8fd,Z9d-Z:d.Z;d/Zd1Z?d+ee/e/ffd2Z@d3ZAd4e/d5ed6ed7e0d+df d8ZBd9e5fd:e6fd;e7ffZCy)/usr/lib/python3/dist-packages/cloudinit/config/cc_growpart.pyr%r%osGGH Fr.r%r!distror"c6d}|dk(r;tD]#\}}||}|j|s!|}n|s td|Si}tD] \}} | ||< ||vrtd|z|||} | j|r| }|std|z|S)Nr)r"zNo resizers availablezunknown resize mode %szmode %s not available)RESIZERS available ValueError TypeError) r!r0r" resize_class_nameresizercurmmapkvmclasss r/resizer_factoryr>ysL v~& NE7&/C}}W}-"    45 5"  DAqDG  t 4t;< <dF#   G  ,!L4t;< < r.c eZdZy)ResizeFailedExceptionN)r*r+r,r-r.r/r@r@sr.r@cBeZdZdefdZededefdZedZ y)Resizerr0c||_yN)_distro)selfr0s r/__init__zResizer.__init__s  r.r"returncyrDr-rFr"s r/r3zResizer.available r.cyrDr-)rFdiskdevpartnumpartdevs r/resizezResizer.resizerKr.N) r*r+r,rrGrlistboolr3rPr-r.r/rBrBsDv  $    r.rBceZdZdefdZdZy)ResizeGrowPartr"c tjddgddij}tjd|ry y#tj$rYywxYw) Ngrowpartz--helpLANGC update_envz --update\s+TF)r stdoutresearchProcessExecutionError)rFr"outs r/r3zResizeGrowPart.availablese ))X&FC=f yy-. ))   s;AAAc0t|}|jj}tj|d5}t j j|d}d|d}t j j|st j|d tjdd||g| tjd||g| ddd|t|fS#tj$rN} | jd k7r(tjtd ||t!| | ||fcYd} ~ cdddSd} ~ wwxYw#tj$r-} tjtd ||t!| | d} ~ wwxYw#1swYxYw) NT)dir needs_exerVrX)rWTMPDIRiz --dry-runrYz&Failed growpart --dry-run for (%s, %s)zFailed: growpart %s %s)get_sizerEget_tmp_exec_pathr tempdirospathjoinexistsmkdirr r^ exit_coder logexcLOGr@) rFrMrNrObeforetmp_dirtmpd growpart_tmpmy_enves r/rPzResizeGrowPart.resizesf'",,002   Gt < 677<<j9L!\:F77>>,/u- ( gw?% 6 :w8VL- 66)**#-- (;;!#KK@  029''' 6 6 (-- 6 C!97GL+A.A5 6/ 6 6sTAF C%5E %E8:E2E3F EF  F (FF  F  FNr*r+r,rQr3rPr-r.r/rTrTs  !+r.rTc"eZdZdZdefdZdZy) 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``. r"cPtjjdxr|dgk(S)z'growfs only works on the root partitionz/etc/rc.d/growfsr )rhriisfilerJs r/r3zResizeGrowFS.availables"ww~~01Fg#6FFr.ct|} |jjdd|t|fS#tj$r+}t j tdt||d}~wwxYw)Nonestartgrowfs)actionservicezFailed: service growfs onestart) rerEmanage_servicer r^r rnror@)rFrMrNrOrprus r/rPzResizeGrowFS.resizesn'" 2 LL ' 'z8 ' L )** )) 2 KK> ?'* 1 2s7A5 &A00A5N)r*r+r,__doc__rQr3rPr-r.r/rxrxs GG+r.rxceZdZdefdZdZy) ResizeGpartr"c tjddgddiddgj}tjd|ry y #tj$rYy wxYw) NgparthelprWrXrrd)rZrcszgpart recover TF)r stderrr\r]r^)rFr"errs r/r3zResizeGpart.availablesl ))&!vsm!Qf yy*C01 ))   s>AAAc tjdd|gt|} tjddd||g|t|fS#tj$r@}|jdk7r'tjt d|t ||Yd}~d}~wwxYw#tj$r-}tjt d||t ||d}~wwxYw) a9 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. rrecoverrzFailed: gpart recover %sNrPz-izFailed: gpart resize -i %s %s)r r^rmr rnror@re)rFrMrNrOrurps r/rPzResizeGpart.resizes 6 IIw 73 4 '" 2 IIw$A B )**)) 6{{a C!;WE+A.A5  6)) 2 KK/dev/.+)[sp](?P\d+[a-z]*)$dev part_slicez had no syspath () partitionz%s not a partitionz /dev/block/%s)rhrirealpathbasenamer is_BSDfind_freebsd_partr\r]rkr4rjr5load_text_filerstripdirname) devpathrpathbnamesyspathfpartmptpathptnumrsyspath disksyspath diskmajmin diskdevpaths r/device_part_infor'se GG  W %E GG  U #E#e+G {{}$0099 II >  U8Q|_, , 77>>' "WgFGG WW\\'; /F 77>>& !,w677    ' . . 0Eww(H''//(+K$$RWW\\+u%EFMMOJ''""?Z#?@K  r.cZ|jdr|Stj|}|s td|d}tj}|dk(rW|sUtj tj }|,tjj|r|Std|S)Nrz,Could not determine device of '%s' % dev_entrz /dev/rootz!Unable to find device '/dev/root') startswithr get_mount_infor4 is_containerrootdev_from_cmdline get_cmdlinerhrirk)deventresultr containers r/ devent2devrRs ! $$V,KL LQi!!#I k)''(8(8(:; ;ww~~c" @A A Jr.ctjj|}|dk(r|jdrtjtj |j }tjtj |j }tjd5}|D]}|jjds tj|j}t j|js_tjtj |jj |k(stjtj |jj |k(stjj|j}nddd|jdrtjd|||Sy#1swY4xYw)aReturns underlying block device for a mapped device. If it is mapped, blockdev will usually take the form of /dev/mapper/some_name If blockdev is a symlink pointing to a /dev/dm-* device, return the device pointed to. Otherwise, return None. alpinez /dev/mapperrzdm-Nz/dev/dm-z$%s is a mapped device pointing to %s)rhrirrmajorstatst_rdevminorscandirrlstatS_ISBLKst_moderodebug)blockdev distro_namerrritdeventryress r/get_mapped_devicerisfww)Hh   } - HHRWWX.667EHHRWWX.667EG$ & " &H}}//6 hhx}}5<< 4 ")?)G)G H#(!)$&HHRWWX]]-C-K-K$L#(%),.77+;+;HMM+J % & &:& 8(HM # & &s$1"G2>G2?G2?G2,G22G;ctjdstjdy tjdd|gttj5tjdd |gtjd | dddy #tj$rP}|j dk(rtjd|n tj d|j Yd}~yd}~wwxYw#1swYyxYw) 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 partitionsFstatusz#Determined that %s is not encryptedzZReceived unexpected exit code %s from cryptsetup status. Assuming no encrypted partitions.NisLukszDetermined that %s is encryptedT)r whichrorr^rmwarningr)rrrus r/ is_encryptedrs ::l # JK  <845 $,, - <956 3X>  % %  ;;!  II;X F KKG     s$B0C=C:*AC55C:=Dcddd|g}tj|d}|jdstd| d|jdd jd dS#t$r}td |d |d |d}~wwxYw)Ndmsetupdepsz--options=devnamerz1 dependz5Expecting '1 dependencies' from 'dmsetup'. Received: rz: (rdrzRan `z$`, but received unexpected stdout: ``)r r RuntimeErrorsplit IndexError)rcommanddeprus r/get_underlying_partitionrs&"5x@Gyy!!$C >>* %CC5 I  syy'*005a89:: G9@Q G  s(A(( B 1BB c tjstjdfS tj 5}t j |}dddd}tj|}|d} tjdddd |g|  tjdd d |t|g tj!tj&d|dfS#1swYxYw#t$r}td|d}~wwxYw#tj$r }tjd |Yd}~d}~wwxYw#t$rt#j$tdYwxYw# tjdd d |t|gn6#tj$r }tjd |Yd}~nd}~wwxYw tj!w#t$rt#j$tdYwwxYwxYw)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} zNo encryption keyfile foundNkeyslotzZCould not load encryption key. This is expected if the volume has been previously resized.rz --key-file-rP)data luksKillSlotz --batch-modez>      #AiilG #en&&s+ v <h A   II ""I       !  1(1= O # #  6  ,))  KKN     KKO  #  II ""I  ))  KKN         !  KKO  sC1C%'C1:E-#D;E%C.*C11 D : DD E!D<<E#E*)E*-H/#FHG&G<HGH GH#HHHHc tj|}g}|r|jd} t|} tj|}tj|jsEtj|js&|j |t j d|zft||}|r t|} t|| r^| |D cgc]} | d c} vr%|j!d||j!d| t#|| \} } |j || | fn&|j |t j d|dfF t)|\} } |j-| ||\}}||k(r*|j |t j.d | d |d fn\||*|j |t j0d| d |dfn.|j |t j0d| d |d|d|f|r|S#t$r0}|j |t j d|zfYd}~1d}~wwxYw#t$r3}|j |t j d|d|fYd}~pd}~wwxYwcc} w#t$$r3}|j |t j&d|d |fYd}~pd}~wwxYw#t*tf$r3}|j |t j d |d |fYd}~d}~wwxYw#t2$r6}|j |t j&d| d|d|fYd}~Dd}~wwxYw)Nrzunable to convert to device: %sz stat of 'z ' failed: zdevice '%s' not a block devicezResizing mapped device (z!) skipped as it is not encrypted.zResizing encrypted device (z ) failed: zdevice_part_info(zno change necessary (z, rz changed (z) size, new size is unknownz) from z to zfailed to resize: disk=z, ptnum=z: )copypoprr4appendr%r&rhrOSErrorrrS_ISCHRrrrinsertrrr)rr5rPr(r'r@)r8r"rinforrrustatretunderlying_blockdevrxrmessagediskroldnews r/resize_devicesrsLii G D Q !&)H ggh'G||GOO,T\\ OO6  KKNN4x?  /+F % 4X>  3Y? t(F  ( S2c H KA  KKNN59     KKNN191=   8)=4   5hZz!M :&  KKNN9A1E   N%  KKMMUA'   s HIJ J)(JA JK.B!L I%I  I J (JJ J K(K  KL#(LL M"+MMrcfgcloudargscd|vr#tjdtt|d<|jd}t |t stj dy|jdd}tj|r4|dk7rtjddd tjd |ytj|jd d rJtjjdr+tjdtjdytj|ddg}t|stjdy t||j |}tj&tjdt(|||j j*f} | D]I\} } } | t,j.k(rtj1d| | 2tjd| | | Ky#t"t$f$r(}tjd|||dk7r|Yd}~yd}~wwxYw)NrVz.No 'growpart' entry in cfg. Using default: %sz#'growpart' in config was not a dictr!roffz)Growpart's 'mode' key with value '{mode}'z22.2zUse 'off' instead.) deprecateddeprecated_version extra_messagezgrowpart disabled: mode=%sr#Fz/etc/growroot-disabledz0growpart disabled: /etc/growroot-disabled existsz&use ignore_growroot_disabled to ignorer"r zgrowpart: empty device list)r0r"z,growpart unable to find resizer for '%s': %sr)logfuncmsgfuncrz'%s' resized: %sz '%s' %s: %s)rorDEFAULT_CONFIGget isinstancedictrr is_false deprecaterhrirzget_cfg_option_listlenr>r0r4r5log_timerrr%r'r) rrrrmycfgr!r"r8ruresizedentryr~rs r/handlers >2 3 IIH I II> ? &&ui#?G w< /0!$u||WMmm  w 1 1 2 G &9vs V^^ # HH' 4 IImUFC 8 9  " @$J 6>G s#H IH>>IrVr}r)Drrrrloggingrhos.pathr\rabcrr contextlibrpathlibrtextwraprtypingrr cloudinitr r r cloudinit.cloudr cloudinit.configrcloudinit.config.schemarrcloudinit.distrosrrcloudinit.settingsrMODULE_DESCRIPTIONrr__annotations__r rr% getLoggerr*rorrQr>rr@rBrTrxrintrerrrrRrrrrrr2r-r.r/r(s   #",,!#<1)%L    %}     ( "7j< t  u % *+ g!#v< I   c  .+W.+b+7+8#+'#+L (3- ( V.'T6"4U38_4nIX4949649%49t4949p  | k r.