1# Permission is hereby granted, free of charge, to any person obtaining a
2# copy of this software and associated documentation files (the
3# "Software"), to deal in the Software without restriction, including
4# without limitation the rights to use, copy, modify, merge, publish, dis-
5# tribute, sublicense, and/or sell copies of the Software, and to permit
6# persons to whom the Software is furnished to do so, subject to the fol-
7# lowing conditions:
8#
9# The above copyright notice and this permission notice shall be included
10# in all copies or substantial portions of the Software.
11#
12# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
13# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
14# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
15# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
16# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18# IN THE SOFTWARE.
19#
20# Created by Chris Huegle for TellApart, Inc.
21
22class ConnectionSettingAttribute(object):
23    """
24    Represents the ConnectionSetting segment of ELB Attributes.
25    """
26    def __init__(self, connection=None):
27        self.idle_timeout = None
28
29    def __repr__(self):
30        return 'ConnectionSettingAttribute(%s)' % (
31            self.idle_timeout)
32
33    def startElement(self, name, attrs, connection):
34        pass
35
36    def endElement(self, name, value, connection):
37        if name == 'IdleTimeout':
38            self.idle_timeout = int(value)
39
40class CrossZoneLoadBalancingAttribute(object):
41    """
42    Represents the CrossZoneLoadBalancing segement of ELB Attributes.
43    """
44    def __init__(self, connection=None):
45        self.enabled = None
46
47    def __repr__(self):
48        return 'CrossZoneLoadBalancingAttribute(%s)' % (
49            self.enabled)
50
51    def startElement(self, name, attrs, connection):
52        pass
53
54    def endElement(self, name, value, connection):
55        if name == 'Enabled':
56            if value.lower() == 'true':
57                self.enabled = True
58            else:
59                self.enabled = False
60
61
62class AccessLogAttribute(object):
63    """
64    Represents the AccessLog segment of ELB attributes.
65    """
66    def __init__(self, connection=None):
67        self.enabled = None
68        self.s3_bucket_name = None
69        self.s3_bucket_prefix = None
70        self.emit_interval = None
71
72    def __repr__(self):
73        return 'AccessLog(%s, %s, %s, %s)' % (
74            self.enabled,
75            self.s3_bucket_name,
76            self.s3_bucket_prefix,
77            self.emit_interval
78        )
79
80    def startElement(self, name, attrs, connection):
81        pass
82
83    def endElement(self, name, value, connection):
84        if name == 'Enabled':
85            if value.lower() == 'true':
86                self.enabled = True
87            else:
88                self.enabled = False
89        elif name == 'S3BucketName':
90            self.s3_bucket_name = value
91        elif name == 'S3BucketPrefix':
92            self.s3_bucket_prefix = value
93        elif name == 'EmitInterval':
94            self.emit_interval = int(value)
95
96
97class ConnectionDrainingAttribute(object):
98    """
99    Represents the ConnectionDraining segment of ELB attributes.
100    """
101    def __init__(self, connection=None):
102        self.enabled = None
103        self.timeout = None
104
105    def __repr__(self):
106        return 'ConnectionDraining(%s, %s)' % (
107            self.enabled,
108            self.timeout
109        )
110
111    def startElement(self, name, attrs, connection):
112        pass
113
114    def endElement(self, name, value, connection):
115        if name == 'Enabled':
116            if value.lower() == 'true':
117                self.enabled = True
118            else:
119                self.enabled = False
120        elif name == 'Timeout':
121            self.timeout = int(value)
122
123
124class LbAttributes(object):
125    """
126    Represents the Attributes of an Elastic Load Balancer.
127    """
128    def __init__(self, connection=None):
129        self.connection = connection
130        self.cross_zone_load_balancing = CrossZoneLoadBalancingAttribute(
131            self.connection)
132        self.access_log = AccessLogAttribute(self.connection)
133        self.connection_draining = ConnectionDrainingAttribute(self.connection)
134        self.connecting_settings = ConnectionSettingAttribute(self.connection)
135
136    def __repr__(self):
137        return 'LbAttributes(%s, %s, %s, %s)' % (
138            repr(self.cross_zone_load_balancing),
139            repr(self.access_log),
140            repr(self.connection_draining),
141            repr(self.connecting_settings))
142
143    def startElement(self, name, attrs, connection):
144        if name == 'CrossZoneLoadBalancing':
145            return self.cross_zone_load_balancing
146        if name == 'AccessLog':
147            return self.access_log
148        if name == 'ConnectionDraining':
149            return self.connection_draining
150        if name == 'ConnectionSettings':
151            return self.connecting_settings
152
153    def endElement(self, name, value, connection):
154        pass
155