o
    rMf@                     @   s   d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ G d	d
 d
eZG dd deZG dd deZdS )    )HealthCheck)Listener)ListElement)PoliciesOtherPolicy)SecurityGroup)InstanceInfo)	ResultSet)sixc                   @   s2   e Zd ZdZdddZdd Zdd Zd	d
 ZdS )BackendzBackend server descriptionNc                 C   s   || _ d | _d | _d S N)
connectioninstance_portpoliciesselfr    r   [/var/www/html/analyze/labelStudio/lib/python3.10/site-packages/boto/ec2/elb/loadbalancer.py__init__$   s   
zBackend.__init__c                 C   s   d| j | jf S )NzBackend(%r:%r))r   r   r   r   r   r   __repr__)   s   zBackend.__repr__c                 C   s"   |dkrt dtfg| _| jS d S )NPolicyNamesmember)r	   r   r   r   nameattrsr   r   r   r   startElement,   s   zBackend.startElementc                 C   s   |dkr	t || _d S )NInstancePort)intr   r   r   valuer   r   r   r   
endElement1   s   
zBackend.endElementr   )__name__
__module____qualname____doc__r   r   r   r!   r   r   r   r   r   !   s    
r   c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
LoadBalancerZoneszj
    Used to collect the zones for a Load Balancer when enable_zones
    or disable_zones are called.
    Nc                 C   s   || _ t | _d S r   )r   r   zonesr   r   r   r   r   <   s   zLoadBalancerZones.__init__c                 C   s   |dkr| j S d S )NAvailabilityZones)r'   r   r   r   r   r   @   s   zLoadBalancerZones.startElementc                 C   s   d S r   r   r   r   r   r   r!   D   s   zLoadBalancerZones.endElementr   )r"   r#   r$   r%   r   r   r!   r   r   r   r   r&   7   s
    
r&   c                   @   s  e Zd ZdZd?ddZdd Zdd Zd	d
 Zdd Zdd Z	d@ddZ
d@ddZdd Zdd Zdd Zdd Zdd Zdd ZdAd d!Zd"d# ZdBd%d&Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Zd=d> Z dS )CLoadBalancerz*
    Represents an EC2 Load Balancer.
    Nc                 C   sv   || _ || _d| _d| _d| _d| _d| _d| _t | _	d| _
