HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/zone.cpython-310.pyc
o

�N�g��@s�dZddlZddlZddlZddlZddlmZddlm	Z	m
Z
ddlmZ
ddlmZe�e�ZddiZd	Zd
d�Zdd
�Zdd�Zdd�Zdd�Zd)dd�Zd*dd�Zd)dd�Zd+dd�Zd,dd�Zd)dd �Zd)d!d"�Z d#d$�Z!d-d%d&�Z"d'd(�Z#dS).a�
Management of Solaris Zones

:maintainer:    Jorge Schrauwen <sjorge@blackdot.be>
:maturity:      new
:depends:       salt.modules.zoneadm, salt.modules.zonecfg
:platform:      solaris

.. versionadded:: 2017.7.0

Below are some examples of how to use this state.
Lets start with creating a zone and installing it.

.. code-block:: yaml

    omipkg1_configuration:
      zone.present:
        - name: omipkg1
        - brand: ipkg
        - zonepath: /zones/omipkg1
        - properties:
          - autoboot: true
          - ip-type: exclusive
          - cpu-shares: 50
        - resources:
          - attr:
            - name: owner
            - value: Jorge Schrauwen
            - type: string
          - attr:
            - name: description
            - value: OmniOS ipkg zone for testing
            - type: string
          - capped-memory:
            - physical: 64M
    omipkg1_installation:
      zone.installed:
        - name: omipkg1
        - require:
            - zone: omipkg1_configuration
    omipkg1_running:
      zone.booted:
        - name: omipkg1
        - require:
            - zone: omipkg1_installation

A zone without network access is not very useful. We could update
the zone.present state in the example above to add a network interface
or we could use a separate state for this.

.. code-block:: yaml

    omipkg1_network:
      zone.resource_present:
        - name: omipkg1
        - resource_type: net
        - resource_selector_property: mac-addr
        - resource_selector_value: "02:08:20:a2:a3:10"
        - physical: znic1
        - require:
            - zone: omipkg1_configuration

Since this is a single tenant system having the owner attribute is pointless.
Let's remove that attribute.

.. note::
    The following state run the omipkg1_configuration state will add it again!
    If the entire configuration is managed it would be better to add resource_prune
    and optionally the resource_selector_property properties to the resource.

.. code-block:: yaml

    omipkg1_strip_owner:
      zone.resource_present:
        - name: omipkg1
        - resource_type: attr
        - resource_selector_property: name
        - resource_selector_value: owner
        - require:
            - zone: omipkg1_configuration

Let's bump the zone's CPU shares a bit.

.. note::
    The following state run the omipkg1_configuration state will set it to 50 again.
    Update the entire zone configuration is managed you should update it there instead.

.. code-block:: yaml

    omipkg1_more_cpu:
      zone.property_present:
        - name: omipkg1
        - property: cpu-shares
        - value: 100

Or we can remove the limit altogether!

.. note::
    The following state run the omipkg1_configuration state will set it to 50 again.
    Update the entire zone configuration is managed you should set the
    property to None (nothing after the :) instead.

.. code-block:: yaml

    omipkg1_no_cpu:
      zone.property_absent:
        - name: omipkg1
        - property: cpu-shares

�N)�CommandExecutionError)�_parse_value�#_zonecfg_resource_default_selectors)�merge)�OrderedDict�import_�import�zonecCs"dtvr
dtvr
dSdd�t�fS)z(
    Provides zone state on Solaris
    �zonecfg.create�zoneadm.installTFz7{} state module can only be loaded on Solaris platforms)�__salt__�format�__virtualname__�rr�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/zone.py�__virtual__�s��rcCs2|iddd�}t|�}tdddd�}||vr�td|dd�}||vs+||t|�kr~td	r4d|d
<ntd|||�}|d|d
<d
|vrL|d|d<|d
rht|�|d|<|ddkrfd�||�|d<|S|ddkr||ddkr|d�||�|d<|Sd|d
<d�||�|d<|Sd|d
<d�|�|d<|S)z�
    Ensure property has a certain value

    name : string
        name of the zone
    property : string
        name of property
    value : string
        value of property

    N���name�changes�result�comment�zoneadm.listT��	installed�
