3 \me0 @sUdZddlZddlZddlZddlmZddlmZmZddl m Z ddl m Z ddl mZmZddlmZdd lmZd gZeZejeZd d d edeededededgedgdZeeeZdZddZddZee e eddddZdS)z``. 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. ax snap: assertions: 00: | signed_assertion_blob_here 02: | signed_assertion_blob_here commands: 00: snap create-user --sudoer --known @mydomain.com 01: snap install canonical-livepatch 02: canonical-livepatch enable ay # 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' z # You can use a list of commands snap: commands: - ['install', 'vlc'] - ['snap', 'install', 'vlc'] - snap install vlc - 'snap install vlc' z # You can use a list of assertions snap: assertions: - signed_assertion_blob_here - | signed_assertion_blob_here snap)idnametitle descriptiondistrosZexamples frequencyZactivate_by_schema_keyscCs|sdStjdt|tr&|j}nt|ts@tdj|dtd|g}dj |}x&|D]}tjd|j ddd qZWt j ||j d tj|d d dS) aImport 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. Nz'Importing user-provided snap assertionsz8assertion parameter was not a list or dict: {assertions}) assertionsZack zSnap acking: %srzutf-8T)Zcapture)LOGdebug isinstancedictvalueslist TypeErrorformatSNAP_CMDjoinsplitrZ write_fileencoder)rZassertions_fileZsnap_cmdZcombinedZasrtr!/usr/lib/python3.6/cc_snap.pyadd_assertionsws        r#cCs|sdStjdt|tr4ddt|jD}nt|tsNtdj|dt d|}g}xb|D]Z}t|t }yt j ||t j jdWqbt jk r}z|jt |WYdd}~XqbXqbW|rd j|d }tjt|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|] \}}|qSr!r!).0_vr!r!r" sz run_commands..z5commands parameter was not a list or dict: {commands})commandsr )shellZ status_cbz.Failures running snap commands: {cmd_failures}) cmd_failures)rrrrsorteditemsrrrr strrsysstderrwriteZProcessExecutionErrorappendrZlogexc RuntimeError)r(Zfixed_snap_commandsr*Zcommandr)emsgr!r!r" run_commandss,        $ r5)r cfgcloudargsreturncCsV|jdi}|s tjd|dSt|jdgtjj|jjdt |jdgdS)Nr z8Skipping module named %s, no 'snap' key in configurationrzsnapd.assertionsr() getrrr#ospathrpathsZ get_ipath_curr5)r r6r7r8Zcfginr!r!r"handles  r>) __doc__Zloggingr;r.textwraprZ cloudinitrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarrZcloudinit.settingsr Zcloudinit.subpr rrZ getLogger__name__rmetarr#r5r-rr>r!r!r!r"sD         '