d| _d| _t | _t | _d| _d| _d| _d| _dS )a  
        :ivar boto.ec2.elb.ELBConnection connection: The connection this load
            balancer was instance was instantiated from.
        :ivar list listeners: A list of tuples in the form of
            ``(<Inbound port>, <Outbound port>, <Protocol>)``
        :ivar boto.ec2.elb.healthcheck.HealthCheck health_check: The health
            check policy for this load balancer.
        :ivar boto.ec2.elb.policies.Policies policies: Cookie stickiness and
            other policies.
        :ivar str name: The name of the Load Balancer.
        :ivar str dns_name: The external DNS name for the balancer.
        :ivar str created_time: A date+time string showing when the
            load balancer was created.
        :ivar list instances: A list of :py:class:`boto.ec2.instanceinfo.InstanceInfo`
            instances, representing the EC2 instances this load balancer is
            distributing requests to.
        :ivar list availability_zones: The availability zones this balancer
            covers.
        :ivar str canonical_hosted_zone_name: Current CNAME for the balancer.
        :ivar str canonical_hosted_zone_name_id: The Route 53 hosted zone
            ID of this balancer. Needed when creating an Alias record in a
            Route 53 hosted zone.
        :ivar boto.ec2.elb.securitygroup.SecurityGroup source_security_group:
            The security group that you can use as part of your inbound rules
            for your load balancer back-end instances to disallow traffic
            from sources other than your load balancer.
        :ivar list subnets: A list of subnets this balancer is on.
        :ivar list security_groups: A list of additional security groups that
            have been applied.
        :ivar str vpc_id: The ID of the VPC that this ELB resides within.
        :ivar list backends: A list of :py:class:`boto.ec2.elb.loadbalancer.Backend
            back-end server descriptions.
        N)r   r   	listenershealth_checkr   dns_namecreated_time	instancesr   availability_zonescanonical_hosted_zone_namecanonical_hosted_zone_name_idsource_security_groupsubnetssecurity_groupsvpc_idschemebackends_attributes)r   r   r   	endpointsr   r   r   r   M   s$   "
zLoadBalancer.__init__c                 C   s
   d| j  S )NzLoadBalancer:%s)r   r   r   r   r   r      s   
zLoadBalancer.__repr__c                 C   s   |dkrt | | _| jS |dkrtdtfg| _| jS |dkr"| jS |dkr1tdtfg| _| jS |dkr=t| | _	| j	S |dkrHt
 | _| jS |dkrO| jS |d	krV| jS |d
kr\d S |dkrktdtfg| _| jS d S )Nr   ListenerDescriptionsr   r(   	Instancesr   SourceSecurityGroupSubnetsSecurityGroupsVPCIdBackendServerDescriptions)r   r+   r	   r   r*   r/   r   r.   r   r   r   r2   r3   r4   r   r7   r   r   r   r   r      s6   

zLoadBalancer.startElementc                 C   s   |dkr	|| _ d S |dkr|| _d S |dkr|| _d S |dkr'| j| d S |dkr0|| _d S |dkr9|| _d S |dkrB|| _d S |dkrK|| _d S t	| || d S )	NLoadBalancerNameDNSNameCreatedTime
InstanceIdCanonicalHostedZoneNameCanonicalHostedZoneNameIDr?   Scheme)
r   r,   r-   r.   appendr0   r1   r5   r6   setattrr   r   r   r   r!      s"   






zLoadBalancer.endElementc                 C   ,   t |tjr	|g}| j| j|}|| _dS )z
        Enable availability zones to this Access Point.
        All zones must be in the same region as the Access Point.

        :type zones: string or List of strings
        :param zones: The name of the zone(s) to add.

        N)
isinstancer
   string_typesr   enable_availability_zonesr   r/   r   r'   	new_zonesr   r   r   enable_zones   s   	
zLoadBalancer.enable_zonesc                 C   rJ   )z
        Disable availability zones from this Access Point.

        :type zones: string or List of strings
        :param zones: The name of the zone(s) to add.

        N)rK   r
   rL   r   disable_availability_zonesr   r/   rN   r   r   r   disable_zones      
zLoadBalancer.disable_zonesFc                 C   s    | j r|r| j| j| _ | j S )z
        Gets the LbAttributes.  The Attributes will be cached.

        :type force: bool
        :param force: Ignore cache value and reload.

        :rtype: boto.ec2.elb.attributes.LbAttributes
        :return: The LbAttribues object
        )r8   r   get_all_lb_attributesr   r   forcer   r   r   get_attributes   s   

zLoadBalancer.get_attributesc                 C   s   |  |jjS )z
        Identifies if the ELB is current configured to do CrossZone Balancing.

        :type force: bool
        :param force: Ignore cache value and reload.

        :rtype: bool
        :return: True if balancing is enabled, False if not.
        )rW   cross_zone_load_balancingenabledrU   r   r   r   is_cross_zone_load_balancing   s   
z)LoadBalancer.is_cross_zone_load_balancingc                 C   *   | j | jdd}|r| jrd| jj_|S )z
        Turns on CrossZone Load Balancing for this ELB.

        :rtype: bool
        :return: True if successful, False if not.
        crossZoneLoadBalancingTr   modify_lb_attributer   r8   rX   rY   r   successr   r   r    enable_cross_zone_load_balancing      

z-LoadBalancer.enable_cross_zone_load_balancingc                 C   r[   )z
        Turns off CrossZone Load Balancing for this ELB.

        :rtype: bool
        :return: True if successful, False if not.
        r\   Fr]   r_   r   r   r   !disable_cross_zone_load_balancing   rb   z.LoadBalancer.disable_cross_zone_load_balancingc                 C   rJ   )aS  
        Adds instances to this load balancer. All instances must be in the same
        region as the load balancer. Adding endpoints that are already
        registered with the load balancer has no effect.

        :param list instances: List of instance IDs (strings) that you'd like
            to add to this load balancer.

        N)rK   r
   rL   r   register_instancesr   r.   r   r.   new_instancesr   r   r   rd     s   


zLoadBalancer.register_instancesc                 C   rJ   )a  
        Remove instances from this load balancer. Removing instances that are
        not registered with the load balancer has no effect.

        :param list instances: List of instance IDs (strings) that you'd like
            to remove from this load balancer.

        N)rK   r
   rL   r   deregister_instancesr   r.   re   r   r   r   rg     s   	

z!LoadBalancer.deregister_instancesc                 C   s   | j | jS )z,
        Delete this load balancer.
        )r   delete_load_balancerr   r   r   r   r   delete&  s   zLoadBalancer.deletec                 C      | j | j|S )af  
        Configures the health check behavior for the instances behind this
        load balancer. See :ref:`elb-configuring-a-health-check` for a
        walkthrough.

        :param boto.ec2.elb.healthcheck.HealthCheck health_check: A
            HealthCheck instance that tells the load balancer how to check
            its instances for health.
        )r   configure_health_checkr   )r   r+   r   r   r   rk   ,  s   
z#LoadBalancer.configure_health_checkc                 C   rj   )a  
        Returns a list of :py:class:`boto.ec2.elb.instancestate.InstanceState`
        objects, which show the health of the instances attached to this
        load balancer.

        :rtype: list
        :returns: A list of
            :py:class:`InstanceState <boto.ec2.elb.instancestate.InstanceState>`
            instances, representing the instances
            attached to this load balancer.
        )r   describe_instance_healthr   )r   r.   r   r   r   get_instance_health8  s   z LoadBalancer.get_instance_healthc                 C   rj   r   )r   create_load_balancer_listenersr   r   r*   r   r   r   create_listenersF     
zLoadBalancer.create_listenerstcpc                 C   s   |d u r|}|  |||fgS r   )rp   )r   inPortoutPortprotor   r   r   create_listenerJ  s   zLoadBalancer.create_listenerc                 C   rj   r   )r   delete_load_balancer_listenersr   ro   r   r   r   delete_listenersO  rq   zLoadBalancer.delete_listenersc                 C   s   |  |gS r   )rx   )r   rs   r   r   r   delete_listenerS  s   zLoadBalancer.delete_listenerc                 C   rj   )z}
        Deletes a policy from the LoadBalancer. The specified policy must not
        be enabled for any listeners.
        )r   delete_lb_policyr   )r   policy_namer   r   r   delete_policyV  s   zLoadBalancer.delete_policyc                 C      | j | j||S r   )r   set_lb_policies_of_listenerr   )r   lb_portr   r   r   r   set_policies_of_listener]  s   
z%LoadBalancer.set_policies_of_listenerc                 C   r}   r   )r   !set_lb_policies_of_backend_serverr   )r   r   r   r   r   r   set_policies_of_backend_serverb     z+LoadBalancer.set_policies_of_backend_serverc                 C      | j || j|S r   )r   "create_lb_cookie_stickiness_policyr   )r   cookie_expiration_periodr{   r   r   r   create_cookie_stickiness_policyf  s   z,LoadBalancer.create_cookie_stickiness_policyc                 C   r   r   )r   #create_app_cookie_stickiness_policyr   )r   r   r{   r   r   r   r   k  s   z0LoadBalancer.create_app_cookie_stickiness_policyc                 C   r}   r   )r   set_lb_listener_SSL_certificater   )r   r   ssl_certificate_idr   r   r   set_listener_SSL_certificatep  r   z)LoadBalancer.set_listener_SSL_certificatec                 C   s   | j | j|||S r   )r   create_lb_policyr   )r   r{   policy_typepolicy_attributer   r   r   r   t  s   
zLoadBalancer.create_lb_policyc                 C   rJ   )a  
        Attaches load balancer to one or more subnets.
        Attaching subnets that are already registered with the
        Load Balancer has no effect.

        :type subnets: string or List of strings
        :param subnets: The name of the subnet(s) to add.

        N)rK   r
   rL   r   attach_lb_to_subnetsr   r3   r   r3   new_subnetsr   r   r   attach_subnetsx  s   

zLoadBalancer.attach_subnetsc                 C   rJ   )z
        Detaches load balancer from one or more subnets.

        :type subnets: string or List of strings
        :param subnets: The name of the subnet(s) to detach.

        N)rK   r
   rL   r   detach_lb_from_subnetsr   r3   r   r   r   r   detach_subnets  rS   zLoadBalancer.detach_subnetsc                 C   rJ   )a7  
        Associates one or more security groups with the load balancer.
        The provided security groups will override any currently applied
        security groups.

        :type security_groups: string or List of strings
        :param security_groups: The name of the security group(s) to add.

        N)rK   r
   rL   r   apply_security_groups_to_lbr   r4   )r   r4   new_sgsr   r   r   apply_security_groups  s   

z"LoadBalancer.apply_security_groups)NNN)Fr   )Nrr   )!r"   r#   r$   r%   r   r   r   r!   rP   rR   rW   rZ   ra   rc   rd   rg   ri   rk   rm   rp   rv   rx   ry   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r)   H   s>    
5



r)   N)boto.ec2.elb.healthcheckr   boto.ec2.elb.listenerr   boto.ec2.elb.listelementr   boto.ec2.elb.policiesr   r   boto.ec2.elb.securitygroupr   boto.ec2.instanceinfor   boto.resultsetr	   boto.compatr
   objectr   r&   r)   r   r   r   r   <module>   s   