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__/genesis.cpython-310.pyc
o

�N�gU�
@s^dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZddl
ZddlmZe�e�Zdddd�ZdZd	d
�Zddddddddddddef
d
d�Zdd�Zd2dd�Zdd�Zdddefdd�Z				d3dd�Z				d4dd�Zdd�Zdd �Zd5d#d$�Zd6d&d'�Z d7d(d)�Z!d8d*d+�Z"d,d-�Z#d2d.d/�Z$d2d0d1�Z%dS)9zI
Module for managing container and VM images

.. versionadded:: 2014.7.0
�N)�SaltInvocationError)�yum�rpm)�debootstrap)�pacman)r�debrzMhttp://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpmcCsdS)zt
    By default, this will be available on all platforms; but not all distros
    will necessarily be supported
    T�rrr�H/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/genesis.py�__virtual__#sr
�dir�ext2c
CsD|dvrtd��|dkr:td|�s9ztd|�Wn�ty8}zdtjj�t�|��iWYd}~Sd}~wwns|dkr�|	sDtd	��|
sMd
t	�
���}
td|
ddd�td
dd|	|fdd�t||||
�td
d�}t�
d|�td
d|�d|���td
d�}t�
d|�td�}td
d|�d|�d|���td|
|�t|||
�|
r�|
}|dur�g}|
dur�g}
|dvr�t|||
|d�n|dkr�t|||||||
d�n|dkr�t||||
d�|dk�r td |�}td!|
�d"�d#||d$�td%|�td
d&|���td
d&|���td'|
�dSdS)(a�

    Create an image for a specific platform.

    Please note that this function *MUST* be run as root, as images that are
    created make files belonging to root.

    platform
        Which platform to use to create the image. Currently supported platforms
        are rpm, deb and pacman.

    root
        Local path to create the root of the image filesystem.

    img_format
        Which format to create the image in. By default, just copies files into
        a directory on the local filesystem (``dir``). Future support will exist
        for ``sparse``.

    fs_format
        When using a non-``dir`` ``img_format``, which filesystem to format the
        image to. By default, ``ext2``.

    fs_opts
        When using a non-``dir`` ``img_format``, a dict of opts may be
        specified.

    arch
        Architecture to install packages for, if supported by the underlying
        bootstrap tool. Currently only used for deb.

    flavor
        Which flavor of operating system to install. This correlates to a
        specific directory on the distribution repositories. For instance,
        ``wheezy`` on Debian.

    repo_url
        Mainly important for Debian-based repos. Base URL for the mirror to
        install from. (e.x.: http://ftp.debian.org/debian/)

    static_qemu
        Local path to the static qemu binary required for this arch.
        (e.x.: /usr/bin/qemu-amd64-static)

    pkg_confs
        The location of the conf files to copy into the image, to point the
        installer to the right repos and configuration.

    img_size
        If img_format is not ``dir``, then the size of the image must be
        specified.

    mount_dir
        If img_format is not ``dir``, then the image must be mounted somewhere.
        If the ``mount_dir`` is not specified, then it will be created at
        ``/opt/salt-genesis.<random_uuid>``. This directory will be unmounted
        and removed when the process is finished.

    pkg_cache
        This points to a directory containing a cache of package files to be
        copied to the image. It does not need to be specified.

    pkgs
        A list of packages to be installed on this image. For RedHat, this
        will include ``yum``, ``centos-release`` and ``iputils`` by default.

    exclude_pkgs
        A list of packages to be excluded. If you do not want to install the
        defaults, you need to include them in this list.

    epel_url
        The URL to download the EPEL release package from.

    CLI Examples:

    .. code-block:: bash

        salt myminion genesis.bootstrap pacman /root/arch
        salt myminion genesis.bootstrap rpm /root/redhat
        salt myminion genesis.bootstrap deb /root/wheezy arch=amd64             flavor=wheezy static_qemu=/usr/bin/qemu-x86_64-static

    )r�sparsez(The img_format must be "sparse" or "dir"r�file.directory_exists�
file.mkdir�ErrorNr
z/An img_size must be specified for a sparse filez/opt/salt-genesis.�root�755�cmd.runZ	fallocatez-lF�Zpython_shell�
losetup -f�First loop device is %s�losetup � �Second loop device is %s�@�losetup -o �mount.mount)rr)�pkgs�exclude_pkgs�epel_urlr)�arch�flavor�repo_url�static_qemurrr)�
img_formatrrz
disk.blkidzfile.replacez/boot/grub/grub.cfgz$ad4103fa-d940-47ca-8506-301d8071d467ZUUID�mount.umount�losetup -d z
file.rmdir)r�__salt__�	Exception�salt�utils�stringutils�
to_unicode�pprint�pformat�uuidZuuid4�_mkpart�log�debug�str�_populate_cache�_bootstrap_yum�_bootstrap_deb�_bootstrap_pacman)�platformrr$�	fs_format�fs_optsr r!r"r#Zimg_size�	mount_dir�	pkg_cacherrr�exc�loop1�loop2�startZblkinforrr	�	bootstrap+s�c$�����	�

