Current File : //lib/python2.7/site-packages/cloudinit/config/cc_snap.pyc
�
oB�]c
@sdZddlZddlmZddlmZddlmZm	Z	ddl
mZddlm
Z
ddlmZd	gZeZeje�Zi	d
d6dd
6dd6ed�d6ed6ed�ed�ed�gd6ed6dd6iidd6iiddgd6idd6d6ed6dd6dd 6ed!6d"6iddgd6iidd6idd6d6idd6gd#6d6ed6dd6dd 6d$6id%d6d&6d'6ed(6gd)6dd 6d*6d'6Zee�Zd*Zd+Zd,�Zd-�Zd.�Zd/�ZdS(0s<Snap: Install, configure and manage snapd and snap packages.i����N(tdedent(tlog(tget_schema_doctvalidate_cloudconfig_schema(tPER_INSTANCE(tprepend_base_command(tutiltubuntutcc_snaptidtSnaptnames5Install, configure and manage snapd and snap packagesttitles,        This module provides a simple configuration namespace in cloud-init to
        both setup snapd and install snaps.

        .. note::
            Both ``assertions`` and ``commands`` values can be either a
            dictionary or a list. If these configs are provided as a
            dictionary, the keys are only used to order the execution of the
            assertions or commands and the dictionary is merged with any
            vendor-data snap configuration provided. If a list is provided by
            the user instead of a dict, any vendor-data snap configuration is
            ignored.

        The ``assertions`` configuration option is a dictionary or list of
        properly-signed snap assertions which will run before any snap
        ``commands``. They will be added to snapd's assertion database by
        invoking ``snap ack <aggregate_assertion_file>``.

        Snap ``commands`` is a dictionary or list of individual snap
        commands to run on the target system. These commands can be used to
        create snap users, install snaps and provide snap configuration.

        .. note::
            If 'side-loading' private/unpublished snaps on an instance, it is
            best to create a snap seed directory and seed.yaml manifest in
            **/var/lib/snapd/seed/** which snapd automatically installs on
            startup.

        **Development only**: The ``squashfuse_in_container`` boolean can be
        set true to install squashfuse package when in a container to enable
        snap installs. Default is false.
        tdescriptiontdistrosst        snap:
            assertions:
              00: |
              signed_assertion_blob_here
              02: |
              signed_assertion_blob_here
            commands:
              00: snap create-user --sudoer --known <snap-user>@mydomain.com
              01: snap install canonical-livepatch
              02: canonical-livepatch enable <AUTH_TOKEN>
    s�        # LXC-based containers require squashfuse before snaps can be installed
        snap:
            commands:
                00: apt-get install squashfuse -y
                11: snap install emoj

    s�        # Convenience: the snap command can be omitted when specifying commands
        # as a list and 'snap' will automatically be prepended.
        # The following commands are equivalent:
        snap:
            commands:
                00: ['install', 'vlc']
                01: ['snap', 'install', 'vlc']
                02: snap install vlc
                03: 'snap install vlc'
    texamplest	frequencytobjectttypetarraytstringtitemstadditionalItemsitminItemst
minPropertiestuniqueItemst
assertionstoneOftcommandstbooleantsquashfuse_in_containert
propertiestadditionalPropertiestrequiredtsnaps(/var/lib/cloud/instance/snapd.assertionscCs�|s
dStjd�t|t�r5|j�}n*t|t�s_tdjd|���ntdg}dj	|�}x.|D]&}tjd|j
d�dd	!�q�Wtjt
|jd
��tj|t
gdt�dS(sImport list of assertions.

    Import assertions by concatenating each assertion into a
    string separated by a '
'.  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.
    Ns'Importing user-provided snap assertionss8assertion parameter was not a list or dict: {assertions}Rtacks
sSnap acking: %siisutf-8tcapture(tLOGtdebugt
isinstancetdicttvaluestlistt	TypeErrortformattSNAP_CMDtjointsplitRt
write_filetASSERTIONS_FILEtencodetsubptTrue(Rtsnap_cmdtcombinedtasrt((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_snap.pytadd_assertions�s
	
$c	Cs=|s
dStjd�t|t�rTgt|j��D]\}}|^q9}n*t|t�s~tdjd|���nt	d|�}g}xl|D]d}t|t
�}y#tj|d|dt
jj�Wq�tjk
r�}|jt
|��q�Xq�W|r9djd	|�}tjt|�t|��ndS(
sMRun 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.
     Ns#Running user-provided snap commandss5commands parameter was not a list or dict: {commands}RR"tshellt	status_cbs.Failures running snap commands:
{cmd_failures}tcmd_failures(R%R&R'R(tsortedRR*R+R,RtstrRR3tsyststderrtwritetProcessExecutionErrortappendtlogexctRuntimeError(	Rt_tvtfixed_snap_commandsR;tcommandR9tetmsg((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_snap.pytrun_commands�s,	
.	
#		cCs�tj�sdSy|jj�Wn$tk
rGtjtd��nXy|jjdg�Wn$tk
r�tjtd��nXdS(s,Install squashfuse if we are in a container.NsPackage update failedt
squashfusesFailed to install squashfuse(Rtis_containertdistrotupdate_package_sourcest	ExceptionRCR%tinstall_packages(tcloud((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_snap.pytmaybe_install_squashfuse�s

cCs�|jdi�}|s,tjd|�dSt|t�tj|jdt��rat|�nt	|jdg��t
|jdg��dS(NR"s8Skipping module named %s, no 'snap' key in configurationRRR(tgetR%R&RtschemaRtis_truetFalseRSR8RK(RtcfgRRRtargstcfgin((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_snap.pythandle�s	

(t__doc__R>ttextwrapRt	cloudinitRtloggingtcloudinit.config.schemaRRtcloudinit.settingsRtcloudinit.subpRRRRt	getLoggert__name__R%RWR4RUR-R1R8RKRSR[(((s</usr/lib/python2.7/site-packages/cloudinit/config/cc_snap.pyt<module>sl	
		



			%