HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_grub_dpkg.cpython-310.pyc
o

�Ad��@s�UdZddlZddlmZddlmZddlmZmZddl	m
Z
ddlmZddl
mZmZdd	lmZdd
lmZdZdd
gZdddeeeed�ggd�Zeed<ee�Zdd�Zdedede
dededdf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.
�ubuntu�debian�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�title�description�distros�	frequency�examples�activate_by_schema_keys�metac
CsLd}g}ztjgd�dd�d��}Wn8ty=}zt|jt�r'|�d�nd|jvr2|�d�n�WYd	}~nd	}~wtyKt	�
|d
�Ynw|rTtj�
|�sVdSztjddd
d|gdd�d����}Wntyzt	�
|d|�Ynw|�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)�capturerz'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-dpkg�udevadm�infoz--rootz--query=symlinkz3udevadm DEVLINKS symlink query failed for disk='%s'z%considering these device symlinks: %s�,cSsg|]}d|vr|�qS)z
disk/by-id�)�.0�devrr�?/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)�logr�devices�e�idevsrrr!�fetch_idevs<sR��
�������r5r�cfg�cloudr1�args�returnc
Cs�|�d|�di��}|si}|�dd�}t�|�r"|�d||�dSt�|dd�}|dur1t|�}|�d�}|dur>|}n
t|t�sHt�|�}t	|��
�}d||f}	|�d	||f�z
t�d
g|	�WdStywt�
|d�YdSw)N�	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)�getr�is_falser'�get_cfg_option_strr5r$�bool�translate_bool�str�lowerrr)r*)
rr6r7r1r8�mycfgr;r4�idevs_empty�	dconf_selrrr!�handlexs<



�����rF)�__doc__r+�loggingr�textwrapr�	cloudinitrr�cloudinit.cloudr�cloudinit.configr�cloudinit.config.schemarr	�cloudinit.settingsr
�cloudinit.subpr�MODULE_DESCRIPTIONrr�__annotations__r5rA�listrFrrrr!�<module>sN��
�<������