File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/libcloud_loadbalancer.cpython-310.pyc
Back
o ;j� � @ sP d Z ddlZe�e�Zdd� Zddd�Z ddd�Zd d � Zdd� Z d d� Z dS )a� Apache Libcloud Load Balancer State =================================== Manage load balancers using libcloud :codeauthor: ``Anthony Shaw <anthonyshaw@apache.org>`` Apache Libcloud load balancer management for a full list of supported clouds, see http://libcloud.readthedocs.io/en/latest/loadbalancer/supported_providers.html Clouds include Amazon ELB, ALB, Google, Aliyun, CloudStack, Softlayer .. versionadded:: 2018.3.0 :configuration: This module uses a configuration profile for one or multiple Cloud providers .. code-block:: yaml libcloud_loadbalancer: profile_test1: driver: gce key: GOOG0123456789ABCXYZ secret: mysecret profile_test2: driver: alb key: 12345 secret: mysecret Example: Using States to deploy a load balancer with extended arguments to specify region .. code-block:: yaml lb_test: libcloud_loadbalancer.balancer_present: - name: example - port: 80 - protocol: http - profile: google - ex_region: us-east1 :depends: apache-libcloud � Nc C s dt v rdS dS )N�$libcloud_loadbalancer.list_balancersT)Fz0libcloud_loadbalancer module could not be loaded)�__salt__� r r �U/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/libcloud_loadbalancer.py�__virtual__5 s r c C s |d u ri }| |||d�S )N)�resultZcomment�name�changesr )r �messager r r r r �state_result; s r c s� t d |�}� fdd�|D �}t|�dkrtdd� �S d} |dur4g } |D ]} | �| d | d d �� q%t d � |||f|| d�|��}tdd � |�S )a� Ensures a load balancer is present. :param name: Load Balancer name :type name: ``str`` :param port: Port the load balancer should listen on, defaults to 80 :type port: ``str`` :param protocol: Loadbalancer protocol, defaults to http. :type protocol: ``str`` :param profile: The profile key :type profile: ``str`` :param algorithm: Load balancing algorithm, defaults to ROUND_ROBIN. See Algorithm type in Libcloud documentation for a full listing. :type algorithm: ``str`` :param members: An optional list of members to create on deployment :type members: ``list`` of ``dict`` (ip, port) r c � g | ] }|d � kr|�qS �r r ��.0�zr r r � <listcomp>[ � z$balancer_present.<locals>.<listcomp>r TzBalancer already existsN�ip�port)r r z%libcloud_loadbalancer.create_balancer)� algorithm�memberszCreated new load balancer)r �lenr �append)r r �protocol�profiler r �libcloud_kwargs� balancers�matchZstarting_members�mZbalancerr r r �balancer_presentA s* ��� r c s` t d |�}� fdd�|D �}t|�dkrtdd� �S t d |d d |fi |��}t|d � �S ) z� Ensures a load balancer is absent. :param name: Load Balancer name :type name: ``str`` :param profile: The profile key :type profile: ``str`` r c r r r r r r r r { r z#balancer_absent.<locals>.<listcomp>r TzBalancer already absentz&libcloud_loadbalancer.destroy_balancer�idzDeleted load balancer)r r r )r r r r r r r r r �balancer_absentp s ��r! c K sr t d ||�}|D ]}|d | kr|d |krtdd|� S q t d || ||fi |��}tdd�|d �||�S ) ak Ensure a load balancer member is present :param ip: IP address for the new member :type ip: ``str`` :param port: Port for the new member :type port: ``int`` :param balancer_id: id of a load balancer you want to attach the member to :type balancer_id: ``str`` :param profile: The profile key :type profile: ``str`` �+libcloud_loadbalancer.list_balancer_membersr r TzMember already presentz,libcloud_loadbalancer.balancer_attach_memberz Member added to balancer, id: {}r )r r �format)r r �balancer_idr r �existing_members�memberr r r �member_present� s$ �����r'