configured�zonecfg.info�Zshow_all�testrzzonecfg.set_property�status�messages�messagerrz%The property {} is was updated to {}.z)The property {} is was not updated to {}!z%The property {} is already set to {}.F�AThe zone {} is not in the configured, installed, or booted state.�rr�__opts__r
)r�property�value�ret�zones�zonecfg�zonecfg_resrrr�property_present�sH
��������r+cCsL|iddd�}tdddd�}||vr�td|dd�}||vr�td	r(d|d
<ntd||�}td|dd�}|d|d
<d
|vrG|d|d<|d
rv||vrVd|d|<n||||krf|||d|<|ddkrtd|�d�|d<|S|ddkr�|ddkr�d�|�|d<|Sd|d
<d|�d�|d<|Sd|d
<d�|�|d<|S)a(
    Ensure property is absent

    name : string
        name of the zone
    property : string
        name of property

    .. note::
        This does a zoneacfg clear call. So the property may be reset to a default value!
        Does has the side effect of always having to be called.

    NrrrTrrrrrzzonecfg.clear_propertyrr r!rrz
The property z
 was cleared!z$The property {} did not get cleared!z does not exist!Fr")rr$r
)rr%r'r(r)r*Zzonecfg_newrrr�property_absent�sF
���
���r,c
Ks
|iddd�}tjjjd!i|��}t|�}|��D]\}}t||�||<qtdddd�}||v�r�td|dd�}	i}
|
�|�||
d	<||
d
<||
d<|rT||
|<||	v�ra|	|D�]}|ri|||k�r`d|d<|rxd
�||�|d<nd�|�|d<|D]?}t	�
d|||vr�||ndt||��|dkr�||vr�t||�d�||<||vr�d|d<q�||t||�kr�d|d<q�|ddu�r`tdr�d|d<ntdd!i|
��}
|
d|d<d|
vr�|
d|d<|d�rFi|d|<|r�i|d||<|d�r|ngD]"}|�rt||�|d|||<�qt||�|d||<�q|ddk�rE|�r>d�||�|d<q]d�|�|d<q]|ddk�r`|�rYd�||�|d<q]d�|�|d<q]|ddu�r�td�rrd|d<n"d|
v�rz|
d=tdd!i|
��}
|
d|d<d|
v�r�|
d|d<|d�r�i|d|<|�r�i|d||<|d�r�|ngD]"}|�r�t||�|d|||<�q�t||�|d||<�q�|ddk�r�d�||�|d<|S|ddk�r�d�||�|d<|Sd|d<d �|�|d<|S)"a�
    Ensure resource exists with provided properties

    name : string
        name of the zone
    resource_type : string
        type of resource
    resource_selector_property : string
        unique resource identifier
    resource_selector_value : string
        value for resource selection
    kwargs : string|int|...
        resource properties

    .. warning::
        Both resource_selector_property and resource_selector_value must be
        provided, some properties like ``name`` are already reserved by salt in
        states.

    .. note::
        You can set both resource_selector_property and resource_selector_value
        to None for resources that do not require them.

    NrrrTrrrr	�
resource_typeZresource_selectorrz!the {} resource {} is up to date.rzthe {} resource is up to date.z7zone.resource_preent - key=%s value=%s current_value=%sZncpusz.2frzzonecfg.update_resourcerr!rzThe {} resource {} was updated.zThe {} resource was updated.z#The {} resource {} was not updated.z The {} resource was not updated.zzonecfg.add_resourcezThe {} resource {} was added.z!The {} resource {} was not added.Fr"r)
�salt�utils�argsZclean_kwargsr�itemsr�updater
�log�debug�floatr$)rr-�resource_selector_property�resource_selector_value�kwargsr'�k�vr(r)Zzonecfg_kwargs�resource�keyr*rrr�resource_presents


�
��
�
�

�

��

��������������





����
���r=c	Cs�|iddd�}|rt|�}nd}tdddd�}||vr�td|dd�}||vr�||D]�}td	r7d|d
<q,|sttd||ddd�}|d
|d
<|d
rad|d|<|ddkr`d�|�|d<q,d|vrl|d|d<q,d�|�|d<q,|||kr�td||||d�}|d
|d
<|d
r�i|d|<d|d||<|ddkr�d�||�|d<q,d|vr�|d|d<q,d�||�|d<q,|d
dur�d|d
<d�||�|d<|Sd|d
<d�|�|d<|S)an
    Ensure resource is absent

    name : string
        name of the zone
    resource_type : string
        type of resource
    resource_selector_property : string
        unique resource identifier
    resource_selector_value : string
        value for resource selection

    .. warning::
        Both resource_selector_property and resource_selector_value must be provided, some properties
        like ```name``` are already reserved by salt in there states.

    .. note::
        You can set both resource_selector_property and resource_selector_value to None for
        resources that do not require them.

    NrrrTrrrrrzzonecfg.remove_resource)r	r-Zresource_keyZresource_valuer�removedrrzThe {} resource was removed.r r!z The {} resource was not removed.zThe {} resource {} was removed.z#The {} resource {} was not removed.zThe {} resource {} was absent.Fr"r#)	rr-r6r7r'r(r)r;r*rrr�resource_absent�s�

���
��
�������
���r?FcCs$|iddd�}tddd�}||vr\||ddkr(d|d	<d
|�d�|d<|Std
s3td||�}td
s;|drOd|d	<d|d|<d
|�d�|d<|Sd|d	<d|��|d<|Sg|d<|d�d|�d��|D]}||d|kr�|d�d�||��qmd|d	<d�|d�|d<|S)z�
    Ensure zone is booted

    name : string
        name of the zone
    single : boolean
        boot in single usermode

    NrrrT�r�state�runningr�Zone z already bootedrrzzoneadm.bootr�bootedrz bootedFzFailed to boot �	The zone z) is not in the installed or booted state.�uuid�?The zone {} has a uuid of {}, please use the zone name instead!�
�rr$�appendr
�join)rZsingler'r(�zoneadm_resr	rrrrD)sB
���
����rDTcCs2|iddd�}tddd�}||vrc||ddkr(d|d	<d
|�d�|d<|Std
s:|r4td|�ntd|�}td
sB|drVd|d	<d|d|<d
|�d�|d<|Sd|d	<d|��|d<|Sg|d<|d�d|�d��|D]}||d|kr�|d�d�||��qtd|d	<d�|d�|d<|S)z�
    Ensure zone is halted

    name : string
        name of the zone
    graceful : boolean
        use shutdown instead of halt if true

    NrrrTr@rArBrrCz already haltedrrzzoneadm.shutdown�zoneadm.haltr�haltedrz haltedFzFailed to halt rEz is not in the installed state.rFrGrHrI)rZgracefulr'r(rLr	rrrrN\sD
 ��
������rNcCs�|iddd�}tdddd�}||v�rtdrDd|d<d	�||�|d
<d|d|<td
|�rB|sBd|d<i|d<d�||�|d
<|Stjj��}td||�td
|�s�z	td||�Wn"ty�td
|�rstd|�d|d<d�||�|d
<Y|Swd|d<d�||�|d
<d|d|<|Std||�}|s�d|d<d�||�|d
<td
|�r�td|�|S|r�z	td||�Wn"ty�td
|�r�td|�d|d<d�||�|d
<Y|Swd|d<d�||�|d
<d|d|<|Sd|d<d�||�|d
<td
|��rtd|�|Sg|d
<|d
�d|�d��|D]}||d|k�r>|d
�d�||���q(d|d<d�	|d
�|d
<|S)z�
    Export a zones configuration

    name : string
        name of the zone
    path : string
        path of file to export too.
    replace : boolean
        replace the file if it exists

    NrrrTrrrz'Zone configartion for {} exported to {}rZexportedr�file.file_existsFz7File {} exists, zone configuration for {} not exported.zzonecfg.exportz	file.movezfile.removez1Unable to export zone configuration for {} to {}!z-Zone configuration for {} was exported to {}.z
file.get_diffz5Zone configuration for {} was already exported to {}.z7Unable to be re-export zone configuration for {} to {}!z0Zone configuration for {} was re-exported to {}.zCZone configuration for {} is different from the one exported to {}!rE� does not exist.rFrGrH)
rr$r
r.r/�filesZmkstemprrJrK)r�path�replacer'r(Zcfg_tmpZcfg_diffr	rrr�export�s�
���\���J���<���1���(���������rTc
Cs&|iddd�}tdddd�}||v�rtdr,d|d<d	�||�|d
<d|d|<|Std
|�r�td||�}|dsKd|d<d|�d�|d
<|Sd|d<d|d|<d	�||�|d
<|��dkr�td|d|�}|d|d<|dr�d|d|<d�||�|d
<n%g|d
<|d
�d�||��d|vr�|d
�|d�d�|d
�|d
<|��dkr�td|||�}	|	d|d<|	dr�d|d|<d�||�|d
<|Sg|d
<|d
�d�||��d|	vr�|d
�|	d�d�|d
�|d
<|Sd|d<d|�d �|d
<|Sd|d<d!�|�|d
<|S)"a�
    Import a zones configuration

    name : string
        name of the zone
    path : string
        path of the configuration file to import
    mode : string
        either import, install, or attach
    nodataset : boolean
        do not create a ZFS file system
    brand_opts : boolean
        brand specific options to pass

    .. note::
        The mode argument can be set to ``import``, ``install``, or ``attach``.
        ``import``: will only import the configuration
        ``install``: will import and then try to install the zone
        ``attach``: will import and then try to attach of the zone

    .. code-block:: yaml

        omipkg1:
          zone.import:
            - path: /foo/bar/baz
    NrrrTrrrzZone {} was imported from {}.rZimportedrrOzzonecfg.importrFz(Unable to import zone configuration for �!�attach�zoneadm.attach�attachedzZone {} was attached from {}.z!Failed to attach zone {} from {}!r!rH�installrrzZone {} was installed from {}.z"Failed to install zone {} from {}!z	The file z# does not exists, unable to import!z4Zone {} already exists, not importing configuration.)rr$r
�lowerrJrK)
rrR�mode�	nodataset�
brand_optsr'r(Z
res_import�
res_attach�res_installrrrrs�
�B�<��
�����������cCs�|idgd�}|sg}|sg}|�td|i��|�td|i��tdddd�}tdr<d|d	<|d
�d|�d��||vrntdrMd
di}g|d
<ntd|||�}|d
rnd|d	<d|d|<|d
�d|�d��td�s�d|d	<t|t�r�|D]i}t|t�r�t|�dkr�t�d|�q~|�	�D]P\}	}
d}|
s�t
||	�}n|
r�t||	|
�}|r�|d	r�|d	nd|d	<|d
�|d
�t|d�dkr�d|dvr�i|dd<t|dd|d�|dd<q�q~t|t��r�|D]�}t|t�r�t|�dk�rt�d|�q�|�	�D]�\}	}
td|dd�}
i}|	|d<t|
t��r.|
D]
}|�
t|���q#d}d}d|v�r>|d}|d=d|v�rJ|d}|d=|�sV|	tv�rVt|	}d}|�rmt||d||�rh||ndd�}n||d<||v�r}|||d<nd|d<||d <td#i|��}|�r�|d	�r�|d	nd|d	<|d
�|d
�t|d�dk�r�d!|dv�r�i|dd!<t|dd!|d�|dd!<�q	q�t|d
t��r�d"�|d
�|d
<|S)$a3
    Ensure a zone with certain properties and resources

    name : string
        name of the zone
    brand : string
        brand of the zone
    zonepath : string
        path of the zone
    properties : list of key-value pairs
        dict of properties
    resources : list of key-value pairs
        dict of resources

    .. note::
        If the zone does not exist it will not be installed.
        You can use the ```zone.installed``` state for this.

    .. note::
        Default resource selectors:
            - fs: dir
            - net: mac-addr
            - device: match
            - rctl: name
            - attr: name
            - dataset: name
            - admin: user

    .. warning::
        Properties and resource will not be removed when they
        are absent from the state!

        For properties, simple set them to ```None```.

        For resources, add the ```resource_prune``` property
        and set it to ```True```. Also specify the
        ```resource_selector_property``` if the default is not
        the one you want.

    Nr�brand�zonepathrTrrrrz5Cannot determine of changes would happen to the zone �.rr
�createdrrEz
 was created.�z+zone.present - failed to parse property: %sFrr%z+zone.present - failed to parse resource: %srrr-�resource_pruner6)r6r7r7rr;rHr)rJrrr$�
isinstance�list�lenr3�warningr1r,r+�
merge_dictr2�dictrr?r=rK)rr`raZ
propertiesZ	resourcesr'r(Z
res_createZpropr<r&�resr;r)Zresource_cfgZrespvrer6rrr�presentvs�)
�


