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

�N�g�8�@s�dZddlZddlmmZdd�Zdd�Zddd	�Zd
d�Z	ddd
�Z
ddd�Zddd�Zddd�Z
ddd�Zddd�Zddd�ZdS)z�
Using states instead of maps to deploy clouds
=============================================

.. versionadded:: 2014.1.0

Use this minion to spin up a cloud instance:

.. code-block:: yaml

    my-ec2-instance:
      cloud.profile:
        my-ec2-config
�NcCsdtvrdSdS)z@
    Only load if the cloud module is available in __salt__
    �
cloud.profileT)Fz cloud module could not be loaded)�__salt__�rr�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/cloud.py�__virtual__srcCs:|iddd�}t�|d�rd|d<d|d<|Sd|d<|S)	N���name�changes�result�commentza-zA-Z0-9._-zInvalid characters in name.rFrT)�sucZ
check_name)r	�retrrr�_check_namesrrcCs|si}|d||d�S)NT)r	rr
rr)r	rr
rrr�_valid)srcCs(t�dd�}tdd|d�}|td<|S)N�testF�cloud.action�
show_instance�Zfun�names)�__opts__�getr)rr�instancerrr�
_get_instance/src	Ks�|iddd�}td}|dur0t|t�s|st|dd�Snt|t�r0||dd�d	kr0t|dd�S|durUt|t�sB|rAt|d
d�Snt|t�rU||dd�d	krUt|d
d�Std|dd�rjd|d
<d|��|d<|Stdrxd|�d�|d<|Std||fd|i|��}|r�d|vr�||d<d|d
<d�||t�|��|d<|S|r�d|vr�d|d
<d�|t|d�|d<|Sd|d
<d�|t�|d<|S)ab
    Spin up a single instance on a cloud provider, using salt-cloud. This state
    does not take a profile argument; rather, it takes the arguments that would
    normally be configured as part of the state.

    Note that while this function does take any configuration argument that
    would normally be used to create an instance, it will not verify the state
    of any of those arguments on an existing instance. Stateful properties of
    an instance should be configured using their own individual state (i.e.,
    cloud.tagged, cloud.untagged, etc).

    name
        The name of the instance to create

    cloud_provider
        The name of the cloud provider to use

    onlyif
        Do run the state only if is unless succeed

    unless
        Do not run the state at least unless succeed

    opts
        Any extra opts that need to be used
    Nrr�cmd.retcode�onlyif condition is false�rT�Zpython_shellr�unless condition is true�cloud.has_instance�r	�providerr�Already present instance rr�	Instance � needs to be createdzcloud.create�opts�Errorr
zCCreated instance {} using provider {} and the following options: {}F�1Failed to create instance {} using profile {}: {}zNFailed to create instance {} using profile {}, please check your configuration)	r�
isinstance�strrr�format�pprintZpformat�profile)	r	Zcloud_provider�onlyif�unlessr%�kwargsr�retcode�inforrr�present8s^
�

�
������r2cCsl|iddd�}td}|dur0t|t�s|st|dd�Snt|t�r0||dd�d	kr0t|dd�S|durUt|t�sB|rAt|d
d�Snt|t�rU||dd�d	krUt|d
d�Std|dd�sjd|d
<d|��|d<|Stdrxd|�d�|d<|Std|�}|r�d|vr�||d<d|d
<d|��|d<|Sd|vr�d|d
<d�||d�|d<|Sd|d
<d|��|d<|S)a�
    Ensure that no instances with the specified names exist.

    CAUTION: This is a destructive state, which will search all
    configured cloud providers for the named instance,
    and destroy it.

    name
        The name of the instance to destroy

    onlyif
        Do run the state only if is unless succeed

    unless
        Do not run the state at least unless succeed

    NrrrrrTrrrrr rzAlready absent instance rrr#z needs to be destroyedz
cloud.destroyr&r
zDestroyed instance Fz!Failed to destroy instance {}: {}zFailed to destroy instance )rr(r)rrr*)r	r-r.rr0r1rrr�absent�sR
�

�

