name : cc_snap.cpython-39.pyc
a

'�Dgl
�@s�UdZddlZddlZddlmZmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZe�e�Zd	d
ge
dgd�Zeed
<dZdd�Zdd�Zee	eedd�dd�ZdS)z<Snap: Install, configure and manage snapd and snap packages.�N)�subp�util)�Cloud)�Config)�
MetaSchema)�PER_INSTANCE)�prepend_base_commandZcc_snapZubuntu�snap)�idZdistrosZ	frequencyZactivate_by_schema_keys�metacCs�|sdSt�d�t|t�r&|��}nt|t�s@tdj|d���td|g}d�	|�}|D]}t�d|�
d�dd	��qXt�||�
d
��tj|dd�dS)
aImport list of assertions.

    Import assertions by concatenating each assertion into a
    string separated by a '\n'.  Write this string to a instance file and
    then invoke `snap ack /path/to/file` and check for errors.
    If snap exits 0, then all assertions are imported.
    Nz'Importing user-provided snap assertionsz8assertion parameter was not a list or dict: {assertions})�
assertionsZack�
zSnap acking: %sr�zutf-8T)Zcapture)�LOG�debug�
isinstance�dict�values�list�	TypeError�format�SNAP_CMD�join�splitrZ
write_file�encoder)rZassertions_fileZsnap_cmdZcombinedZasrt�r�</usr/lib/python3.9/site-packages/cloudinit/config/cc_snap.py�add_assertionss"



��

rcCs�|sdSt�d�t|t�r4dd�t|���D�}nt|t�sNtdj|d���t	d|�}g}|D]V}t|t
�}ztj||d�Wq`tjy�}z|�
t
|��WYd}~q`d}~00q`|r�d	j|d
�}t�t|�t|��dS)aHRun the provided commands provided in snap:commands configuration.

    Commands are run individually. Any errors are collected and reported
    after attempting all commands.

    @param commands: A list or dict containing commands to run. Keys of a
        dict will be used to order the commands provided as dict values.
    Nz#Running user-provided snap commandscSsg|]\}}|�qSrr)�.0�_�vrrr�
<listcomp>I�z run_commands.<locals>.<listcomp>z5commands parameter was not a list or dict: {commands})�commandsr	)�shellz.Failures running snap commands:
{cmd_failures})�cmd_failures)rrrr�sorted�itemsrrrr�strrZProcessExecutionError�appendrZlogexc�RuntimeError)r#Zfixed_snap_commandsr%Zcommandr$�e�msgrrr�run_commands;s2	


��

&�r-)�name�cfg�cloud�args�returncCs`|�di�}|s t�d|�dSt�|�t|�dg�tj�|j	�
�d��t|�dg��dS)Nr	z8Skipping module named %s, no 'snap' key in configurationrzsnapd.assertionsr#)�getrrrZwait_for_snap_seededr�os�pathr�pathsZ
get_ipath_curr-)r.r/r0r1Zcfginrrr�handlebs�

�r7)�__doc__Zloggingr4Z	cloudinitrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarZcloudinit.settingsrZcloudinit.subprZ	getLogger�__name__rr�__annotations__rrr-r(rr7rrrr�<module>s$
�'

© 2025 Cubjrnet7