���

��
����

�����>rmcCsX|iddd�}tdddd�}||v�rtdr,d|d<d	|d
|<d|�d�|d
<|Sd|d<|r�||ddvr�td|�}td|�}|d|d<|dr_d|d
|<d|�d�|d
<nrg|d
<|d
�d|�d��d|vr{|d
�|d�d�|d
�|d
<nL||ddkr�td|�}|d|d<|dr�d|d
|<d|�d�|d
<n%g|d
<|d
�d|�d��d|vr�|d
�|d�d�|d
�|d
<|d�rtd|�}|d|d<|dr�d |d
|<d|�d!�|d
<|Sg|d
<|d
�d"|�d��d|v�r|d
�|d�d�|d
�|d
<|Sd|d<d|�d#�|d
<|S)$z�
    Ensure a zone is absent

    name : string
        name of the zone
    uninstall : boolean
        when true, uninstall instead of detaching the zone first.

    NrrrTrrrr>rrCz
 was removed.rrA)rBrrM�zoneadm.uninstallr�uninstalledrE� was uninstalled.�Failed to uninstall zone rUr!rHr�zoneadm.detach�detached� was detached.�Failed to detach zone zzonecfg.deleteZdeletedz was delete.zFailed to delete zone rP�rr$rJrK)rZ	uninstallr'r(Zres_halt�
