Merge branch 'master' of https://github.com/spulec/moto into 0.4.1-threadsafe
* 'master' of https://github.com/spulec/moto: (25 commits) Add @zkourouma to authors. 0.4.2 Fix bug where listener certificate was not being saved correctly when creating an elb. Added test to cover that case. [dynamodb2] adds lookup method to Table class Add IAM list_groups and list_groups_for_user. Closes #343. Fix for deleting Route53 record sets with set identifiers. Closes #342. Use dummy date instead of an invalid date Adding support for comments on hosted zones. Add availability zone support to Subnets created via CloudFormation Make availability zone dynamic in Subnet Response templates Add filter "availabilityZone" to DescribeSubnets and add availability zone support too allow starting without reseting Fix bug with empty string for instance vpc_id. Closes #337. Fix default security group description. Update responses.py Add @mrucci to authors. Fix merge conflicts. Add support for ELB attributes. cast to int when doing math. General cleanup. ...
This commit is contained in:
commit
e722b67f36
33 changed files with 1381 additions and 167 deletions
|
|
@ -1,6 +1,13 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import boto.ec2.elb
|
||||
from boto.ec2.elb.attributes import (
|
||||
LbAttributes,
|
||||
ConnectionSettingAttribute,
|
||||
ConnectionDrainingAttribute,
|
||||
AccessLogAttribute,
|
||||
CrossZoneLoadBalancingAttribute,
|
||||
)
|
||||
from moto.core import BaseBackend
|
||||
|
||||
|
||||
|
|
@ -29,6 +36,7 @@ class FakeLoadBalancer(object):
|
|||
self.instance_ids = []
|
||||
self.zones = zones
|
||||
self.listeners = []
|
||||
self.attributes = FakeLoadBalancer.get_default_attributes()
|
||||
|
||||
for protocol, lb_port, instance_port, ssl_certificate_id in ports:
|
||||
listener = FakeListener(
|
||||
|
|
@ -73,6 +81,28 @@ class FakeLoadBalancer(object):
|
|||
raise NotImplementedError('"Fn::GetAtt" : [ "{0}" , "SourceSecurityGroup.OwnerAlias" ]"')
|
||||
raise UnformattedGetAttTemplateException()
|
||||
|
||||
@classmethod
|
||||
def get_default_attributes(cls):
|
||||
attributes = LbAttributes()
|
||||
|
||||
cross_zone_load_balancing = CrossZoneLoadBalancingAttribute()
|
||||
cross_zone_load_balancing.enabled = False
|
||||
attributes.cross_zone_load_balancing = cross_zone_load_balancing
|
||||
|
||||
connection_draining = ConnectionDrainingAttribute()
|
||||
connection_draining.enabled = False
|
||||
attributes.connection_draining = connection_draining
|
||||
|
||||
access_log = AccessLogAttribute()
|
||||
access_log.enabled = False
|
||||
attributes.access_log = access_log
|
||||
|
||||
connection_settings = ConnectionSettingAttribute()
|
||||
connection_settings.idle_timeout = 60
|
||||
attributes.connecting_settings = connection_settings
|
||||
|
||||
return attributes
|
||||
|
||||
|
||||
class ELBBackend(BaseBackend):
|
||||
|
||||
|
|
@ -151,6 +181,26 @@ class ELBBackend(BaseBackend):
|
|||
load_balancer.instance_ids = new_instance_ids
|
||||
return load_balancer
|
||||
|
||||
def set_cross_zone_load_balancing_attribute(self, load_balancer_name, attribute):
|
||||
load_balancer = self.get_load_balancer(load_balancer_name)
|
||||
load_balancer.attributes.cross_zone_load_balancing = attribute
|
||||
return load_balancer
|
||||
|
||||
def set_access_log_attribute(self, load_balancer_name, attribute):
|
||||
load_balancer = self.get_load_balancer(load_balancer_name)
|
||||
load_balancer.attributes.access_log = attribute
|
||||
return load_balancer
|
||||
|
||||
def set_connection_draining_attribute(self, load_balancer_name, attribute):
|
||||
load_balancer = self.get_load_balancer(load_balancer_name)
|
||||
load_balancer.attributes.connection_draining = attribute
|
||||
return load_balancer
|
||||
|
||||
def set_connection_settings_attribute(self, load_balancer_name, attribute):
|
||||
load_balancer = self.get_load_balancer(load_balancer_name)
|
||||
load_balancer.attributes.connecting_settings = attribute
|
||||
return load_balancer
|
||||
|
||||
|
||||
elb_backends = {}
|
||||
for region in boto.ec2.elb.regions():
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
from __future__ import unicode_literals
|
||||
from boto.ec2.elb.attributes import (
|
||||
ConnectionSettingAttribute,
|
||||
ConnectionDrainingAttribute,
|
||||
AccessLogAttribute,
|
||||
CrossZoneLoadBalancingAttribute,
|
||||
)
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from .models import elb_backends
|
||||
|
|
@ -25,7 +31,7 @@ class ELBResponse(BaseResponse):
|
|||
break
|
||||
lb_port = self.querystring['Listeners.member.{0}.LoadBalancerPort'.format(port_index)][0]
|
||||
instance_port = self.querystring['Listeners.member.{0}.InstancePort'.format(port_index)][0]
|
||||
ssl_certificate_id = self.querystring.get('Listeners.member.{0}.SSLCertificateId'.format(port_index)[0], None)
|
||||
ssl_certificate_id = self.querystring.get('Listeners.member.{0}.SSLCertificateId'.format(port_index), [None])[0]
|
||||
ports.append([protocol, lb_port, instance_port, ssl_certificate_id])
|
||||
port_index += 1
|
||||
|
||||
|
|
@ -122,6 +128,64 @@ class ELBResponse(BaseResponse):
|
|||
load_balancer = self.elb_backend.deregister_instances(load_balancer_name, instance_ids)
|
||||
return template.render(load_balancer=load_balancer)
|
||||
|
||||
def describe_load_balancer_attributes(self):
|
||||
load_balancer_name = self.querystring.get('LoadBalancerName')[0]
|
||||
load_balancer = self.elb_backend.describe_load_balancers(load_balancer_name)[0]
|
||||
template = self.response_template(DESCRIBE_ATTRIBUTES_TEMPLATE)
|
||||
return template.render(attributes=load_balancer.attributes)
|
||||
|
||||
def modify_load_balancer_attributes(self):
|
||||
load_balancer_name = self.querystring.get('LoadBalancerName')[0]
|
||||
load_balancer = self.elb_backend.describe_load_balancers(load_balancer_name)[0]
|
||||
|
||||
def parse_attribute(attribute_name):
|
||||
"""
|
||||
Transform self.querystring parameters matching `LoadBalancerAttributes.attribute_name.attribute_key`
|
||||
into a dictionary of (attribute_name, attribute_key)` pairs.
|
||||
"""
|
||||
attribute_prefix = "LoadBalancerAttributes." + attribute_name
|
||||
return dict((key.lstrip(attribute_prefix), value[0]) for key, value in self.querystring.items() if key.startswith(attribute_prefix))
|
||||
|
||||
cross_zone = parse_attribute("CrossZoneLoadBalancing")
|
||||
if cross_zone:
|
||||
attribute = CrossZoneLoadBalancingAttribute()
|
||||
attribute.enabled = cross_zone["Enabled"] == "true"
|
||||
self.elb_backend.set_cross_zone_load_balancing_attribute(load_balancer_name, attribute)
|
||||
|
||||
access_log = parse_attribute("AccessLog")
|
||||
if access_log:
|
||||
attribute = AccessLogAttribute()
|
||||
attribute.enabled = access_log["Enabled"] == "true"
|
||||
attribute.s3_bucket_name = access_log["S3BucketName"]
|
||||
attribute.s3_bucket_prefix = access_log["S3BucketPrefix"]
|
||||
attribute.emit_interval = access_log["EmitInterval"]
|
||||
self.elb_backend.set_access_log_attribute(load_balancer_name, attribute)
|
||||
|
||||
connection_draining = parse_attribute("ConnectionDraining")
|
||||
if connection_draining:
|
||||
attribute = ConnectionDrainingAttribute()
|
||||
attribute.enabled = connection_draining["Enabled"] == "true"
|
||||
attribute.timeout = connection_draining["Timeout"]
|
||||
self.elb_backend.set_connection_draining_attribute(load_balancer_name, attribute)
|
||||
|
||||
connection_settings = parse_attribute("ConnectionSettings")
|
||||
if connection_settings:
|
||||
attribute = ConnectionSettingAttribute()
|
||||
attribute.idle_timeout = connection_settings["IdleTimeout"]
|
||||
self.elb_backend.set_connection_settings_attribute(load_balancer_name, attribute)
|
||||
|
||||
template = self.response_template(MODIFY_ATTRIBUTES_TEMPLATE)
|
||||
return template.render(attributes=load_balancer.attributes)
|
||||
|
||||
def describe_instance_health(self):
|
||||
load_balancer_name = self.querystring.get('LoadBalancerName')[0]
|
||||
instance_ids = [value[0] for key, value in self.querystring.items() if "Instances.member" in key]
|
||||
if len(instance_ids) == 0:
|
||||
instance_ids = self.elb_backend.describe_load_balancers(load_balancer_name)[0].instance_ids
|
||||
template = self.response_template(DESCRIBE_INSTANCE_HEALTH_TEMPLATE)
|
||||
return template.render(instance_ids=instance_ids)
|
||||
|
||||
|
||||
CREATE_LOAD_BALANCER_TEMPLATE = """<CreateLoadBalancerResult xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<DNSName>tests.us-east-1.elb.amazonaws.com</DNSName>
|
||||
</CreateLoadBalancerResult>"""
|
||||
|
|
@ -253,3 +317,84 @@ DELETE_LOAD_BALANCER_LISTENERS = """<DeleteLoadBalancerListenersResponse xmlns="
|
|||
<RequestId>83c88b9d-12b7-11e3-8b82-87b12EXAMPLE</RequestId>
|
||||
</ResponseMetadata>
|
||||
</DeleteLoadBalancerListenersResponse>"""
|
||||
|
||||
DESCRIBE_ATTRIBUTES_TEMPLATE = """<DescribeLoadBalancerAttributesResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<DescribeLoadBalancerAttributesResult>
|
||||
<LoadBalancerAttributes>
|
||||
<AccessLog>
|
||||
<Enabled>{{ attributes.access_log.enabled }}</Enabled>
|
||||
{% if attributes.access_log.enabled %}
|
||||
<S3BucketName>{{ attributes.access_log.s3_bucket_name }}</S3BucketName>
|
||||
<S3BucketPrefix>{{ attributes.access_log.s3_bucket_prefix }}</S3BucketPrefix>
|
||||
<EmitInterval>{{ attributes.access_log.emit_interval }}</EmitInterval>
|
||||
{% endif %}
|
||||
</AccessLog>
|
||||
<ConnectionSettings>
|
||||
<IdleTimeout>{{ attributes.connecting_settings.idle_timeout }}</IdleTimeout>
|
||||
</ConnectionSettings>
|
||||
<CrossZoneLoadBalancing>
|
||||
<Enabled>{{ attributes.cross_zone_load_balancing.enabled }}</Enabled>
|
||||
</CrossZoneLoadBalancing>
|
||||
<ConnectionDraining>
|
||||
<Enabled>{{ attributes.connection_draining.enabled }}</Enabled>
|
||||
{% if attributes.connection_draining.enabled %}
|
||||
<Timeout>{{ attributes.connection_draining.timeout }}</Timeout>
|
||||
{% endif %}
|
||||
</ConnectionDraining>
|
||||
</LoadBalancerAttributes>
|
||||
</DescribeLoadBalancerAttributesResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>83c88b9d-12b7-11e3-8b82-87b12EXAMPLE</RequestId>
|
||||
</ResponseMetadata>
|
||||
</DescribeLoadBalancerAttributesResponse>
|
||||
"""
|
||||
|
||||
MODIFY_ATTRIBUTES_TEMPLATE = """<ModifyLoadBalancerAttributesResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<ModifyLoadBalancerAttributesResult>
|
||||
<LoadBalancerName>my-loadbalancer</LoadBalancerName>
|
||||
<LoadBalancerAttributes>
|
||||
<AccessLog>
|
||||
<Enabled>{{ attributes.access_log.enabled }}</Enabled>
|
||||
{% if attributes.access_log.enabled %}
|
||||
<S3BucketName>{{ attributes.access_log.s3_bucket_name }}</S3BucketName>
|
||||
<S3BucketPrefix>{{ attributes.access_log.s3_bucket_prefix }}</S3BucketPrefix>
|
||||
<EmitInterval>{{ attributes.access_log.emit_interval }}</EmitInterval>
|
||||
{% endif %}
|
||||
</AccessLog>
|
||||
<ConnectionSettings>
|
||||
<IdleTimeout>{{ attributes.connecting_settings.idle_timeout }}</IdleTimeout>
|
||||
</ConnectionSettings>
|
||||
<CrossZoneLoadBalancing>
|
||||
<Enabled>{{ attributes.cross_zone_load_balancing.enabled }}</Enabled>
|
||||
</CrossZoneLoadBalancing>
|
||||
<ConnectionDraining>
|
||||
<Enabled>{{ attributes.connection_draining.enabled }}</Enabled>
|
||||
{% if attributes.connection_draining.enabled %}
|
||||
<Timeout>{{ attributes.connection_draining.timeout }}</Timeout>
|
||||
{% endif %}
|
||||
</ConnectionDraining>
|
||||
</LoadBalancerAttributes>
|
||||
</ModifyLoadBalancerAttributesResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>83c88b9d-12b7-11e3-8b82-87b12EXAMPLE</RequestId>
|
||||
</ResponseMetadata>
|
||||
</ModifyLoadBalancerAttributesResponse>
|
||||
"""
|
||||
|
||||
DESCRIBE_INSTANCE_HEALTH_TEMPLATE = """<DescribeInstanceHealthResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<DescribeInstanceHealthResult>
|
||||
<InstanceStates>
|
||||
{% for instance_id in instance_ids %}
|
||||
<member>
|
||||
<Description>N/A</Description>
|
||||
<InstanceId>{{ instance_id }}</InstanceId>
|
||||
<State>InService</State>
|
||||
<ReasonCode>N/A</ReasonCode>
|
||||
</member>
|
||||
{% endfor %}
|
||||
</InstanceStates>
|
||||
</DescribeInstanceHealthResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>1549581b-12b7-11e3-895e-1334aEXAMPLE</RequestId>
|
||||
</ResponseMetadata>
|
||||
</DescribeInstanceHealthResponse>"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue