Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add ELB access log support #2150

Merged
merged 1 commit into from

2 participants

@danielgtaylor

Implements http://aws.amazon.com/releasenotes/2931833491682296 and adds an integration test for the new feature.

@toastdriven, please review.

@danielgtaylor danielgtaylor self-assigned this
@toastdriven

This looks good. :ship: it!

@danielgtaylor danielgtaylor merged commit 7aa35ea into boto:develop
@danielgtaylor danielgtaylor deleted the danielgtaylor:elb-access-log branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 6, 2014
  1. @danielgtaylor
This page is out of date. Refresh to see the latest.
View
10 boto/ec2/elb/__init__.py
@@ -385,6 +385,7 @@ def modify_lb_attribute(self, load_balancer_name, attribute, value):
:param attribute: The attribute you wish to change.
* crossZoneLoadBalancing - Boolean (true)
+ * accessLog - :py:class:`AccessLogAttribute` instance
:type value: string
:param value: The new value for the attribute
@@ -405,6 +406,15 @@ def modify_lb_attribute(self, load_balancer_name, attribute, value):
if attribute.lower() == 'crosszoneloadbalancing':
params['LoadBalancerAttributes.CrossZoneLoadBalancing.Enabled'
] = value
+ elif attribute.lower() == 'accesslog':
+ params['LoadBalancerAttributes.AccessLog.Enabled'] = \
+ value.enabled and 'true' or 'false'
+ params['LoadBalancerAttributes.AccessLog.S3BucketName'] = \
+ value.s3_bucket_name
+ params['LoadBalancerAttributes.AccessLog.S3BucketPrefix'] = \
+ value.s3_bucket_prefix
+ params['LoadBalancerAttributes.AccessLog.EmitInterval'] = \
+ value.emit_interval
else:
raise ValueError('InvalidAttribute', attribute)
return self.get_status('ModifyLoadBalancerAttributes', params,
View
45 boto/ec2/elb/attributes.py
@@ -40,6 +40,41 @@ def endElement(self, name, value, connection):
else:
self.enabled = False
+class AccessLogAttribute(object):
+ """
+ Represents the AccessLog segment of ELB attributes.
+ """
+ def __init__(self, connection=None):
+ self.enabled = None
+ self.s3_bucket_name = None
+ self.s3_bucket_prefix = None
+ self.emit_interval = None
+
+ def __repr__(self):
+ return 'AccessLog(%s, %s, %s, %s)' % (
+ self.enabled,
+ self.s3_bucket_name,
+ self.s3_bucket_prefix,
+ self.emit_interval
+ )
+
+ def startElement(self, name, attrs, connection):
+ pass
+
+ def endElement(self, name, value, connection):
+ if name == 'Enabled':
+ if value.lower() == 'true':
+ self.enabled = True
+ else:
+ self.enabled = False
+ elif name == 'S3BucketName':
+ self.s3_bucket_name = value
+ elif name == 'S3BucketPrefix':
+ self.s3_bucket_prefix = value
+ elif name == 'EmitInterval':
+ self.emit_interval = int(value)
+
+
class LbAttributes(object):
"""
Represents the Attributes of an Elastic Load Balancer.
@@ -48,14 +83,18 @@ def __init__(self, connection=None):
self.connection = connection
self.cross_zone_load_balancing = CrossZoneLoadBalancingAttribute(
self.connection)
+ self.access_log = AccessLogAttribute(self.connection)
def __repr__(self):
- return 'LbAttributes(%s)' % (
- repr(self.cross_zone_load_balancing))
+ return 'LbAttributes(%s, %s)' % (
+ repr(self.cross_zone_load_balancing),
+ repr(self.access_log))
def startElement(self, name, attrs, connection):
if name == 'CrossZoneLoadBalancing':
return self.cross_zone_load_balancing
-
+ if name == 'AccessLog':
+ return self.access_log
+
def endElement(self, name, value, connection):
pass
View
38 tests/integration/ec2/elb/test_connection.py
@@ -24,6 +24,8 @@
Initial, and very limited, unit tests for ELBConnection.
"""
+import boto
+import time
import unittest
from boto.ec2.elb import ELBConnection
@@ -39,6 +41,19 @@ def setUp(self):
self.listeners = [(80, 8000, 'HTTP')]
self.balancer = self.conn.create_load_balancer(self.name, self.availability_zones, self.listeners)
+ # S3 bucket for log tests
+ self.s3 = boto.connect_s3()
+ self.timestamp = str(int(time.time()))
+ self.bucket_name = 'boto-elb-%s' % self.timestamp
+ self.bucket = self.s3.create_bucket(self.bucket_name)
+ self.bucket.set_canned_acl('public-read-write')
+ self.addCleanup(self.cleanup_bucket, self.bucket)
+
+ def cleanup_bucket(self, bucket):
+ for key in bucket.get_all_keys():
+ key.delete()
+ bucket.delete()
+
def tearDown(self):
""" Deletes the test load balancer after every test.
It does not delete EVERY load balancer in your account"""
@@ -161,5 +176,28 @@ def test_create_load_balancer_complex_listeners(self):
sorted([(80, 8000, 'HTTP', 'HTTP')] + complex_listeners)
)
+ def test_load_balancer_access_log(self):
+ attributes = self.balancer.get_attributes()
+
+ self.assertEqual(False, attributes.access_log.enabled)
+
+ attributes.access_log.enabled = True
+ attributes.access_log.s3_bucket_name = self.bucket_name
+ attributes.access_log.s3_bucket_prefix = 'access-logs'
+ attributes.access_log.emit_interval = 5
+
+ self.conn.modify_lb_attribute(self.balancer.name, 'accessLog',
+ attributes.access_log)
+
+ new_attributes = self.balancer.get_attributes()
+
+ self.assertEqual(True, new_attributes.access_log.enabled)
+ self.assertEqual(self.bucket_name,
+ new_attributes.access_log.s3_bucket_name)
+ self.assertEqual('access-logs',
+ new_attributes.access_log.s3_bucket_prefix)
+ self.assertEqual(5, new_attributes.access_log.emit_interval)
+
+
if __name__ == '__main__':
unittest.main()
Something went wrong with that request. Please try again.