3 \�me"T � @ s* U d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl m Z mZ ddlm Z ddlmZ ddlmZ ddlmZ ddlmZmZmZ dd lmZ dd lmZ ddlmZmZ ddlm Z m!Z! dd l"m#Z# dZ$e#Z%ddde$e ge%ed�ed�gg d�Z&e&ee&�Z ddgdd�Z'ed�Z(G dd� d�Z)ej*e+�Z,e-e!e.d�dd�Z/G dd � d e0�Z1G d!d"� d"e �Z2G d#d$� d$e2�Z3G d%d&� d&e2�Z4G d'd(� d(e2�Z5d)d*� Z6d+d,� Z7d-d.� Z8d/d0� Z9e:d1�d2d3�Z;d4d5� Z<ee-e-f d1�d6d7�Z=d8d9� Z>e-eee.dd:�d;d<�Z?d=e3fd>e4fd?e5ffZ@dS )@zGrowpart: Grow partitions� N)�ABC�abstractmethod)�suppress)�Path)�dedent)�Tuple)�subp� temp_utils�util)�Cloud)�Config)� MetaSchema�get_meta_doc)�ALL_DISTROS�Distro)� PER_ALWAYSa6 Growpart resizes partitions to fill the available disk space. This is useful for cloud instances with a larger amount of disk space available than the pristine image uses, as it allows the instance to automatically make use of the extra space. Note that this only works if the partition to be resized is the last one on a disk with classic partitioning scheme (MBR, BSD, GPT). LVM, Btrfs and ZFS have no such restrictions. The devices on which to run growpart are specified as a list under the ``devices`` key. There is some functionality overlap between this module and the ``growroot`` functionality of ``cloud-initramfs-tools``. However, there are some situations where one tool is able to function and the other is not. The default configuration for both should work for most cloud instances. To explicitly prevent ``cloud-initramfs-tools`` from running ``growroot``, the file ``/etc/growroot-disabled`` can be created. By default, both ``growroot`` and ``cc_growpart`` will check for the existence of this file and will not run if it is present. However, this file can be ignored for ``cc_growpart`` by setting ``ignore_growroot_disabled`` to ``true``. For more information on ``cloud-initramfs-tools`` see: https://launchpad.net/cloud-initramfs-tools On FreeBSD, there is also the ``growfs`` service, which has a lot of overlap with ``cc_growpart`` and ``cc_resizefs``, but only works on the root partition. In that configuration, we use it, otherwise, we fall back to ``gpart``. Note however, that ``growfs`` may insert a swap partition, if none is present, unless instructed not to via ``growfs_swap_size=0`` in either ``kenv(1)``, or ``rc.conf(5)``. Growpart is enabled by default on the root partition. The default config for growpart is:: growpart: mode: auto devices: ["/"] ignore_growroot_disabled: false Zcc_growpartZGrowpartzGrow partitionsz� growpart: mode: auto devices: ["/"] ignore_growroot_disabled: false z� growpart: mode: growpart devices: - "/" - "/dev/vdb1" ignore_growroot_disabled: true )�id�name�title�descriptionZdistros� frequencyZexamplesZactivate_by_schema_keys�auto�/F)�mode�devices�ignore_growroot_disabledz/cc_growpart_keydatac @ s e Zd ZdZdZdZdZdS )�RESIZE�SKIPPED�CHANGED�NOCHANGE�FAILEDN)�__name__� __module__�__qualname__r r r r � r$ r$ �!/usr/lib/python3.6/cc_growpart.pyr o s r )r �distror c C s� d }| dkrFx*t D ]"\}}||�}|j|d�r|}P qW |s�td��n^i }xt D ]\}} | ||<