3 \�mep� � @ s� U d Z ddlZddlZddlZddlmZ ddlmZmZ ddl m Z ddlmZ ddl mZmZ ddlmZ dd lmZ ejd �Zejd�Zejd�Zejd �Zejd�Zejd�Zejd�ZddiZeje�ZdZ ddde egeed�gddgd�Z!e!ee!�Z e"ee e#dd�dd�Z$dd� Z%d d!� Z&dTd"d#�Z'dUd%d&�Z(d'd(� Z)dVd)d*�Z*d+d,� Z+d-d.� Z,dWd0d1�Z-d2d3� Z.d4d5� Z/d6d7� Z0d8d9� Z1d:d;� Z2d<d=� Z3d>d?� Z4d@dA� Z5dBdC� Z6dDdE� Z7dFdG� Z8dHdI� Z9dJdK� Z:dLdM� Z;dNdO� Z<dPdQ� Z=dRdS� Z>dS )Xz1Disk Setup: Configure partitions and filesystems.� N)�dedent)�subp�util)�Cloud)�Config)� MetaSchema�get_meta_doc)�ALL_DISTROS)�PER_INSTANCEZsfdiskZsgdiskZlsblkZblkidZblockdevZ partprobeZwipefsZLANG�Cai This module is able to configure simple partition tables and filesystems. .. note:: for more detail about configuration options for disk setup, see the disk setup example .. note:: if a swap partition is being created via ``disk_setup`` then a ``fs_entry`` entry is also needed in order for mkswap to be run, otherwise when swap activation is later attempted it will fail. For convenience, aliases can be specified for disks using the ``device_aliases`` config key, which takes a dictionary of alias: path mappings. There are automatic aliases for ``swap`` and ``ephemeral<X>``, where ``swap`` will always refer to the active swap partition and ``ephemeral<X>`` will refer to the block device of the ephemeral image. Disk partitioning is done using the ``disk_setup`` directive. This config directive accepts a dictionary where each key is either a path to a block device or an alias specified in ``device_aliases``, and each value is the configuration options for the device. File system configuration is done using the ``fs_setup`` directive. This config directive accepts a list of filesystem configs. Z cc_disk_setupz Disk Setupz$Configure partitions and filesystemsan device_aliases: my_alias: /dev/sdb swap_disk: /dev/sdc disk_setup: my_alias: table_type: gpt layout: [50, 50] overwrite: true swap_disk: table_type: gpt layout: [[100, 82]] overwrite: true /dev/sdd: table_type: mbr layout: true overwrite: true fs_setup: - label: fs1 filesystem: ext4 device: my_alias.1 cmd: mkfs -t %(filesystem)s -L %(label)s %(device)s - label: fs2 device: my_alias.2 filesystem: ext4 - label: swap device: swap_disk.1 filesystem: swap - label: fs3 device: /dev/sdd1 filesystem: ext4 mounts: - ["my_alias.1", "/mnt1"] - ["my_alias.2", "/mnt2"] - ["swap_disk.1", "none", "swap", "sw", "0", "0"] - ["/dev/sdd1", "/mnt3"] � disk_setup�fs_setup)�id�name�title�descriptionZdistrosZ frequencyZexamplesZactivate_by_schema_keys)r �cfg�cloud�args�returnc s� |j di ��� �fdd�}|j d�}t|t�r�t||� tjdt|�� x�|j� D ]~\}}t|t�srtjd|� qRy*tjd� t j tjd| t||fd � W qR tk r� } zt j td | � W Y dd}~X qRX qRW |j d�} t| t��r�tjd t| �� t| |� x�| D ]�}t|t��s*tjd|� �q y2tjd� |j d�} t j tjd| t|fd � W n4 tk �r� } zt j td| � W Y dd}~X nX �q W dS )z[ See doc/examples/cloud-config-disk-setup.txt for documentation on the format. �device_aliasesc s �j | �}� j|p| �p|S )N)�getZdevice_name_to_device)Zcandr )r r � �#/usr/lib/python3.6/cc_disk_setup.py�alias_to_devicey s zhandle.<locals>.alias_to_devicer zPartitioning disks: %szInvalid disk definition for %sz!Creating new partition table/diskzCreating partition on %s)Zlogfunc�msg�funcr z Failed partitioning operation %sNr zsetting up filesystems: %sz"Invalid file system definition: %szCreating new filesystem.�devicezCreating fs for %sz%Failed during filesystem operation %s)r � isinstance�dict�update_disk_setup_devices�LOG�debug�str�items�warningr Zlog_time�mkpart� Exception�logexc�list�update_fs_setup_devices�mkfs)r r r r r r �disk� definition�er r r )r r r �handler sJ & r/ c C s� x�t | �D ]t}||�}|d ks ||kr(q || krDtjd||� | |= | | | |<