HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/seed.cpython-310.pyc
o

�N�gS#�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZe�e
�ZddiZdd�Zdd�Zdd	d
�Zdd�Z			
	
				ddd�Z	ddd�Zdd�Zdd�Zdd�ZdS)z(
Virtual machine image management tools
�N�apply_ZapplycCsPtj�|�r&tjj�|��}tjj�|�	��Wd�S1s!wY|S�N)
�os�path�exists�salt�utils�files�fopen�stringutils�
to_unicode�read)Zfile_�fic�r�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/seed.py�_file_or_contents
 �rcCsxtd�}tj�|dt����}tj�|�st�|�t�|d�tj�|tj�	|��}t
�||�|�|d�}||fS)z�
    Update and get the random script to a random place

    CLI Example:

    .. code-block:: bash

        salt '*' seed.prep_bootstrap /tmp

    zconfig.gather_bootstrap_script�tmpi��)
�__salt__rr�join�uuidZuuid4r�makedirs�chmod�basename�shutil�copy�replace)�mptZbs_Zfpd_�fp_�tmppathrrr�prep_bootstraps

r cCs�d}|dkrt��}td||�st�|�dS|S|dkr |S|dkrAdtvr+d}n	dtvr2d}ndStd|||d	�}|sAdS|S)
N�blockzmount.mount�dir�file�
guestfs.mount�guestfs�
qemu_nbd.init�qemu_nbd�Zdevice�util)�tempfile�mkdtemprr�rmdir)r�ftype�rootrr)rrr�_mount7s&

�r/cCsj|dkrtd|�t�|�dS|dkr1d}dtvrd}ndtvr$d}|r3td|||d�dSdSdS)	Nr!zmount.umountr#r$r%r&r'r()rrr,)rZdiskr-r)rrr�_umountMs�r0TFc		Cs�td|dd�}	|	s|�d�S|	d}
|	d}t�d|
|�zt�|�Wn	ty.Ynwt||
|�}|s<|�d�Stj�|d	�}t�d
|�zt�|�Wnty`tj�	|�s^�Ynwt
||||||d�}
t|�r�t�d|�t
j�|
d
�}|d}tj�	tj�||�d���s�tdtj�||�d�d��t�|
dtj�||�d�d��t�|
dtj�||�d�d��t�|
d
tj�|d��d}n"|r�t�d|�t|�}n|r�t�dt
jj�d}nt�d|�d}t|||
�|S)a
    Seed a location (disk image, directory, or block device) with the
    minion config, approve the minion's key, and/or install salt-minion.

    CLI Example:

    .. code-block:: bash

        salt 'minion' seed.apply path id [config=config_data] \
                [gen_key=(true|false)] [approve_key=(true|false)] \
                [install=(true|false)]

    path
        Full path to the directory, device, or disk image  on the target
        minion's file system.

    id
        Minion id with which to seed the path.

    config
        Minion configuration options. By default, the 'master' option is set to
        the target host's 'master'.

    approve_key
        Request a pre-approval of the generated minion key. Requires
        that the salt-master be configured to either auto-accept all keys or
        expect a signing request from the target host. Default: true.

    install
        Install salt-minion, if absent. Default: true.

    prep_install
        Prepare the bootstrap script, but don't run it. Default: false
    z
file.statsT)�follow_symlinksz does not exist�type�targetzMounting %s at %sz could not be mountedrz!Attempting to create directory %s)r�id_�approve_key�pub_key�priv_keyz5salt-minion pre-installed on image, configuring as %s�config�pki_dir�/z
file.makedirsr�privkey�
minion.pem�pubkey�
minion.pubzetc/salt/minionz'Attempting to install salt-minion to %szsThe prep_install option is no longer supported. Please use the bootstrap script installed with Salt, located at %s.Fz No useful action performed on %s)r�log�debugrr�OSErrorr/rr�isdir�mkconfig�_check_install�inforr8�
minion_config�lstrip�rename�_install�error�syspaths�	BOOTSTRAP�warningr0)rr4r8r5�installZprep_installr6r7Zmount_pointZstatsr-rrZ	cfg_filesrFr9�resrrrr[st-
�
���	��
�c
Cs�|durt��}|duri}d|vrtddkrtd|d<|r$||d<tj�|d�}tjj�	|d��}|�
tjj�|��Wd�n1sHwYtj�|d�}tj�|d�}	|o^|}
|
r�t
�d	|�t
�d
|	�tjj�	|d��}|�
tjj�t|���Wd�n1s�wYtjj�	|	d��}|�
tjj�t|���Wd�n1s�wYt�|d�t�|	d�ntj�|dd
�|r�|
s�tjj�	|��}tjj�|���}tdd||gi�Wd�n1s�wY|||	d�S)a�
    Generate keys and config and put them in a tmp directory.

    pub_key
        absolute path or file content of an optional preseeded salt key

    priv_key
        absolute path or file content of an optional preseeded salt key

    CLI Example:

    .. code-block:: bash

        salt 'minion' seed.mkconfig [config=config_data] [tmp=tmp_dir] \
                [id_=minion_id] [approve_key=(true|false)]
    NZmasterr�idZminionzw+r>r<zWriting minion.pub to %szWriting minion.pem to %s�wi�iz
pillar.extZvirtkey)r8r=r;)r*r+Z__opts__rrrrrr	r
�writeZcloudZsalt_config_to_yamlr?r@rZto_strrrZcryptZgen_keysrr
r)
r8rr4r5r6r7Z
tmp_configrZpubkeyfnZ	privkeyfnZ	preseededrr=rrrrC�sB����rCcCsPt|�t|�ptjj\}}d}|d�tj�|d��7}t	d||dd�dS)z�
    Determine whether salt-minion is installed and, if not,
    install it.
    Return True if install is successful or already installed.
    z"if type salt-minion; then exit 0; zelse sh {} -c /tmp; fizbootstrap-salt.shzcmd.run_chrootT)�python_shell�retcode)
�
_check_resolvr rrKrL�formatrrrr)rZboot_r�cmdrrrrIs
rIcCs�tj�|d�}d}tj�|�r(tj�|�}tj�tj�|��s(t�tj�|��tj�|�s0d}|s_t	j
j�|d��}t	j
j
�|���}d|vrJd}d|vrPd}Wd�n1sZwY|rit�d|�dSdS)	z=
    Check that the resolv.conf is present and populated
    zetc/resolv.confFT�rbZ
nameserverznameserver 127.0.0.1Nz/etc/resolv.conf)rrr�islink�realpathrB�dirnamer�isfilerrr	r
rrr
rr)rZresolvrrZcontsrrrrUs(���rUcCsNd}tj�tj�|d��rd}d}d|�d|�d|�d�}td	|d
dd�S)
Nz/bin/shzbin/bashz	/bin/bashz&if ! type salt-minion; then exit 1; fizchroot 'z' z -c '�'zcmd.retcode�quietT)Zoutput_loglevelrS)rrr\rr)r.Zsh_rWrrrrD(srDr)NNTTFNNN)NNNTNN)�__doc__�loggingrrr*rZsalt.configrZ
salt.cryptZ
salt.syspathsZsalt.utils.cloudZsalt.utils.files�	getLogger�__name__r?Z__func_alias__rr r/r0rrCrIrUrDrrrr�<module>s>


�q
�8