���r3cKs|iddd�}td}|dur0t|t�s|st|dd�Snt|t�r0||dd�d	kr0t|dd�S|durUt|t�sB|rAt|d
d�Snt|t�rU||dd�d	krUt|d
d�St|g�}|rrtdd�|D��srd|d
<d|��|d<|Stdr�d|�d�|d<|Std||||d�}	|	�dd�}
d}t|	t�r�|	�|i�}t|t�r�|�dd�}|
p�|}
|	r�|
s�|	�|�}d|d
<d�	||�}d|vr�|d|d<|�d|�|d<|S|	|d<||d<|S|
r�d|d
<d�	|||
�d|�d��
��|d<|Sd|d
<d�	||�|d<|S)a0
    Create a single instance on a cloud provider, using a salt-cloud profile.

    Note that while profiles used this function do take any configuration
    argument that would normally be used to create an instance using a profile,
    this state will not verify the state of any of those arguments on an
    existing instance. Stateful properties of an instance should be configured
    using their own individual state (i.e., cloud.tagged, cloud.untagged, etc).

    name
        The name of the instance to create

    profile
        The name of the cloud profile to use

    onlyif
        Do run the state only if is unless succeed

    unless
        Do not run the state at least unless succeed

    kwargs
        Any profile override or addition

    opts
        Any extra opts that need to be used
    NrrrrrTrrrcss�|]}d|vVqdS)zNot ActionedNr)�.0�keyrrr�	<genexpr>�s�zprofile.<locals>.<genexpr>rr"rrr#r$r)Zvm_overridesr%r&z$Created instance {} using profile {}r
Fr'�
z-Failed to create instance {} using profile {})rr(r)rr�anyrr�dictr*�strip)r	r,r-r.r%r/rr0rr1Z
main_errorZ
name_errorZsubinfo�errorZ	node_infoZdefault_msgrrrr,�s|
�

�




������r,cKs�t|�}|ds
|Std|d�}||vr"d|��|d<d|d<|Stdr4d|�d	�|d<d
|d<|Stdd||d�|��}|rWd|d<d|�d
�|d<d
|d�|d<|Sd|d<d|�d�|d<|S)�+
    Check that a block volume exists.
    r�cloud.volume_list�r!zVolume exists: rTr�Volume z will be created.Nzcloud.volume_create�rr!� was created��old�newr
Fz failed to create.r�rrr�r	r!r/r�volumes�responserrr�volume_present&s*�rIcKs�t|�}|ds
|Std|d�}||vrd|d<d|d<|Stdr1d|�d	�|d<d
|d<|Stdd||d�|��}|rVd|d<d|�d
�|d<|||d�|d<|Sd|d<d|�d�|d<|S)r<rr=r>zVolume is absent.rTrr?z will be deleted.Nzcloud.volume_deleter@z was deletedrBr
Fz failed to delete.rrErFrrr�
volume_absentDs*�rJc	KsVt|�}|ds
|St|�}|ds|Std|d�}tdd|d�}||vrC||drC||}djdi||��|d	<d
|d<|S||vrUd|�d�|d	<d
|d<|S|sed|�d�|d	<d
|d<|Stdrwd|�d�|d	<d|d<|Stdd|||d�|��}|r�d
|d<d|�d�|d	<|||d�|d<|Sd
|d<d|�d�|d	<|S)z.
    Check if a block volume is attached.
    rr=r>rrr�attachmentsz0Volume {name} is already attached: {attachments}rTr?� does not existF�Server rz will be will be attached.Nzcloud.volume_attach�r!r�server_namerArBr
z failed to attach.r�rrr*r�	r	rOr!r/rrGrZvolumerHrrr�volume_attachedbsP
����rRc	Ksrt|�}|ds
|S|durt|�}|ds|Std|d�}|r+tdd|gd�}nd}||vrM||dsM||}d	jdi||��|d
<d|d<|S||vr_d|�d
�|d
<d|d<|S|ss|dursd|�d
�|d
<d|d<|Stdr�d|�d�|d
<d|d<|Stdd|||d�|��}|r�d|d<d|�d�|d
<|||d�|d<|Sd|d<d|�d�|d
<|S)zb
    Check if a block volume is attached.

    Returns True if server or Volume do not exist.
    rNr=r>rrrrKz4Volume {name} is not currently attached to anything.rTr?rLrMrz will be will be detached.zcloud.volume_detachrNrArBr
Fz failed to detach.rrPrQrrr�volume_detached�sV
����rS)rN)NNN)NN)N)�__doc__r+Zsalt.utils.cloud�utilsZcloudr
rrrrr2r3r,rIrJrRrSrrrr�<module>s	

	
Q
>
_

0