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/modules/__pycache__/boto_asg.cpython-310.pyc
o

�N�g���@srdZddlZddlZddlZddlZddlZddlZddl	Zddl
mmZddl
Ze�e�ZdZz>ddlZddlZddlmmZddlmmZddlZe�d��ej�ddlZddlmZe�d��ej�dZWne y{dZYnwd	d
�Z!dd�Z"d;d
d�Z#d;dd�Z$																		d<dd�Z%																		d<dd�Z&dd�Z'dd�Z(d=dd�Z)dd�Z*d;dd�Z+d;dd �Z,d;d!d"�Z-	d;d#d$�Z.						%																d>d&d'�Z/d;d(d)�Z0	d;d*d+�Z1d;d,d-�Z2d;d.d/�Z3	0	1	2					d?d3d4�Z4d5d6�Z5					d=d7d8�Z6					d=d9d:�Z7dS)@a�
Connection module for Amazon Autoscale Groups

.. versionadded:: 2014.7.0

:configuration: This module accepts explicit autoscale credentials but can also
    utilize IAM roles assigned to the instance through Instance Profiles.
    Dynamic credentials are then automatically obtained from AWS API and no
    further configuration is necessary. More Information available at:

    .. code-block:: text

        http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html

    If IAM roles are not used you need to specify them either in a pillar or
    in the minion's config file:

    .. code-block:: yaml

        asg.keyid: GKTADJGHEIQSXMKKRBJ08H
        asg.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

    A region may also be specified in the configuration:

    .. code-block:: yaml

        asg.region: us-east-1

    If a region is not specified, the default is us-east-1.

    It's also possible to specify key, keyid and region via a profile, either
    as a passed in dict, or as a string to pull from pillars or minion config:

    .. code-block:: yaml

        myprofile:
            keyid: GKTADJGHEIQSXMKKRBJ08H
            key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
            region: us-east-1

:depends: boto
:depends: boto3
�Nz%Y-%m-%dT%H:%M:%SZ�boto)�ClientError�boto3TFcCsFtjj��}|dur!tdtddtd�ttj	tdtdd��|S)	z,
    Only load if boto libraries exist.
    Tzboto.assign_funcs�asgz
ec2.autoscale)�module�pack�
_get_ec2_connzboto.get_connection_func�ec2)
�salt�utilsZversionsZcheck_boto_reqs�	__utils__�__name__�__salt__�setattr�sys�modules)Z
has_boto_reqs�r�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/boto_asg.py�__virtual__Qs�
�rcCstr
tdtddd�dSdS)Nzboto3.assign_funcsZautoscaling�_get_conn_autoscaling_boto3)Zget_conn_funcname)�HAS_BOTOrr
)�optsrrr�__init__bs

��rc

Cs�t||||d�}d}	z|j|gd�}|rWdSd|��}t�|�WdStjjyY}	z'|rI|	jdkrIt�d�t�	d	�|d
8}WYd}	~	q
t�
|	�WYd}	~	dSd}	~	ww)z�
    Check to see if an autoscale group exists.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_asg.exists myasg region=us-east-1
    ��region�key�keyid�profile�T��namesz-The autoscale group does not exist in region F�
Throttling�.Throttled by AWS API, retrying in 5 seconds...��N)�	_get_conn�get_all_groups�log�debugr�	exception�BotoServerError�code�time�sleep�error)
�namerrrr�conn�retriesZ_conn�msg�errr�existsis(





��r4c
CsFt||||d�}d}	z�|j|gd�}|r|d}niWSt��}gd�}	|	D]V}
|
dkrRg}|jD]}t��}
|j|
d<|j|
d	<|j|
d
<|�|
�q2||d<q'|
dkrat	||
��
d�||
<q'|
d
krvt	||
�}tdd�|D��||
<q't	||
�||
<q'|j|d�}g|d<|D]}|d�t
d|jfd|jfd|jfd|jfd|jfg��q�|j|d�}i|d<|D]0}d}|jr�|j��}t
d|jfd|jfdt|j�fd|j��fd|fd|jfg�|d|j<q�|WStjj�y"}z*|�r|jdk�rt �!d �t"�#d!�|d"8}WYd}~q
t �$|�iWYd}~Sd}~ww)#z�
    Get the configuration for an autoscale group.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_asg.get_config myasg region=us-east-1
    rrTrr)r/�availability_zones�default_cooldown�desired_capacity�health_check_period�health_check_type�launch_config_name�load_balancers�max_size�min_size�placement_group�vpc_zone_identifier�tags�termination_policies�suspended_processesr@r�value�propagate_at_launchr?�,rBcss�|]}|jVqdS)N)Zprocess_name)�.0�xrrr�	<genexpr>�s�zget_config.<locals>.<genexpr>��as_group�scaling_policiesr/�adjustment_type�scaling_adjustment�min_adjustment_step�cooldown�scheduled_actionsNr=r<r7�
start_time�end_time�
recurrencer!r"r#r$)%r%r&�odict�OrderedDictr@rrCrD�append�getattr�split�sorted�get_all_policies�dictr/rLrMrNrO�get_all_scheduled_actionsrR�	isoformatr=r<�intr7rQrSrr)r*r+r'r(r,r-r.)r/rrrrr0r1r�retZattrs�attr�_tags�tag�_tagrB�policies�policy�actions�actionrRr3rrr�
get_config�s�







���
��


��rhc!CsNt||||d�}t|t�rtjj�|�}t|t�r tjj�|�}t|t�r,tjj�|�}t|t�r8tjj�|�}g}|r�|D]F}z|�d�}WntyWt	�
d�YdSwz|�d�}Wntyot	�
d�YdSw|�dd�}tj||||d�}|�
|�q>t|
t�r�tjj�|
�}
t|t�r�tjj�|�}t|t�r�tjj�|�}d	}	z9tj||||||||||	|
|||
|d�}|�|�t|||�t|||�|r�|r�|�|||�t	�d|�Wd
Stjj�y&}z2|�r
|jd
k�r
t	�d�t�d�|d8}WYd}~q�t	�
|�d|f} t	�
| �WYd}~dSd}~ww)a
    Create an autoscale group.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_asg.create myasg mylc '["us-east-1a", "us-east-1e"]' 1 10 load_balancers='["myelb", "myelb2"]' tags='[{"key": "Name", value="myasg", "propagate_at_launch": True}]'
    rr�Tag missing key.FrC�Tag missing value.rD�rrCZresource_idrDrT)r/�
launch_configr5r=r<r7r;r6r9r8r>r@r?rArBzCreated ASG %sr!r"r#r$NzFailed to create ASG %s)r%�
isinstance�strr
r�json�loads�get�KeyErrorr'r.�	autoscale�TagrV�AutoScalingGroupZcreate_auto_scaling_group�_create_scaling_policies�_create_scheduled_actions�put_notification_configuration�inforr)r*r+r(r,r-)!r/r:r5r=r<r7r;r6r9r8r>r?r@rArBrKrPr�notification_arn�notification_typesrrrr0rarbrCrDrcr1�_asgr3r2rrr�create�s�"




�
��


�
�



��r}c&s�t||||d�}t||||d�}|sdSt|t�r tjj�|�}t|t�r,tjj�|�}t|t�r8tjj�|�}t|t�rDtjj�|�}t|
t�rPtjj�|
�}
t|t�r\tjj�|�}t|t�rhtjj�|�}|jd|gd�gd��	dg�}dd�|D�}g}g�|r�t
d	|�}|D]]}z|�	d
�}Wnty�t�
d�dd
|�d�fYSwz|�	d�}Wnty�t�
d�dd
|�d�fYSw|�	dd�}||||d�}||vr�|�|���|�q��fdd�|D�}d} 	z�tj|||||||||||	|
|||
d�}!|�r|�r|�|!||�|!��|�r/t�d|�|�dd�|D��|�rBt�d|�|�dd�|D��|!��|�rN|!�|�t�d|�|j|d�D]}"|j|"j|d��qZt|||�|j|d�D]}#|j|#j|d��qrt|||�WdSt j!j"�y�}$z8| �r�|$j#d k�r�t�d!�t$�%d"�| d#8} WYd$}$~$q�t�
|$�d%|��}%t�
|%�dt|$�fWYd$}$~$Sd$}$~$ww)&a
    Update an autoscale group.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_asg.update myasg mylc '["us-east-1a", "us-east-1e"]' 1 10 load_balancers='["myelb", "myelb2"]' tags='[{"key": "Name", value="myasg", "propagate_at_launch": True}]'
    r)Fzfailed to connect to AWSzauto-scaling-group)�NameZValues)ZFiltersZTagsc	Ss.g|]}|d|d|d|�dd�d��qS)ZKeyZValueZ
ResourceIdZPropagateAtLaunchFrk)rq�rF�trrr�
<listcomp>�s�
��zupdate.<locals>.<listcomp>z
boto3.orderedrriFzTag z missing keyrCrjz missing valuerDrkcsg|]}|�vr|�qSrrr�Zdesired_tagsrrr��srT)�
connectionr/rlr5r=r<r7r;r6r9r8r>r@r?rAz!Adding/updating tags from ASG: %scS�g|]
}tjdi|���qS�r�rsrtrrrrr���zDeleting tags from ASG: %scSr�r�r�rrrrr��r�zUpdated ASG %srI)Zautoscale_group)T�r!r"r#r$NzFailed to update ASG )&r%rrmrnr
rrorpZ
describe_tagsrqrrrr'r.rVrsrurx�updater(Zcreate_or_update_tags�delete_tagsZresume_processesZsuspend_processesryrZZ
delete_policyr/rvr\Zdelete_scheduled_actionrwrr)r*r+r,r-)&r/r:r5r=r<r7r;r6r9r8r>r?r@rArBrKrPrzr{rrrrr0Zconn3Zcurrent_tagsZadd_tagsrbrCrDrcr�r1r|reZscheduled_actionr3r2rr�rr�bs�#�






���	
�
��
��

�




��r�c
CsP|r$|D]!}tjj|d||d|d|�dd�|dd�}|�|�qdSdS)z*helper function to create scaling policiesr/rLrMrNNrO)r/�as_namerLrMrNrO)rsreZ
ScalingPolicyrqZcreate_scaling_policy)r0r�rKrerrrrvs
��rvcCs�|rV|��D]Q\}}d|vr t|dt�r tj�|dt�|d<d|vr6t|dt�r6tj�|dt�|d<|j|||�d�|�d�|�d�|�d�|�d�|�d�d�qdSdS)	z5
    Helper function to create scheduled actions
    rQrRr7r=r<rS)r7r=r<rQrRrSN)�itemsrmrn�datetime�strptime�DATE_FORMATZcreate_scheduled_group_actionrq)r0r�rPr/rgrrrrws,����rwc

Cs�t||||d�}d}	z|�||�d|�d�}t�|�WdStjjy^}	z1|rD|	jdkrDt�d�t	�
d�|d	8}WYd
}	~	q
t�|	�d|��}t�|�WYd
}	~	dSd
}	~	ww)
z�
    Delete an autoscale group.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_asg.delete myasg region=us-east-1
    rrTzDeleted autoscale group �.r!r"r#r$Nz!Failed to delete autoscale group F)r%Zdelete_auto_scaling_groupr'ryrr)r*r+r(r,r-r.)
