Current File : //lib/python2.7/site-packages/cloudinit/config/cc_snap_config.pyc
�
oB�]c@s|dZddlmZddlmZddlmZeje�Z	eZ
dZdZd
d�Zd
d�Zd	�Zd
S(s@
Snap Config
-----------
**Summary:** snap_config modules allows configuration of snapd.

**Deprecated**: Use :ref:`snap` module instead. This module will not exist
in cloud-init 18.3.

This module uses the same ``snappy`` namespace for configuration but
acts only only a subset of the configuration.

If ``assertions`` is set and the user has included a list of assertions
then cloud-init will collect the assertions into a single assertion file
and invoke ``snap ack <path to file with assertions>`` which will attempt
to load the provided assertions into the snapd assertion database.

If ``email`` is set, this value is used to create an authorized user for
contacting and installing snaps from the Ubuntu Store.  This is done by
calling ``snap create-user`` command.

If ``known`` is set to True, then it is expected the user also included
an assertion of type ``system-user``.  When ``snap create-user`` is called
cloud-init will append '--known' flag which instructs snapd to look for
a system-user assertion with the details.  If ``known`` is not set, then
``snap create-user`` will contact the Ubuntu SSO for validating and importing
a system-user for the instance.

.. note::
    If the system is already managed, then cloud-init will not attempt to
    create a system-user.

**Internal name:** ``cc_snap_config``

**Module frequency:** per instance

**Supported distros:** any with 'snapd' available

**Config keys**::

    #cloud-config
    snappy:
        assertions:
        - |
        <assertion 1>
        - |
        <assertion 2>
        email: user@user.org
        known: true

i����(tlog(tPER_INSTANCE(tutiltsnaps(/var/lib/cloud/instance/snapd.assertionscCs�|sg}nt|t�s9tdjd|���ntdg}dj|�}t|�dkrutd��nx.|D]&}tjd|j	d�dd!�q|Wt
jt|j
d	��t
j|tgd
t�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.
    s0assertion parameter was not a list: {assertions}t
assertionstacks
isAssertion list is emptys
Acking: %sisutf-8tcaptureN(t
isinstancetlistt
ValueErrortformatt
SNAPPY_CMDtjointlentLOGtdebugtsplitRt
write_filetASSERTIONS_FILEtencodetsubptTrue(Rtsnap_cmdtcombinedtasrt((sC/usr/lib/python2.7/site-packages/cloudinit/config/cc_snap_config.pytadd_assertionsRs		
$cCs|si}nt|t�s9tdjd|���n|jdd�}|sUdSi|d6|jdt�d6}tjt	dgdt
�\}}|j�d	kr�tj
d
�dS|jd�rtjt	ddgdt
�\}}t|�dkrtjd
�dSn|S(sAdd a snap system-user if provided with email under snappy config.

      - Check that system is not already managed.
      - Check that if using a system-user assertion, that it's
        imported into snapd.

    Returns a dictionary to be passed to Distro.create_user
    s-configuration parameter was not a dict: {cfg}tcfgtemailNtsnapusertknowntmanagedRttrues=This device is already managed. Skipping system-user creationssystem-userisEMissing "system-user" assertion. Check "snappy" user-data assertions.(RtdictR	R
tgettNonetFalseRRRRtstripRtwarningR
terror(RRtusercfgtoutt_((sC/usr/lib/python2.7/site-packages/cloudinit/config/cc_snap_config.pyt
add_snap_userns,
	!

cCs�|jd�}|s&tjd�dS|jd�tj�sStjd|�dS|jdg�}t|�dkr�tjd�t|�ntd|�}|r�|j	j
|jd	�|�ndS(
Ntsnappys#No snappy config provided, skippingsXDEPRECATION: snap_config module will be dropped in 18.3 release. Use snap module insteads%s: system not snappyRis'Importing user-provided snap assertionsRR(R!RRR%Rtsystem_is_snappyR
RR*tdistrotcreate_user(tnameRtcloudRtargstcfginRR'((sC/usr/lib/python2.7/site-packages/cloudinit/config/cc_snap_config.pythandle�s 


	N(t__doc__t	cloudinitRtloggingtcloudinit.settingsRRt	getLoggert__name__Rt	frequencyRRR"RR*R3(((sC/usr/lib/python2.7/site-packages/cloudinit/config/cc_snap_config.pyt<module>9s-