PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/boto-2.5.2/boto/ec2/elb/healthcheck.py

#
Python | 87 lines | 44 code | 6 blank | 37 comment | 3 complexity | bbec381b285030c52f629bacfcab0e1c MD5 | raw file
 1# Copyright (c) 2006-2009 Mitch Garnaat http://garnaat.org/
 2#
 3# Permission is hereby granted, free of charge, to any person obtaining a
 4# copy of this software and associated documentation files (the
 5# "Software"), to deal in the Software without restriction, including
 6# without limitation the rights to use, copy, modify, merge, publish, dis-
 7# tribute, sublicense, and/or sell copies of the Software, and to permit
 8# persons to whom the Software is furnished to do so, subject to the fol-
 9# lowing conditions:
10#
11# The above copyright notice and this permission notice shall be included
12# in all copies or substantial portions of the Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20# IN THE SOFTWARE.
21
22class HealthCheck(object):
23    """
24    Represents an EC2 Access Point Health Check. See
25    :ref:`elb-configuring-a-health-check` for a walkthrough on configuring
26    load balancer health checks.
27    """
28    def __init__(self, access_point=None, interval=30, target=None,
29                 healthy_threshold=3, timeout=5, unhealthy_threshold=5):
30        """
31        :ivar str access_point: The name of the load balancer this
32            health check is associated with.
33        :ivar int interval: Specifies how many seconds there are between
34            health checks.
35        :ivar str target: Determines what to check on an instance. See the
36            Amazon HealthCheck_ documentation for possible Target values.
37
38        .. _HealthCheck: http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/API_HealthCheck.html
39        """
40        self.access_point = access_point
41        self.interval = interval
42        self.target = target
43        self.healthy_threshold = healthy_threshold
44        self.timeout = timeout
45        self.unhealthy_threshold = unhealthy_threshold
46
47    def __repr__(self):
48        return 'HealthCheck:%s' % self.target
49
50    def startElement(self, name, attrs, connection):
51        return None
52
53    def endElement(self, name, value, connection):
54        if name == 'Interval':
55            self.interval = int(value)
56        elif name == 'Target':
57            self.target = value
58        elif name == 'HealthyThreshold':
59            self.healthy_threshold = int(value)
60        elif name == 'Timeout':
61            self.timeout = int(value)
62        elif name == 'UnhealthyThreshold':
63            self.unhealthy_threshold = int(value)
64        else:
65            setattr(self, name, value)
66
67    def update(self):
68        """
69        In the case where you have accessed an existing health check on a
70        load balancer, this method applies this instance's health check
71        values to the load balancer it is attached to.
72
73        .. note:: This method will not do anything if the :py:attr:`access_point`
74            attribute isn't set, as is the case with a newly instantiated
75            HealthCheck instance.
76        """
77        if not self.access_point:
78            return
79
80        new_hc = self.connection.configure_health_check(self.access_point, self)
81        self.interval = new_hc.interval
82        self.target = new_hc.target
83        self.healthy_threshold = new_hc.healthy_threshold
84        self.unhealthy_threshold = new_hc.unhealthy_threshold
85        self.timeout = new_hc.timeout
86
87