r/�forcerrrrr0r1r2r3rrr�delete.s(






��r�cCs�t|t�rtjj�|�}tjj�	�}d|vr.|d�
�D]\}}tjj�|d�}|�
|�qd|vrJ|d�
�D]\}}tjj�|d�}|�
|�q8d|vrf|d}tjj�tjjj|dd�d�}|�
|�|��S)z�
    Get a mime multipart encoded string from a cloud-init dict. Currently
    supports boothooks, scripts and cloud-config.

    CLI Example:

    .. code-block:: bash

        salt myminion boto.get_cloud_init_mime <cloud init>
    Z	boothookszcloud-boothook�scriptsz
x-shellscriptzcloud-configF)Zdefault_flow_style)rmrnr
rrorp�email�mime�	multipartZ
MIMEMultipartr��textZMIMEText�attachZyamlZ	safe_dump�	as_string)Z
cloud_initZ_cloud_init�script_nameZscript�_scriptZcloud_configZ
_cloud_configrrr�get_cloud_init_mimeLs&
�
r�c

Cs�t||||d�}d}	z|j|gd�}|rWdSd�|�}t�|�WdStjjyY}	z'|rI|	jdkrIt�d�t	�
d	�|d
8}WYd}	~	q
t�|	�WYd}	~	dSd}	~	ww)z�
    Check for a launch configuration's existence.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_asg.launch_configuration_exists mylc
    rrTr�4The launch configuration does not exist in region {}Fr!r"r#r$N�r%�get_all_launch_configurations�formatr'r(rr)r*r+r,r-r.�
r/rrrrr0r1�lcr2r3rrr�launch_configuration_existsls,
�



��r�c
Cs�t||||d�}d}	z|��WStjjyF}z(|r5|jdkr5t�d�t�	d�|d8}WYd}~q
t�
|�gWYd}~Sd}~ww)	z�
    Fetch and return all Launch Configuration with details.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_asg.get_all_launch_configurations
    rrTr!r"r#r$N)r%r�rr)r*r+r'r(r,r-r.)rrrrr0r1r3rrrr��s




��r�cCst||||�}dd�|D�S)z�
    List all Launch Configurations.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_asg.list_launch_configurations
    cS�g|]}|j�qSr�r/)rF�rrrrr���z.list_launch_configurations.<locals>.<listcomp>)r�)rrrrr_rrr�list_launch_configurations�s
r�c

Cs�t||||d�}d}	z|j|gd�}|r|dWSd�|�}t�|�WdStjjy[}	z'|rK|	jdkrKt�d	�t	�
d
�|d8}WYd}	~	q
t�|	�WYd}	~	dSd}	~	ww)z�
    Dump details of a given launch configuration.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_asg.describe_launch_configuration mylc
    rrTrrr�Nr!r"r#r$r�r�rrr�describe_launch_configuration�s,
�



��r��m1.smallc%
Cs�t||||d�}t|t�rtjj�|�}t|
t�r tjj�|
�}
g}|
rPt��}|
D]"}|�	�D]\}}t�
�}|�	�D]
\}} t||| �q<|||<q0q*|g}|rc|sV|rctd|||||||d�}t
jd id|�d|�d|�d|�d|�d	|�d
|�d|	�d|�d
|�d|�d|
�d|�d|�d|�d|�d|�d|��}!d}"	z|�|!�t�d|�WdStjjy�}#z1|"r�|#jdkr�t�d�t�d�|"d8}"WYd}#~#q�t�|#�d|��}$t�|$�WYd}#~#dSd}#~#ww)!z�
    Create a launch configuration.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_asg.create_launch_configuration mylc image_id=ami-0b9c9f62 key_name='mykey' security_groups='["mygroup"]' instance_type='c3.2xlarge'
    rz"boto_secgroup.convert_to_group_ids)�vpc_id�vpc_namerrrrr/�image_id�key_name�security_groups�	user_data�
