Your IP : 216.73.217.13


Current Path : /usr/lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/cloudinit/config/__pycache__/cc_grub_dpkg.cpython-38.pyc

U

�Ad��	@s�UdZddlZddlmZddlmZddlmZmZddl	m
Z
ddlmZddl
mZmZdd	lmZdd
lmZdZdd
gZdddeeeed�ggd�Zeed<ee�Zdd�Zeee
eedd�dd�ZdS)z5Grub Dpkg: Configure grub debconf installation device�N)�Logger)�dedent)�subp�util)�Cloud)�Config)�
MetaSchema�get_meta_doc)�PER_INSTANCE)�ProcessExecutionErrora�Configure which device is used as the target for grub installation. This module
can be enabled/disabled using the ``enabled`` config key in the ``grub_dpkg``
config dict. The global config key ``grub-dpkg`` is an alias for ``grub_dpkg``.
If no installation device is specified this module will execute grub-probe to
determine which disk the /boot directory is associated with.

The value which is placed into the debconf database is in the format which the
grub postinstall script expects. Normally, this is a /dev/disk/by-id/ value,
but we do fallback to the plain disk name if a by-id name is not present.

If this module is executed inside a container, then the debconf database is
seeded with empty values, and install_devices_empty is set to true.
ZubuntuZdebianZcc_grub_dpkgz	Grub Dpkgz*Configure grub debconf installation devicez�            grub_dpkg:
              enabled: true
              grub-pc/install_devices: /dev/sda
              grub-pc/install_devices_empty: false
            )�id�name�titleZdescription�distrosZ	frequencyZexamplesZactivate_by_schema_keys�metac
CsTd}g}z"tjddddgdd�d��}Wnptk
r|}z4t|jt�rT|�d	�nd
|jkrj|�d�n�W5d}~XYn tk
r�t	�
|d
�YnX|r�tj�
|�s�dSz(tjdddd|gdd�d����}Wn"tk
r�t	�
|d|�YnX|�dd�|��dd�|D�}|�dd�|��|�r@t|�dn|}|�d|�|S)z�
    Fetches the /dev/disk/by-id device grub is installed to.
    Falls back to plain disk name if no by-id entry is present.
    �z
grub-probez-t�diskz/bootT)Zcapturerz'grub-probe' not found in $PATHzfailed to get canonical pathz)grub-probe 'failed to get canonical path'Nz*grub-probe failed to execute for grub-dpkgZudevadm�infoz--rootz--query=symlinkz3udevadm DEVLINKS symlink query failed for disk='%s'z%considering these device symlinks: %s�,cSsg|]}d|kr|�qS)z
disk/by-id�)�.0Zdevrr�?/usr/lib/python3/dist-packages/cloudinit/config/cc_grub_dpkg.py�
<listcomp>oszfetch_idevs.<locals>.<listcomp>z)filtered to these disk/by-id symlinks: %szselected %s)r�stripr�
isinstance�reason�FileNotFoundError�debug�stderr�	Exceptionr�logexc�os�path�exists�split�join�sorted)�logrZdevices�e�idevsrrr�fetch_idevs<sH�
��
��
r*)r
�cfg�cloudr'�args�returnc
Cs�|�d|�di��}|si}|�dd�}t�|�rD|�d||�dSt�|dd�}|dkrbt|�}|�d�}|dkr||}nt|t�s�t�|�}t	|��
�}d||f}	|�d	||f�zt�d
g|	�Wn tk
r�t�
|d�YnXdS)NZ	grub_dpkgz	grub-dpkg�enabledTz*%s disabled by config grub_dpkg/enabled=%szgrub-pc/install_deviceszgrub-pc/install_devices_emptyz[grub-pc grub-pc/install_devices string %s
grub-pc grub-pc/install_devices_empty boolean %s
z2Setting grub debconf-set-selections with '%s','%s'zdebconf-set-selectionsz2Failed to run debconf-set-selections for grub-dpkg)�getrZis_falserZget_cfg_option_strr*r�boolZtranslate_bool�str�lowerrrr )
r
r+r,r'r-Zmycfgr/r)Zidevs_emptyZ	dconf_selrrr�handlexs:



����r4)�__doc__r!Zloggingr�textwraprZ	cloudinitrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarr	Zcloudinit.settingsr
Zcloudinit.subprZMODULE_DESCRIPTIONrr�__annotations__r*r2�listr4rrrr�<module>	s@��
�=