3 \mei @sUdZddlZddlZddlmZddlmZmZmZddl m Z ddl m Z ddl mZmZddlmZejeZeZd gZd d d ed eedgedgdZeeeZee e eddddZdS)z:Bootcmd: run arbitrary commands early in the boot process.N)dedent)subp temp_utilsutil)Cloud)Config) MetaSchema get_meta_doc) PER_ALWAYSallZ cc_bootcmdZBootcmdz0Run arbitrary commands early in the boot processa This module runs arbitrary commands very early in the boot process, only slightly after a boothook would run. This is very similar to a boothook, but more user friendly. The environment variable ``INSTANCE_ID`` will be set to the current instance id for all run commands. Commands can be specified either as lists or strings. For invocation details, see ``runcmd``. .. note:: bootcmd should only be used for things that could not be done later in the boot process. .. note:: when writing files, do not use /tmp dir as it races with systemd-tmpfiles-clean LP: #1707222. Use /run/somedir instead. z bootcmd: - echo 192.168.1.130 us.archive.ubuntu.com > /etc/hosts - [ cloud-init-per, once, mymkfs, mkfs, /dev/vdb ] bootcmd)idnametitle descriptiondistrosZexamples frequencyZactivate_by_schema_keys)rcfgcloudargsreturnc Csd|krtjd|dStjdd}y*tj|d}|jtj||jWn6t k r}ztj tdt |WYdd}~XnXy@t j j}|j}|rt ||d<d|jg} tj| |dd Wn$t k rtj td |YnXWdQRXdS) Nr z;Skipping module named %s, no 'bootcmd' key in configurationz.sh)suffixzFailed to shellify bootcmd: %sZ INSTANCE_IDz/bin/shF)envZcapturezFailed to run bootcmd module %s)LOGdebugrZExtendedTemporaryFilerZshellifywriteZ encode_textflush ExceptionZlogexcstrosenvironcopyZget_instance_idrr) rrrrZtmpfZcontenterZiidcmdr$ /usr/lib/python3.6/cc_bootcmd.pyhandleDs,    r&)__doc__ZloggingrtextwraprZ cloudinitrrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarr Zcloudinit.settingsr Z getLogger__name__rrrmetarlistr&r$r$r$r% s.