instance_type�	kernel_id�
ramdisk_id�block_device_mappings�instance_monitoring�
spot_price�instance_profile_name�
ebs_optimized�associate_public_ip_address�volume_type�delete_on_termination�iops�use_block_device_typesrTz
Created LC %sr!r"r#r$NzFailed to create LC Fr)r%rmrnr
rrorp�blockdevicemappingZBlockDeviceMappingr�ZEBSBlockDeviceTyperrrsZLaunchConfiguration�create_launch_configurationr'ryrr)r*r+r(r,r-r.)%r/r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr0Z_bdmsZ_block_device_mapZblock_device_dictZblock_device�
attributesZ
_block_device�	attributerCr�r1r3r2rrrr��s�#


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




��r�c	
Cs�t||||d�}d}	z|�|�t�d|�WdStjjyX}z1|r>|jdkr>t�d�t	�
d�|d8}WYd	}~q
t�|�d
|��}t�|�WYd	}~dSd	}~ww)z�
    Delete a launch configuration.

    CLI Example:

    .. code-block:: bash

        salt myminion boto_asg.delete_launch_configuration mylc
    rrTz
Deleted LC %sr!r"r#r$NzFailed to delete LC F)r%�delete_launch_configurationr'ryrr)r*r+r(r,r-r.)	r/rrrrr0r1r3r2rrrr�>s&






��r�c
Cs�t||||d�}d}|dkrZ|d8}z|j|d�}|D]
}	|	j|kr(|	jWSqt�d|�WdStjjyU}
z|
j	dkrA�t�
d	�t�d
�WYd}
~
nd}
~
ww|dkst�d�dS)a:
    Return the arn for a scaling policy in a specific autoscale group or None
    if not found. Mainly used as a helper method for boto_cloudwatch_alarm, for
    linking alarms to scaling policies.

    CLI Example:

    .. code-block:: bash

        salt '*' boto_asg.get_scaling_policy_arn mygroup mypolicy
    rrrr$rIzCould not convert: %sNr!z)Throttled by API, will retry in 5 secondsr#z"Maximum number of retries exceeded)
r%rZr/Z
policy_arnr'r.rr)r*Z
error_coder(r,r-)rJZscaling_policy_namerrrrr0r1rdrer3rrr�get_scaling_policy_arn[s,
�

���
r�c

Cs�t||||d�}d}	z!d}g}|dur*|j|d�}|dd�|D�7}|j}|dus|WStjjyb}	z(|rQ|	jd	krQt�d
�t	�
d�|d8}WYd}	~	q
t�|	�gWYd}	~	Sd}	~	ww)
a
    Return all AutoScale Groups visible in the account
    (as a list of boto.ec2.autoscale.group.AutoScalingGroup).

    .. versionadded:: 2016.11.0

    CLI Example:

    .. code-block:: bash

        salt-call boto_asg.get_all_groups region=us-east-1 --output yaml

    rrTr�N)�
next_tokencSsg|]}|�qSrr�rF�arrrr��sz"get_all_groups.<locals>.<listcomp>r!r"r#r$)r%r&r�rr)r*r+r'r(r,r-r.)
rrrrr0r1r��asgsr_r3rrrr&~s,�


��r&cCsdd�t||||d�D�S)z�
    Return all AutoScale Groups visible in the account
    (as a list of names).

    .. versionadded:: 2016.11.0

    CLI Example:

    .. code-block:: bash

        salt-call boto_asg.list_groups region=us-east-1

    cSr�rr�r�rrrr��s��zlist_groups.<locals>.<listcomp>r)r&rrrr�list_groups�s�r��	InService�Healthy�private_ip_addressc	