res_uninstall�
res_detachZ
res_deleterrr�absents`

,�
�
�rycCs|iddd�}tdddd�}||vrz||ddkrltd	r$d
di}ntd||�}|d
|d<|drEd
|d|<d|�d�|d<|Sg|d<|d�d|�d��d|vra|d�|d�d�|d�|d<|Sd|d<d|�d�|d<|Sd|d<d|�d�|d<|S)z�
    Ensure zone is attached

    name : string
        name of the zone
    force : boolean
        force attach the zone

    NrrrTrrArrrrWrrXrrEz was attached.rzFailed to attach zone rUr!rH�zone z already attached.F� is not configured!rv)r�forcer'r(r^rrrrX_s0

���rXcC�|iddd�}tdddd�}||vry||ddkrktd	r$d
di}ntd|�}|d
|d<|drDd
|d|<d|�d�|d<|Sg|d<|d�d|�d��d|vr`|d�|d�d�|d�|d<|Sd|d<d|�d�|d<|Sd|d<d|�d�|d<|S)zN
    Ensure zone is detached

    name : string
        name of the zone

    NrrrTrrArrrrrrrsrrErtrrurUr!rHrzz already detached.r{rv)rr'r(rxrrrrs��0
�	��rscCs|iddd�}tdddd�}||vr{||ddkrmtd	r$d
di}ntd|||�}|d
|d<|drFd
|d|<d|�d�|d<|Sg|d<|d�d|�d��d|vrb|d�|d�d�|d�|d<|Sd|d<d|�d�|d<|Sd|d<d|�d�|d<|S)z�
    Ensure zone is installed

    name : string
        name of the zone
    nodataset : boolean
        do not create a ZFS file system
    brand_opts : boolean
        brand specific options to pass

    NrrrTrrArrrrrrrrEz was installed.rzFailed to install zone rUr!rHrzz already installed.Fr{rv)rr\r]r'r(r_rrrr�s0
���rcCr})zQ
    Ensure zone is uninstalled

    name : string
        name of the zone

    NrrrTrrArrrrnrrorrErprrqrUr!rHrzz already uninstalled.r{rv)rr'r(rwrrrro�r~ro)F)T)rFN)NN)FN)$�__doc__�loggingZsalt.utils.argsr.Zsalt.utils.atomicfileZsalt.utils.filesZsalt.exceptionsrZsalt.modules.zonecfgrrZsalt.utils.dictupdaterrjZsalt.utils.odictr�	getLogger�__name__r3Z__func_alias__rrr+r,r=r?rDrNrTrrmryrXrsrrorrrr�<module>s<o
�:9;
i
3
5
{
j
*
@'
&)