��rAc		CsHtd|d�tdd�}t�d|�tdd|�d|���td|�}td	�d
}|dd}td
|d||d�td|ddd�td|�}tdd�}t�d|�|�d
�}tdd|�d|�d|���t|||�td||�tddddddd|�d�|fdd�td |�tdd!|���tdd!|���|S)"zP
    Make a partition, and make it bootable

    .. versionadded:: 2015.8.0
    zpartition.mklabelZmsdosrrrrrzpartition.listr�B�info�sizezpartition.mkpartZprimary)r@�endz
partition.set�1Zboot�onrrrzgrub-installz--target=i386-pcz--debugz--no-floppyz--modules=part_msdos linuxz--boot-directory=z/bootFrr%r&)r'r1r2r3�rstrip�_mkfs)	rr9r:r;r>Z	part_infor@rEr?rrr	r0�s>

�	�r0cCsr|duri}|dvrtd||fi|��dS|dvr'td|fi|��dS|dvr7td|fi|��dSdS)zX
    Make a filesystem using the appropriate module

    .. versionadded:: 2015.8.0
    N)rZext3Zext4z
extfs.mkfs)Zbtrfsz
btrfs.mkfs)Zxfszxfs.mkfs�r')rr9r:rrr	rIs�rIcCsT|sdStj�|�sdS|dkr|�d�}td|ddd�td||ddd	�dS)
z`
    If a ``pkg_cache`` directory is specified, then use it to populate the
    disk image.
    Nrz/var/cache/pacman/pkgrrr�	file.copyT)�recurseZremove_existing)�os�path�isdirr')r8r<r;Z	cache_dirrrr	r4s
r4z	/etc/yum*c	CsZ|durg}n
t|t�r|�d�}d}|D]}||vr |�|�q|dur(g}n
t|t�r2|�d�}|D]}|�|�q4t|�dd�t�d�D�}tddj	t
�|�d	�|�d
��tddj	t
�|�d	�|�d
��tddj	t
�|�t
�|�d
��dddt
�|���dg|}td|dd�d|vr�tdddt
�|���d|fdd�dSdS)aD
    Bootstrap an image using the yum tools

    root
        The root of the image to install to. Will be created as a directory if
        it does not exist. (e.x.: /root/arch)

    pkg_confs
        The location of the conf files to copy into the image, to point yum
        to the right repos and configuration.

    pkgs
        A list of packages to be installed on this image. For RedHat, this
        will include ``yum``, ``centos-release`` and ``iputils`` by default.

    exclude_pkgs
        A list of packages to be excluded. If you do not want to install the
        defaults, you need to include them in this list.

    epel_url
        The URL to download the EPEL release package from.

    TODO: Set up a pre-install overlay, to copy files into /etc/ and so on,
        which are required for the install to work.
    N�,)rzcentos-releaseZiputilscS�g|]	}|�d�r|�qS)�release)�endswith��.0Zrfrrr	�
<listcomp>X�z"_bootstrap_yum.<locals>.<listcomp>�/etcrz$cp /etc/resolv/conf {rfs} {root}/etcr)rZrfszcp -r {rfs} {root}/etczcp -r {confs} {root}/etc)rZconfsr�installz--installroot=z-yFrzepel-releaserz--root=z-Uvh)
�
isinstancer3�split�append�remove�_make_nodesrM�listdirr'�format�shlex�quote�join)	r�	pkg_confsrrr�default_pkgs�pkgZ
release_filesZyum_argsrrr	r5%s\ 


�

��������
��r5c	Csb|durd}tjj�d�st�d�dS|r&tjjj�|�s&t�d|�dSt|t	t
f�r2d�|�}t|t	t
f�r>d�|�}ddd	t�
|�g}|rR|d
t�
|�g7}|r]|dt�
|�g7}|t�
|�t�
|�t�
|�g7}td|dd
�|r�tddjt�
|�t�
|�d��ddddddd�}tddjt�
|�d�|d�tddt�
|��d�|d�dS)a�
    Bootstrap an image using the Debian tools

    root
        The root of the image to install to. Will be created as a directory if
        it does not exist. (e.x.: /root/wheezy)

    arch
        Architecture of the target image. (e.x.: amd64)

    flavor
        Flavor of Debian to install. (e.x.: wheezy)

    repo_url
        Base URL for the mirror to install from.
        (e.x.: http://ftp.debian.org/debian/)

    static_qemu
        Local path to the static qemu binary required for this arch.
        (e.x.: /usr/bin/qemu-amd64-static)

    pkgs
        A list of packages to be installed on this image.

    exclude_pkgs
        A list of packages to be excluded.
    Nzhttp://ftp.debian.org/debian/rz+Required tool debootstrap is not installed.Fz.Required tool qemu not present/readable at: %srPz	--foreignz--archz	--includez	--excluderrzcp {qemu} {root}/usr/bin/)ZqemurZnoninteractive�true�Cz/sbin:/bin:/usr/bin)ZDEBIAN_FRONTENDZDEBCONF_NONINTERACTIVE_SEEN�LC_ALL�LANGUAGE�LANG�PATHz5chroot {root} /debootstrap/debootstrap --second-stage)r)�envzchroot z dpkg --configure -a)r)r*rN�whichr1�error�validateZ
is_executablerZ�list�tuplercrarbr'r`)	rr r!r"r#rrZdeb_argsrmrrr	r6xsV%