sLt||||d�}	t||||d�}
d}	z	|	j|gd�}Wn5tjjyQ}
z'|rA|
jdkrAt�d�t	�
d�|d8}WYd	}
~
qt�|
�WYd	}
~
d
Sd	}
~
wwt|�dkrft�d|dd
�|D��d
S|d}g}|j
D]}|d	ur{|j|kr{qo|d	ur�|j|kr�qo|�|j�qo|
j|d�}�r��fdd
�|D�S�fdd
�|D�S)z�
    return attribute of all instances in the named autoscale group.

    CLI Example:

    .. code-block:: bash

        salt-call boto_asg.get_instances my_autoscale_group_name

    rrTrr!r"r#r$NFz#name '%s' returns multiple ASGs: %scSr�rr�)rFrrrrr��r�z!get_instances.<locals>.<listcomp>r)�instance_idscsg|]��fdd��D��qS)csg|]}t�|��qSr)�_convert_attribute)rFr`��instancerrr��sz,get_instances.<locals>.<listcomp>.<listcomp>r)rF)r�r�rr��s��cs g|]}t|��rt|���qSr)rWr�)rFr�)r�rrr��s��)r%rr&rr)r*r+r'r(r,r-r.�len�	instances�lifecycle_state�
health_statusrVZinstance_idZget_only_instances)r/r�r�r�r�rrrrr0Zec2_connr1r�r3rr��ir�r)r�r�r�
get_instances�sL


���

�
�r�cCs8|dkrtt||��}dd�|��D�St||��d�S)Nr@cSs"i|]
\}}|�d�|�d��qS)zutf-8)�encode)rFrrCrrr�
<dictcomp>�s�z&_convert_attribute.<locals>.<dictcomp>�ascii)r[rWr�r�)r�r�r@rrrr��s�r�c
Cs�t||||d�}z
|j|||d�}Wn2tyD}	z&td|	�}
|	j�di��d�dkr6ddiWYd	}	~	Sd
|
iWYd	}	~	Sd	}	~	wwtdd�|d
D��S)z�
    Switch desired instances to StandBy mode

    .. versionadded:: 2016.11.0

    CLI Example:

    .. code-block:: bash

        salt-call boto_asg.enter_standby my_autoscale_group_name '["i-xxxxxx"]'

    r)�InstanceIds�AutoScalingGroupNameZShouldDecrementDesiredCapacity�boto3.get_error�Error�Code�ResourceNotFoundExceptionr4FNr.cs��|]	}|ddkVqdS�Z
StatusCodeZFailedNr�rFZactivityrrrrH$��
�z enter_standby.<locals>.<genexpr>�
Activities)r�
enter_standbyrr�responserq�all�r/r�Z!should_decrement_desired_capacityrrrrr0r�r3�errrrrr�s&�
����r�c
Cs�t||||d�}z	|j||d�}Wn2tyC}	z&td|	�}
|	j�di��d�dkr5ddiWYd	}	~	Sd
|
iWYd	}	~	Sd	}	~	wwtdd�|d
D��S)z�
    Exit desired instances from StandBy mode

    .. versionadded:: 2016.11.0

    CLI Example:

    .. code-block:: bash

        salt-call boto_asg.exit_standby my_autoscale_group_name '["i-xxxxxx"]'

    r)r�r�r�r�r�r�r4FNr.csr�r�rr�rrrrHJr�zexit_standby.<locals>.<genexpr>r�)r�exit_standbyrrr�rqr�r�rrrr�)s"�
����r�)NNNN)NNNNNNNNNNNNNNNNNN)FNNNN)NNNNNr�NNNFNNFNNTNFNNNN)r�r�r�NNNNN)8�__doc__r�Zemail.mime.multipartr��loggingrr,Zsalt.utils.compatr
Zsalt.utils.jsonZsalt.utils.odictrrTZsalt.utils.versions�	getLoggerr
r'r�rZboto.ec2Zboto.ec2.autoscaler	rsZboto.ec2.blockdevicemappingr�Zboto.ec2.instance�setLevel�CRITICALrZbotocore.exceptionsrr�ImportErrorrrr4rhr}r�rvrwr�r�r�r�r�r�r�r�r�r&r�r�r�r�r�rrrr�<module>s0
�

m
�y
�$

 
!

�&
�
g
�
#
#
�B

�+