o ckF[@sdZddlmZddlmZddlmZmZddlm Z ddl m Z ddl m Z mZmZddl mZdd lZdd lmZed iZd d ZddZGdddeZd S)zg This module provides an interface to the Elastic Compute Cloud (EC2) load balancing service from AWS. )AWSQueryConnection) InstanceInfo) LoadBalancerLoadBalancerZones) InstanceState) HealthCheck) RegionInfo get_regions load_regions)connectN)sixelasticloadbalancingcCs tdtdS)z Get all available regions for the ELB service. :rtype: list :return: A list of :class:`boto.RegionInfo` instances r )connection_cls)r ELBConnectionrr7/usr/lib/python3/dist-packages/boto/ec2/elb/__init__.pyregions)s rcKstd|fdti|S)a4 Given a valid region name, return a :class:`boto.ec2.elb.ELBConnection`. :param str region_name: The name of the region to connect to. :rtype: :class:`boto.ec2.ELBConnection` or ``None`` :return: A connection to the given region, or None if an invalid region name is given r r)r r) region_name kw_paramsrrrconnect_to_region3s rcs:eZdZejdddZejdddZejdddZ   dCfd d Z ddZ ddZ dDddZ   dEddZ  dDddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*ZdFd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z d=d>Z!d?d@Z"dAdBZ#Z$S)GrBoto elb_versionz 2012-06-01elb_region_namez us-east-1elb_region_endpointz,elasticloadbalancing.us-east-1.amazonaws.comNTr/csP| s t||j|j} | |_tt|j|||||||||jj| | | | ||ddS)z Init method to create a new connection to EC2 Load Balancing Service. .. note:: The region argument is overridden by the region specified in the boto configuration file. )validate_certs profile_nameN)rDefaultRegionNameDefaultRegionEndpointregionsuperr__init__endpoint)selfaws_access_key_idaws_secret_access_key is_secureportproxy proxy_port proxy_user proxy_passdebughttps_connection_factoryrpathsecurity_tokenrr __class__rrr!Js   zELBConnection.__init__cCsdgS)Nzhmac-v4r)r#rrr_required_auth_capabilitycsz'ELBConnection._required_auth_capabilitycCs8t|tjr |g}t|D] \}}||||d<q dS)N) isinstancer string_types enumerate)r#paramsitemslabelindexitemrrrbuild_list_paramsfs zELBConnection.build_list_paramscCs6i}|r |||d|r||d<|d|dtfgS)a Retrieve all load balancers associated with your account. :type load_balancer_names: list :keyword load_balancer_names: An optional list of load balancer names. :type marker: string :param marker: Use this only when paginating results and only in follow-up request after you've received a response where the results are truncated. Set this to the value of the Marker element in the response you just received. :rtype: :py:class:`boto.resultset.ResultSet` :return: A ResultSet containing instances of :class:`boto.ec2.elb.loadbalancer.LoadBalancer` zLoadBalancerNames.member.%dMarkerDescribeLoadBalancersmember)r<get_listr)r#load_balancer_namesmarkerr7rrrget_all_load_balancerslsz$ELBConnection.get_all_load_balancersinternet-facingcCs|s|sdS||d}|rHt|D]6\} } | d} | d} | d|d| <| d|d| <| d|d| <| d ks?| d krG| d |d | <q|rt|D]D\} } | d} | d} | d } | d|d| <| d|d| <| d|d| <| d |d | <| d ks| d kr| d|d | <qN|r|||d|r|||d|r|||d|d|t}||_||_||_||_||_ |S)a Create a new load balancer for your account. By default the load balancer will be created in EC2. To create a load balancer inside a VPC, parameter zones must be set to None and subnets must not be None. The load balancer will be automatically created under the VPC that contains the subnet(s) specified. :type name: string :param name: The mnemonic name associated with the new load balancer :type zones: List of strings :param zones: The names of the availability zone(s) to add. :type listeners: List of tuples :param listeners: Each tuple contains three or four values, (LoadBalancerPortNumber, InstancePortNumber, Protocol, [SSLCertificateId]) where LoadBalancerPortNumber and InstancePortNumber are integer values between 1 and 65535, Protocol is a string containing either 'TCP', 'SSL', HTTP', or 'HTTPS'; SSLCertificateID is the ARN of a AWS IAM certificate, and must be specified when doing HTTPS. :type subnets: list of strings :param subnets: A list of subnet IDs in your VPC to attach to your LoadBalancer. :type security_groups: list of strings :param security_groups: The security groups assigned to your LoadBalancer within your VPC. :type scheme: string :param scheme: The type of a LoadBalancer. By default, Elastic Load Balancing creates an internet-facing LoadBalancer with a publicly resolvable DNS name, which resolves to public IP addresses. Specify the value internal for this option to create an internal LoadBalancer with a DNS name that resolves to private IP addresses. This option is only available for LoadBalancers attached to an Amazon VPC. :type complex_listeners: List of tuples :param complex_listeners: Each tuple contains four or five values, (LoadBalancerPortNumber, InstancePortNumber, Protocol, InstanceProtocol, SSLCertificateId). Where: - LoadBalancerPortNumber and InstancePortNumber are integer values between 1 and 65535 - Protocol and InstanceProtocol is a string containing either 'TCP', 'SSL', 'HTTP', or 'HTTPS' - SSLCertificateId is the ARN of an SSL certificate loaded into AWS IAM :rtype: :class:`boto.ec2.elb.loadbalancer.LoadBalancer` :return: The newly created :class:`boto.ec2.elb.loadbalancer.LoadBalancer` N)LoadBalancerNameSchemer3r$Listeners.member.%d.LoadBalancerPort Listeners.member.%d.InstancePortListeners.member.%d.ProtocolHTTPSSSL$Listeners.member.%d.SSLCertificateId$Listeners.member.%d.InstanceProtocolAvailabilityZones.member.%dSubnets.member.%dSecurityGroups.member.%dCreateLoadBalancer) r6upperr< get_objectrname listenersavailability_zonessubnetssecurity_groups)r#rWzonesrXrZr[schemecomplex_listenersr7r:listeneriprotocolInstanceProtocol load_balancerrrrcreate_load_balancersX@   z"ELBConnection.create_load_balancerc Cs0|s|sdSd|i}|rGt|D]6\}}|d}|d}|d|d|<|d|d|<|d|d|<|d ks>|d krF|d |d |<q|rt|D]D\}}|d}|d}|d } |d|d|<|d|d|<|d|d|<|d |d |<|d ks|d kr|d|d |<qM|d|S)av Creates a Listener (or group of listeners) for an existing Load Balancer :type name: string :param name: The name of the load balancer to create the listeners for :type listeners: List of tuples :param listeners: Each tuple contains three or four values, (LoadBalancerPortNumber, InstancePortNumber, Protocol, [SSLCertificateId]) where LoadBalancerPortNumber and InstancePortNumber are integer values between 1 and 65535, Protocol is a string containing either 'TCP', 'SSL', HTTP', or 'HTTPS'; SSLCertificateID is the ARN of a AWS IAM certificate, and must be specified when doing HTTPS. :type complex_listeners: List of tuples :param complex_listeners: Each tuple contains four or five values, (LoadBalancerPortNumber, InstancePortNumber, Protocol, InstanceProtocol, SSLCertificateId). Where: - LoadBalancerPortNumber and InstancePortNumber are integer values between 1 and 65535 - Protocol and InstanceProtocol is a string containing either 'TCP', 'SSL', 'HTTP', or 'HTTPS' - SSLCertificateId is the ARN of an SSL certificate loaded into AWS IAM :return: The status of the request NrEr3rGrrHrIrJrKrLrMrNrOrPCreateLoadBalancerListeners)r6rU get_status) r#rWrXr^r7r:r_r`rarbrrrcreate_load_balancer_listenerss4"    z,ELBConnection.create_load_balancer_listenerscCsd|i}|d|S)z Delete a Load Balancer from your account. :type name: string :param name: The name of the Load Balancer to delete rEDeleteLoadBalancerrf)r#rWr7rrrdelete_load_balancer<s z"ELBConnection.delete_load_balancercCs6d|i}t|D] \}}||d|d<q|d|S)aL Deletes a load balancer listener (or group of listeners) :type name: string :param name: The name of the load balancer to create the listeners for :type ports: List int :param ports: Each int represents the port on the ELB to be removed :return: The status of the request rEzLoadBalancerPorts.member.%dr3DeleteLoadBalancerListeners)r6rf)r#rWportsr7r:r'rrrdelete_load_balancer_listenersFs  z,ELBConnection.delete_load_balancer_listenerscC*d|i}|||d|d|t}|jS)a Add availability zones to an existing Load Balancer All zones must be in the same region as the Load Balancer Adding zones that are already registered with the Load Balancer has no effect. :type load_balancer_name: string :param load_balancer_name: The name of the Load Balancer :type zones: List of strings :param zones: The name of the zone(s) to add. :rtype: List of strings :return: An updated list of zones for this Load Balancer. rErQ&EnableAvailabilityZonesForLoadBalancerr<rVrr\)r#load_balancer_name zones_to_addr7objrrrenable_availability_zonesWsz'ELBConnection.enable_availability_zonescCrn)aT Remove availability zones from an existing Load Balancer. All zones must be in the same region as the Load Balancer. Removing zones that are not registered with the Load Balancer has no effect. You cannot remove all zones from an Load Balancer. :type load_balancer_name: string :param load_balancer_name: The name of the Load Balancer :type zones: List of strings :param zones: The name of the zone(s) to remove. :rtype: List of strings :return: An updated list of zones for this Load Balancer. rErQ'DisableAvailabilityZonesForLoadBalancerrp)r#rqzones_to_remover7rsrrrdisable_availability_zonesosz(ELBConnection.disable_availability_zonescCsd}||vrt|tr|rd}nd}d|i}|dkr#||d<nE|dkrB|jr.dp/d|d<|j|d <|j|d <|j|d <n&|d krW|jrMdpNd|d <|j|d<n|dkrc|j|d<nt d||j d|ddS)aChanges an attribute of a Load Balancer :type load_balancer_name: string :param load_balancer_name: The name of the Load Balancer :type attribute: string :param attribute: The attribute you wish to change. * crossZoneLoadBalancing - Boolean (true) * connectingSettings - :py:class:`ConnectionSettingAttribute` instance * accessLog - :py:class:`AccessLogAttribute` instance * connectionDraining - :py:class:`ConnectionDrainingAttribute` instance :type value: string :param value: The new value for the attribute :rtype: bool :return: Whether the operation succeeded or not )crosszoneloadbalancingtruefalserErxz5LoadBalancerAttributes.CrossZoneLoadBalancing.Enabled accesslogz(LoadBalancerAttributes.AccessLog.Enabledz-LoadBalancerAttributes.AccessLog.S3BucketNamez/LoadBalancerAttributes.AccessLog.S3BucketPrefixz-LoadBalancerAttributes.AccessLog.EmitIntervalconnectiondrainingz1LoadBalancerAttributes.ConnectionDraining.Enabledz1LoadBalancerAttributes.ConnectionDraining.Timeoutconnectingsettingsz5LoadBalancerAttributes.ConnectionSettings.IdleTimeoutInvalidAttributeModifyLoadBalancerAttributesGET)verb) lowerr4boolenableds3_bucket_names3_bucket_prefix emit_intervaltimeout idle_timeout ValueErrorrf)r#rq attributevalue bool_reqsr7rrrmodify_lb_attributes>         z!ELBConnection.modify_lb_attributecCs"ddlm}d|i}|d||S)aGets all Attributes of a Load Balancer :type load_balancer_name: string :param load_balancer_name: The name of the Load Balancer :rtype: boto.ec2.elb.attribute.LbAttributes :return: The attribute object of the ELB. r) LbAttributesrEDescribeLoadBalancerAttributes)boto.ec2.elb.attributesrrV)r#rqrr7rrrget_all_lb_attributess z#ELBConnection.get_all_lb_attributescCsX||}|dkr|jS|dkr|jjS|dkr!|jS|dkr*|jSdS)aGets an attribute of a Load Balancer This will make an EC2 call for each method call. :type load_balancer_name: string :param load_balancer_name: The name of the Load Balancer :type attribute: string :param attribute: The attribute you wish to see. * accessLog - :py:class:`AccessLogAttribute` instance * crossZoneLoadBalancing - Boolean * connectingSettings - :py:class:`ConnectionSettingAttribute` instance * connectionDraining - :py:class:`ConnectionDrainingAttribute` instance :rtype: Attribute dependent :return: The new value for the attribute r{rxr|r}N)rr access_logcross_zone_load_balancingrconnection_drainingconnecting_settings)r#rqr attributesrrrget_lb_attributes     zELBConnection.get_lb_attributecC*d|i}|||d|d|dtfgS)a Add new Instances to an existing Load Balancer. :type load_balancer_name: string :param load_balancer_name: The name of the Load Balancer :type instances: List of strings :param instances: The instance ID's of the EC2 instances to add. :rtype: List of strings :return: An updated list of instances for this Load Balancer. rEInstances.member.%d.InstanceId!RegisterInstancesWithLoadBalancerr?r<r@rr#rq instancesr7rrrregister_instances z ELBConnection.register_instancescCr)a Remove Instances from an existing Load Balancer. :type load_balancer_name: string :param load_balancer_name: The name of the Load Balancer :type instances: List of strings :param instances: The instance ID's of the EC2 instances to remove. :rtype: List of strings :return: An updated list of instances for this Load Balancer. rEr#DeregisterInstancesFromLoadBalancerr?rrrrrderegister_instancesrz"ELBConnection.deregister_instancescCs.d|i}|r |||d|d|dtfgS)aH Get current state of all Instances registered to an Load Balancer. :type load_balancer_name: string :param load_balancer_name: The name of the Load Balancer :type instances: List of strings :param instances: The instance ID's of the EC2 instances to return status for. If not provided, the state of all instances will be returned. :rtype: List of :class:`boto.ec2.elb.instancestate.InstanceState` :return: list of state info for instances in this Load Balancer. rErDescribeInstanceHealthr?)r<r@rrrrrdescribe_instance_healthsz&ELBConnection.describe_instance_healthcCs*||j|j|j|j|jd}|d|tS)a Define a health check for the EndPoints. :type name: string :param name: The mnemonic name associated with the load balancer :type health_check: :class:`boto.ec2.elb.healthcheck.HealthCheck` :param health_check: A HealthCheck object populated with the desired values. :rtype: :class:`boto.ec2.elb.healthcheck.HealthCheck` :return: The updated :class:`boto.ec2.elb.healthcheck.HealthCheck` )rEzHealthCheck.TimeoutzHealthCheck.TargetzHealthCheck.IntervalzHealthCheck.UnhealthyThresholdzHealthCheck.HealthyThresholdConfigureHealthCheck)rtargetintervalunhealthy_thresholdhealthy_thresholdrVr)r#rW health_checkr7rrrconfigure_health_check+sz$ELBConnection.configure_health_checkcC|||d}|d|S)z Sets the certificate that terminates the specified listener's SSL connections. The specified certificate replaces any prior certificate that was used on the same LoadBalancer and port. )rELoadBalancerPortSSLCertificateId%SetLoadBalancerListenerSSLCertificateri)r#lb_namelb_portssl_certificate_idr7rrrset_lb_listener_SSL_certificateAs  z-ELBConnection.set_lb_listener_SSL_certificatecCr)a Generates a stickiness policy with sticky session lifetimes that follow that of an application-generated cookie. This policy can only be associated with HTTP listeners. This policy is similar to the policy created by CreateLBCookieStickinessPolicy, except that the lifetime of the special Elastic Load Balancing cookie follows the lifetime of the application-generated cookie specified in the policy configuration. The load balancer only inserts a new stickiness cookie when the application response includes a new application cookie. If the application cookie is explicitly removed or expires, the session stops being sticky until a new application cookie is issued. ) CookieNamerE PolicyNameCreateAppCookieStickinessPolicyri)r#rWr policy_namer7rrr#create_app_cookie_stickiness_policyMs  z1ELBConnection.create_app_cookie_stickiness_policycCs&||d}|dur ||d<|d|S)a1 Generates a stickiness policy with sticky session lifetimes controlled by the lifetime of the browser (user-agent) or a specified expiration period. This policy can only be associated only with HTTP listeners. When a load balancer implements this policy, the load balancer uses a special cookie to track the backend server instance for each request. When the load balancer receives a request, it first checks to see if this cookie is present in the request. If so, the load balancer sends the request to the application server specified in the cookie. If not, the load balancer sends the request to a server that is chosen based on the existing load balancing algorithm. A cookie is inserted into the response for binding subsequent requests from the same user to that server. The validity of the cookie is based on the cookie expiration time, which is specified in the policy configuration. None may be passed for cookie_expiration_period. rErNCookieExpirationPeriodCreateLBCookieStickinessPolicyri)r#cookie_expiration_periodrrr7rrr"create_lb_cookie_stickiness_policybs  z0ELBConnection.create_lb_cookie_stickiness_policyc CsV|||d}tt|dD]\}\}}||d|<||d|<qd|d<|d|S)a Creates a new policy that contains the necessary attributes depending on the policy type. Policies are settings that are saved for your load balancer and that can be applied to the front-end listener, or the back-end application server. )rErPolicyTypeNamer3z(PolicyAttributes.member.%d.AttributeNamez)PolicyAttributes.member.%d.AttributeValuePolicyAttributesCreateLoadBalancerPolicy)r6r iteritemsrf) r#rr policy_typepolicy_attributesr7r:rWrrrrcreate_lb_policy~s   zELBConnection.create_lb_policycCs||d}|d|S)z} Deletes a policy from the LoadBalancer. The specified policy must not be enabled for any listeners. rDeleteLoadBalancerPolicyri)r#rrr7rrrdelete_lb_policys zELBConnection.delete_lb_policycCs6||d}t|r|||dnd|d<|d|S)z Associates, updates, or disables a policy with a listener on the load balancer. Currently only zero (0) or one (1) policy can be associated with a listener. )rErPolicyNames.member.%dr PolicyNames!SetLoadBalancerPoliciesOfListener)lenr<rf)r#rrpoliciesr7rrrset_lb_policies_of_listeners z)ELBConnection.set_lb_policies_of_listenercCs2||d}|r|||dnd|d<|d|S)z Replaces the current set of policies associated with a port on which the back-end server is listening with a new set of policies. )rE InstancePortrrr'SetLoadBalancerPoliciesForBackendServer)r<rf)r#r instance_portrr7rrr!set_lb_policies_of_backend_serversz/ELBConnection.set_lb_policies_of_backend_servercC$d|i}|||d|d|dS)a Associates one or more security groups with the load balancer. The provided security groups will override any currently applied security groups. :type name: string :param name: The name of the Load Balancer :type security_groups: List of strings :param security_groups: The name of the security group(s) to add. :rtype: List of strings :return: An updated list of security groups for this Load Balancer. rErS!ApplySecurityGroupsToLoadBalancerNr<r@)r#rWr[r7rrrapply_security_groups_to_lbz)ELBConnection.apply_security_groups_to_lbcCr)a Attaches load balancer to one or more subnets. Attaching subnets that are already registered with the Load Balancer has no effect. :type name: string :param name: The name of the Load Balancer :type subnets: List of strings :param subnets: The name of the subnet(s) to add. :rtype: List of strings :return: An updated list of subnets for this Load Balancer. rErRAttachLoadBalancerToSubnetsNrr#rWrZr7rrrattach_lb_to_subnetsrz"ELBConnection.attach_lb_to_subnetscCr)a\ Detaches load balancer from one or more subnets. :type name: string :param name: The name of the Load Balancer :type subnets: List of strings :param subnets: The name of the subnet(s) to detach. :rtype: List of strings :return: An updated list of subnets for this Load Balancer. rErRDetachLoadBalancerFromSubnetsNrrrrrdetach_lb_from_subnetssz$ELBConnection.detach_lb_from_subnets)NNTNNNNNrNNrNTN)NN)NNNrDN)N)%__name__ __module__ __qualname__botoconfigget APIVersionrrr!r2r<rCrdrgrjrmrtrwrrrrrrrrrrrrrrrrr __classcell__rrr0rrBsX  r B 7   r)__doc__boto.connectionrboto.ec2.instanceinforboto.ec2.elb.loadbalancerrrboto.ec2.elb.instancestaterboto.ec2.elb.healthcheckrboto.regioninforr r r r boto.compatr r RegionDatarrrrrrrs