������"r6�/etc/pacman*c
Cs�t|�|durg}n
t|t�r|�d�}d}|D]}||vr$|�|�q|dur,g}n
t|t�r6|�d�}|D]}|�|�q8|dkr^td|�d�dddd	�td|�d
�d
ddd	�td|�d�d
d
d�dd�t�d�D�}|D]}tdd|�dt	�
|��d��qvtdd|�d�dd�dddt	�
|�dg|}	td|	dd�|dkr�td|�d��td|�d
��dSdS) a)
    Bootstrap an image using the pacman tools

    root
        The root of the image to install to. Will be created as a directory if
        it does not exist. (e.x.: /root/arch)

    pkg_confs
        The location of the conf files to copy into the image, to point pacman
        to the right repos and configuration.

    img_format
        The image format to be used. The ``dir`` type needs no special
        treatment, but others need special treatment.

    pkgs
        A list of packages to be installed on this image. For Arch Linux, this
        will include ``pacman``, ``linux``, ``grub``, and ``systemd-sysvcompat``
        by default.

    exclude_pkgs
        A list of packages to be excluded. If you do not want to install the
        defaults, you need to include them in this list.
    NrP)r�linuxzsystemd-sysvcompatZgrubrr�/proc��bind)Zfstype�opts�/devrz/var/lib/pacman/localrrcSrQ)zpacman.)�
startswithrTrrr	rVrWz%_bootstrap_pacman.<locals>.<listcomp>rXrzcp -r /etc/rrKz/var/lib/pacman/syncT)rLrz--noconfirmz-rz-SFrr%)r^rZr3r[r\r]r'rMr_rarb)
rrdr$rrrerfZ	pac_filesZpac_fileZpacman_argsrrr	r7�s@


�

"��r7cCsd|�d�dddf|�d�dddf|�d�dddf|�d�dddf|�d�dddff}|�d	�d
ddddd
f|�d�d
ddddd
f|�d�d
ddddd
f|�d�d
ddddd
f|�d�d
ddddd
f|�d�d
ddddd
f|�d�d
dddddf|�d�d
ddddd
f|�d�ddddddf|�d�d
ddddd
ff
}|D]}td |�q�|D]}td!|�q�d"S)#z�
    Make the minimum number of nodes inside of /dev/. Based on:

    https://wiki.archlinux.org/index.php/Linux_Containers
    rXrrryruz/dev/ptsz/dev/shmZ1755z	/dev/null�c��Z666z	/dev/zero�z/dev/random�z/dev/urandom�	z/dev/ttyrz	/dev/tty0�z/dev/consoleZ600z	/dev/full�z/dev/initctl�pz	/dev/ptmx�rz
