o ckF[@@sddlmZddlmZddlmZddlmZmZddl m Z ddl m Z ddl mZddlmZGd d d eZGd d d eZGd ddeZdS)) HealthCheck)Listener) ListElement)Policies OtherPolicy) SecurityGroup) InstanceInfo) ResultSet)sixc@s2eZdZdZd ddZddZddZd d ZdS) BackendzBackend server descriptionNcCs||_d|_d|_dSN) connection instance_portpoliciesselfr r;/usr/lib/python3/dist-packages/boto/ec2/elb/loadbalancer.py__init__$s zBackend.__init__cCsd|j|jfS)NzBackend(%r:%r))rrrrrr__repr__)szBackend.__repr__cCs"|dkrtdtfg|_|jSdS)N PolicyNamesmember)r rrrnameattrsr rrr startElement,szBackend.startElementcCs|dkr t||_dS)N InstancePort)intrrrvaluer rrr endElement1s zBackend.endElementr )__name__ __module__ __qualname____doc__rrrr!rrrrr !s   r c@s*eZdZdZd ddZddZddZdS) LoadBalancerZoneszj Used to collect the zones for a Load Balancer when enable_zones or disable_zones are called. NcCs||_t|_dSr )r rzonesrrrrr<s zLoadBalancerZones.__init__cCs|dkr|jSdS)NAvailabilityZones)r'rrrrr@szLoadBalancerZones.startElementcCsdSr rrrrrr!DszLoadBalancerZones.endElementr )r"r#r$r%rrr!rrrrr&7s   r&c@seZdZdZd?ddZddZddZd d Zd d Zd dZ d@ddZ d@ddZ ddZ ddZ ddZddZddZddZdAd d!Zd"d#ZdBd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Zd=d>Z dS)C LoadBalancerz* Represents an EC2 Load Balancer. NcCsv||_||_d|_d|_d|_d|_d|_d|_t|_ d|_ d|_ d|_ t|_ t|_d|_d|_d|_d|_dS)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 ``(, , )`` :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_checkrdns_name created_time instancesravailability_zonescanonical_hosted_zone_namecanonical_hosted_zone_name_idsource_security_groupsubnetssecurity_groupsvpc_idschemebackends _attributes)rr r endpointsrrrrMs$" zLoadBalancer.__init__cCs d|jS)NzLoadBalancer:%s)rrrrrrs zLoadBalancer.__repr__cCs|dkr t||_|jS|dkrtdtfg|_|jS|dkr"|jS|dkr1tdtfg|_|jS|dkr=t||_ |j S|dkrHt |_ |j S|dkrO|j S|d krV|j S|d kr\dS|d krktdtfg|_|jSdS) NrListenerDescriptionsrr( InstancesrSourceSecurityGroupSubnetsSecurityGroupsVPCIdBackendServerDescriptions)rr+r rr*r/rr.rrrr2r3r4r r7rrrrrs6  zLoadBalancer.startElementcCs|dkr ||_dS|dkr||_dS|dkr||_dS|dkr'|j|dS|dkr0||_dS|dkr9||_dS|dkrB||_dS|dkrK||_dSt |||dS) NLoadBalancerNameDNSName CreatedTime InstanceIdCanonicalHostedZoneNameCanonicalHostedZoneNameIDr?Scheme) rr,r-r.appendr0r1r5r6setattrrrrrr!s"       zLoadBalancer.endElementcC,t|tjr |g}|j|j|}||_dS)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_zonesrr/rr' new_zonesrrr enable_zoness  zLoadBalancer.enable_zonescCrJ)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)rKr rLr disable_availability_zonesrr/rNrrr disable_zones  zLoadBalancer.disable_zonesFcCs |jr|r |j|j|_|jS)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 )r8r get_all_lb_attributesrrforcerrrget_attributess zLoadBalancer.get_attributescCs||jjS)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. )rWcross_zone_load_balancingenabledrUrrris_cross_zone_load_balancings z)LoadBalancer.is_cross_zone_load_balancingcC*|j|jdd}|r|jrd|jj_|S)z Turns on CrossZone Load Balancing for this ELB. :rtype: bool :return: True if successful, False if not. crossZoneLoadBalancingTr modify_lb_attributerr8rXrYrsuccessrrr enable_cross_zone_load_balancing   z-LoadBalancer.enable_cross_zone_load_balancingcCr[)z Turns off CrossZone Load Balancing for this ELB. :rtype: bool :return: True if successful, False if not. r\Fr]r_rrr!disable_cross_zone_load_balancingrbz.LoadBalancer.disable_cross_zone_load_balancingcCrJ)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)rKr rLr register_instancesrr.rr. new_instancesrrrrds   zLoadBalancer.register_instancescCrJ)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)rKr rLr deregister_instancesrr.rerrrrgs   z!LoadBalancer.deregister_instancescCs|j|jS)z, Delete this load balancer. )r delete_load_balancerrrrrrdelete&szLoadBalancer.deletecC|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)rr+rrrrk,s z#LoadBalancer.configure_health_checkcCrj)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 ` instances, representing the instances attached to this load balancer. )r describe_instance_healthr)rr.rrrget_instance_health8s z LoadBalancer.get_instance_healthcCrjr )r create_load_balancer_listenersrrr*rrrcreate_listenersF zLoadBalancer.create_listenerstcpcCs|dur|}||||fgSr )rp)rinPortoutPortprotorrrcreate_listenerJszLoadBalancer.create_listenercCrjr )r delete_load_balancer_listenersrrorrrdelete_listenersOrqzLoadBalancer.delete_listenerscCs ||gSr )rx)rrsrrrdelete_listenerSs zLoadBalancer.delete_listenercCrj)z} Deletes a policy from the LoadBalancer. The specified policy must not be enabled for any listeners. )r delete_lb_policyr)r policy_namerrr delete_policyVszLoadBalancer.delete_policycC|j|j||Sr )r set_lb_policies_of_listenerr)rlb_portrrrrset_policies_of_listener]s z%LoadBalancer.set_policies_of_listenercCr}r )r !set_lb_policies_of_backend_serverr)rrrrrrset_policies_of_backend_serverbz+LoadBalancer.set_policies_of_backend_servercC|j||j|Sr )r "create_lb_cookie_stickiness_policyr)rcookie_expiration_periodr{rrrcreate_cookie_stickiness_policyfsz,LoadBalancer.create_cookie_stickiness_policycCrr )r #create_app_cookie_stickiness_policyr)rrr{rrrrksz0LoadBalancer.create_app_cookie_stickiness_policycCr}r )r set_lb_listener_SSL_certificater)rrssl_certificate_idrrrset_listener_SSL_certificateprz)LoadBalancer.set_listener_SSL_certificatecCs|j|j|||Sr )r create_lb_policyr)rr{ policy_typepolicy_attributerrrrts zLoadBalancer.create_lb_policycCrJ)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)rKr rLr attach_lb_to_subnetsrr3rr3 new_subnetsrrrattach_subnetsxs  zLoadBalancer.attach_subnetscCrJ)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)rKr rLr detach_lb_from_subnetsrr3rrrrdetach_subnetsrSzLoadBalancer.detach_subnetscCrJ)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)rKr rLr apply_security_groups_to_lbrr4)rr4new_sgsrrrapply_security_groupss  z"LoadBalancer.apply_security_groups)NNN)Fr )Nrr)!r"r#r$r%rrrr!rPrRrWrZrarcrdrgrirkrmrprvrxryr|rrrrrrrrrrrrrr)Hs> 5        r)N)boto.ec2.elb.healthcheckrboto.ec2.elb.listenerrboto.ec2.elb.listelementrboto.ec2.elb.policiesrrboto.ec2.elb.securitygrouprboto.ec2.instanceinforboto.resultsetr boto.compatr objectr r&r)rrrrs