U '¡DgŠ*ã@sjUdZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z ddl m Z ddlmZddlmZddlmZdd lmZd Zd egegd œZeed <e e¡Zdd„Zdd„Zdd„Zdd„Zdd„Z dd„Z!dd„Z"dd„Z#defdefd efd!efd"e fd#e!fd$e"fgZ$d!e#iZ%ee&d%œd&d'„Z'd(d)„Z(d*d+„Z)e&ee e*dd,œd-d.„Z+d/d0„Z,dS)1z:Resizefs: cloud-config module which resizes the filesysteméN)ÚOptional)Ú lifecycleÚsubpÚutil)ÚCloud)ÚConfig)Ú MetaSchema)Ú ALL_DISTROS)Ú PER_ALWAYSZnoblockZ cc_resizefs)ÚidZdistrosZ frequencyZactivate_by_schema_keysÚmetacCs¢t |¡s.tj d|¡r.ddddd|g}ndddd|g}tj d¡}tj t ddg¡j   d¡d   d ¡d   ¡¡}||krš|  d¡}|  |d d ¡t|ƒS)Nz %s/.snapshotsÚbtrfsZ filesystemÚresizeÚmaxz5.10z --versionÚ rÚvéÿÿÿÿéz --enqueue)rZmount_is_read_writeÚosÚpathÚisdirrZVersionZfrom_strrÚstdoutÚsplitÚstripÚindexÚinsertÚtuple)Ú mount_pointÚdevpthÚcmdZbtrfs_with_queueZsystem_btrfs_verÚidx©r!ú>/usr/lib/python3/dist-packages/cloudinit/config/cc_resizefs.pyÚ _resize_btrfs%s4ÿû ÿÿþþÿ r#cCsd|fS)NZ resize2fsr!©rrr!r!r"Ú _resize_extIsr%cCsd|fS)NZ xfs_growfsr!r$r!r!r"Ú _resize_xfsMsr&cCs dd|fS)NÚgrowfsz-yr!r$r!r!r"Ú _resize_ufsQsr(cCsddd||fS)NÚzpoolZonlinez-er!r$r!r!r"Ú _resize_zfsUsr*cCs dd|fS)NÚhammer2r'r!r$r!r!r"Ú_resize_hammer2Ysr,cCs ddd|fS)zSingle device resizeÚbcachefsZdevicerr!r$r!r!r"Ú_resize_bcachefs]sr.c Csjd}d}zt dd|g¡WnHtjk rd}z(|j |¡rP||jkrPWY¢ dS|‚W5d}~XYnXdS)Nzgrowfs: requested sizez.is not larger than the current filesystem sizer'z-NTF)rÚProcessExecutionErrorÚstderrÚ startswith)rrZ skip_startZ skip_containÚer!r!r"Ú_can_skip_resize_ufsbs r3r ZextZxfsZufsÚzfsr+r-)Úreturnc Csút ¡rtjntj}tj d¡s.t d¡dSz0t dd|g¡\}}|r\t  d||¡WdSWn6tj k r”}z|d||ƒWY¢dSd}~XYnXd}|  d¡D]B}t   ||¡r¤||kr¤d |kr¤|  ¡d }t d ||¡|Sq¤|d |||ƒdS) Nz/dev/zfsz"Cannot get zpool info, no /dev/zfsr)Zstatusz0zpool status returned error: [%s] for zpool [%s]z$Unable to get zpool status of %s: %sz .*(ONLINE).*rÚstaterzfound zpool "%s" on disk %sz'No zpool found: [%s]: out: [%s] err: %s)rÚ is_containerÚLOGÚdebugÚwarningrrÚexistsrÚinfor/rÚreÚsearch)r)Zlog_warnZ zpoolstatusÚerrÚrÚlineZdiskr!r!r"Úget_device_info_from_zpool…s:  ý    ÿrBcCs6| ¡}t ¡D] \}}| |¡r|||ƒSqdS)NF)ÚlowerÚRESIZE_FS_PRECHECK_CMDSÚitemsr1)Úfs_typeÚ resize_whatrÚ fstype_lcÚiÚfuncr!r!r"Úcan_skip_resize£s  rKc Cs|t ¡}|dkrPtj |¡sP|sPt t ¡¡}|dkrDt d¡dSt  d|¡|dkrjt  d||¡dS|  d¡r‚t  d¡|S|  d ¡s¸tj |¡s¸d |  d ¡}t  d ||¡|}zt  |¡}Wnlt k r2}zL|rú|jtjkrút  d ||¡n"|jtjkrt d ||¡n|‚WY¢dSd}~XYnXt  |j¡sxt  |j¡sx|rft  d||¡nt d||¡dS|S)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 cmdlineZ overlayrootz)Not attempting to resize devpath '%s': %szgpt/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)rr7rrr;Zrootdev_from_cmdlineZ get_cmdliner8r:r9r1ÚlstripÚstatÚOSErrorÚerrnoZENOENTÚS_ISBLKÚst_modeÚS_ISCHR)Zdevpathr<Z containerZ fulldevpathZstatretÚexcr!r!r"Úmaybe_get_writable_device_path«sr ÿ þý    ýýÿüýrU)ÚnameÚcfgÚcloudÚargsr5cCs’t|ƒdkr|d}nt |dd¡}tj|tgdsDt d|¡dSd}t |t¡}|sht d|¡dS|\}}} |dkrœ|  d¡d} t | ƒ}|s˜dS| }d || |f} t d | ¡t || ƒ}|sÈdSd} t |||ƒrêt d ||¡dS|  ¡} tD]\}}|  |¡rö|} qqö| s,t d ||¡dS| ||ƒ}t d ||d |¡¡|tkrdt t|¡nt|ƒd}|tkr~d}t d|||¡dS)NrZ resize_rootfsT)Zaddonsz+Skipping module named %s, resizing disabledrLz)Could not determine filesystem type of %sr4zdev=%s mnt_point=%s path=%szresize_info: %sz%Skip resize filesystem type %s for %sz.Not resizing unknown filesystem type %s for %szResizing %s (%s) using %sú ZResizedzResizing (via forking)z$%s root filesystem (type=%s, val=%s))ÚlenrZget_cfg_option_strZtranslate_boolÚNOBLOCKr8r9Zget_mount_infor:rrBrUrKrCÚRESIZE_FS_PREFIXES_CMDSr1ÚjoinZfork_cbÚ do_resize)rVrWrXrYZ resize_rootrGÚresultrrFrr)r<ZresizerrHZpfixZroot_cmdÚ resize_cmdÚactionr!r!r"Úhandleûs‚         ÿ  ý ÿ þ ÿrccCs:zt |¡Wn&tjk r4t td|¡‚YnXdS)Nz$Failed to resize filesystem (cmd=%s))rr/rZlogexcr8)rar!r!r"r_Ks r_)-Ú__doc__rPZloggingrr=rNÚtypingrZ cloudinitrrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarZcloudinit.distrosr Zcloudinit.settingsr r\r Ú__annotations__Z getLoggerÚ__name__r8r#r%r&r(r*r,r.r3r]rDÚstrrBrKrUÚlistrcr_r!r!r!r"Ú sR      ü $ù PP