file.mknodNrJ)r�dirsZnodesrNrrr	r^s,�	�
�r^cCs>i}tD]}d||<t|D]
}tjj�|�sd||<qq|S)z�
    Return which platforms are available

    CLI Example:

    .. code-block:: bash

        salt myminion genesis.avail_platforms
    TF)�CMD_MAPr)r*rNrn)�retr8�cmdrrr	�avail_platforms=s
��r��tar�bzip2cC�|dkr
t||||�dSdS)z�
    Pack up a directory structure, into a specific format

    CLI Examples:

    .. code-block:: bash

        salt myminion genesis.pack centos /root/centos
        salt myminion genesis.pack centos /root/centos pack_format='tar'
    r�N)�_tar)�namerrN�pack_format�compressrrr	�packPs�r��bz2cCr�)z�
    Unpack an image into a directory structure

    CLI Example:

    .. code-block:: bash

        salt myminion genesis.unpack centos /root/centos
    r�N)�_untar)r��destrNr�r�rrr	�unpack_s
�r�c	
Cs�|dur
tj�tjjd�}td|�s:ztd|�Wnty9}zdtjj	�
t�|��iWYd}~Sd}~wwt
|�\}}|�d|�d|��}td|�d	�|d
|d�}dS)z'
    Pack up image in a tar format
    N�imgrrr�/�.tar.�archive.tarZpcf�.)�options�tarfileZsourcesr��rMrNrcr)ZsyspathsZBASE_FILE_ROOTS_DIRr'r(r*r+r,r-r.�	_compress)	r�rrNr�r=�compression�extr��outrrr	r�ms"$��
�r�c	
Cs�|dur
tj�tjjd�}|s|}td|�s>ztd|�Wnty=}zdtjj	�
t�|��iWYd}~Sd}~wwt
|�\}}|�d|�d|��}td|�d	�||d
�}dS)z4
    Unpack a tarball to be used as a container
    Nr�rrrr�r�r�Zxf)r�r�r�r�)	r�r�rNr�r=r�r�r�r�rrr	r��s$$��
�r�cCsH|dvrd}d}||fS|dvrd}d}||fS|dvr d}d	}||fS)
z#
    Resolve compression flags
    )r�r��jr�r�)�gz�gzip�zr�r�)�xz�a�Jr�r�r)r�r�r�rrr	r��s��r�c	Cs�tj�|�s
tjj�|�}|durg}tdd|fdd�}|��D]W}|��s(q!d}d|vrH|�	d�}|d	���	�}tj�|d
�rG|d
}n|���	�}tj�|d
�rZ|d
}|rx||vrx|�
|�t||�}|D]}||vrw|�
|�qlq!|S)al
    Recurse through a set of dependencies reported by ``ldd``, to find
    associated dependencies.

    Please note that this does not necessarily resolve all (non-package)
    dependencies for a file; but it does help.

    CLI Example:

    .. code-block:: bash

        salt myminion genesis.ldd_deps bash
        salt myminion genesis.ldd_deps /bin/bash
    NrZlddFrrvz=>z => r|r)rMrN�existsr)r*rnr'�
splitlines�stripr[r\�ldd_deps)	�filenamer�r��lineZdep_path�compsZ	dep_compsZnew_depsZdeprrr	r��s6
�


�r�cCsL|dkrtjj�||�S|dkrtjj�||�S|dkr$tjj�||�SdS)al
    Convert an installation file/script to an SLS file. Currently supports
    ``kickstart``, ``preseed``, and ``autoyast``.

    CLI Examples:

    .. code-block:: bash

        salt <minion> genesis.mksls kickstart /path/to/kickstart.cfg
        salt <minion> genesis.mksls kickstart /path/to/kickstart.cfg /path/to/dest.sls

    .. versionadded:: 2015.8.0
    �	kickstart�preseedZautoyastN)r)r*r��mkslsr�Zyast)�fmt�src�dstrrr	r��s�r�)N)NNNN)rsrNN)Nr�r�)NNr�r�)Nr�)NNr�)&�__doc__�loggingrMr-rar/Z
salt.syspathsr)Zsalt.utils.kickstartZsalt.utils.pathZsalt.utils.preseedZsalt.utils.stringutilsZsalt.utils.validate.pathZsalt.utils.yastZsalt.exceptionsr�	getLogger�__name__r1r�ZEPEL_URLr
rAr0rIr4r5r6r7r^r�r�r�r�r�r�r�r�rrrr	�<module>s�
��
�1
(
�W
�^
�G"




/