Your IP : 216.73.217.13


Current Path : /lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_seed_random.cpython-38.pyc

U

�Ad@�	@sUdZddlZddlZddlmZddlmZddlmZddl	m
Zddl	mZmZddl
mZdd	lmZdd
lmZmZddlmZddlmZe�e�Zd
Zdddeegeed�ed�ggd�Zeed<ee�Zddd�Zddd�Ze eeee!dd�dd�Z"dS)z%Seed Random: Provide random seed data�N)�BytesIO)�Logger)�dedent)�log)�subp�util)�Cloud)�Config)�
MetaSchema�get_meta_doc)�ALL_DISTROS)�PER_INSTANCEaPAll cloud instances started from the same image will produce very similar
data when they are first booted as they are all starting with the same seed
for the kernel's entropy keyring. To avoid this, random seed data can be
provided to the instance either as a string or by specifying a command to run
to generate the data.

Configuration for this module is under the ``random_seed`` config key. If
the cloud provides its own random seed data, it will be appended to ``data``
before it is written to ``file``.

If the ``command`` key is specified, the given command will be executed.  This
will happen after ``file`` has been populated.  That command's environment will
contain the value of the ``file`` key as ``RANDOM_SEED_FILE``. If a command is
specified that cannot be run, no error will be reported unless
``command_required`` is set to true.
Zcc_seed_randomzSeed RandomzProvide random seed dataz�            random_seed:
              file: /dev/urandom
              data: my random string
              encoding: raw
              command: ['sh', '-c', 'dd if=/dev/urandom of=$RANDOM_SEED_FILE']
              command_required: true
            a_            # To use 'pollinate' to gather data from a remote entropy
            # server and write it to '/dev/urandom', the following
            # could be used:
            random_seed:
              file: /dev/urandom
              command: ["pollinate", "--server=http://local.polinate.server"]
              command_required: true
            )�id�name�titleZdescriptionZdistrosZ	frequencyZexamplesZactivate_by_schema_keys�metacCsd|sdS|r|��dkr"t�|�S|��dkr8t�|�S|��dkrTtj|ddd�Std|��dS)N�)�raw)�base64Zb64)ZgzipZgzF)�quiet�decodez Unknown random_seed encoding: %s)�lowerr�encode_textrZ	b64decodeZdecomp_gzip�IOError)�data�encoding�r�A/usr/lib/python3/dist-packages/cloudinit/config/cc_seed_random.py�_decodeQs

rcCsp|s|rtd��n|s$t�d�dS|d}t�|�s\|rLtdj|d���nt�d|�dStj||dd�dS)	Nz"no command found but required=truezno command providedrz+command '{cmd}' not found but required=true)�cmdz'command '%s' not found for seed_commandF)�envZcapture)�
ValueError�LOG�debugrZwhich�format)�command�requiredr rrrr�handle_random_seed_command^s



�r')r�cfg�cloudr�args�returnc
Cs|�di�}|�dd�}|�dd�}t�}|rF|�t||�d�d��|jj}	|	rnd|	krn|�t�|	d��|��}t	|�r�|�
d|t	|�|�t�||�|�d	d�}
|�d
d�}z$tj
��}||d<t|
||d
�Wn6tk
�r}
z|�d|
|
�|
�W5d}
~
XYnXdS)NZrandom_seed�filez/dev/urandomrrr)rz0%s: adding %s bytes of random seed entropy to %sr%Zcommand_requiredFZRANDOM_SEED_FILE)r%r&r z'handling random command [%s] failed: %s)�getr�writerZ
datasource�metadatarr�getvalue�lenr#Zappend_file�os�environ�copyr'r!Zwarning)rr(r)rr*ZmycfgZ	seed_pathZ	seed_dataZseed_bufr/r%Zreqr �errr�handleqs6�
r6)N)N)#�__doc__rr2�iorZloggingr�textwraprZ	cloudinitrrrZcloudinit.cloudrZcloudinit.configr	Zcloudinit.config.schemar
rZcloudinit.distrosrZcloudinit.settingsr
Z	getLogger�__name__r"ZMODULE_DESCRIPTIONr�__annotations__rr'�str�listr6rrrr�<module>	sN
�
���!

