PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Python | 87 lines | 44 code | 6 blank | 37 comment | 7 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. class HealthCheck(object):
  22. """
  23. Represents an EC2 Access Point Health Check. See
  24. :ref:`elb-configuring-a-health-check` for a walkthrough on configuring
  25. load balancer health checks.
  26. """
  27. def __init__(self, access_point=None, interval=30, target=None,
  28. healthy_threshold=3, timeout=5, unhealthy_threshold=5):
  29. """
  30. :ivar str access_point: The name of the load balancer this
  31. health check is associated with.
  32. :ivar int interval: Specifies how many seconds there are between
  33. health checks.
  34. :ivar str target: Determines what to check on an instance. See the
  35. Amazon HealthCheck_ documentation for possible Target values.
  36. .. _HealthCheck: http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/API_HealthCheck.html
  37. """
  38. self.access_point = access_point
  39. self.interval = interval
  40. self.target = target
  41. self.healthy_threshold = healthy_threshold
  42. self.timeout = timeout
  43. self.unhealthy_threshold = unhealthy_threshold
  44. def __repr__(self):
  45. return 'HealthCheck:%s' % self.target
  46. def startElement(self, name, attrs, connection):
  47. return None
  48. def endElement(self, name, value, connection):
  49. if name == 'Interval':
  50. self.interval = int(value)
  51. elif name == 'Target':
  52. self.target = value
  53. elif name == 'HealthyThreshold':
  54. self.healthy_threshold = int(value)
  55. elif name == 'Timeout':
  56. self.timeout = int(value)
  57. elif name == 'UnhealthyThreshold':
  58. self.unhealthy_threshold = int(value)
  59. else:
  60. setattr(self, name, value)
  61. def update(self):
  62. """
  63. In the case where you have accessed an existing health check on a
  64. load balancer, this method applies this instance's health check
  65. values to the load balancer it is attached to.
  66. .. note:: This method will not do anything if the :py:attr:`access_point`
  67. attribute isn't set, as is the case with a newly instantiated
  68. HealthCheck instance.
  69. """
  70. if not self.access_point:
  71. return
  72. new_hc = self.connection.configure_health_check(self.access_point, self)
  73. self.interval = new_hc.interval
  74. self.target = new_hc.target
  75. self.healthy_threshold = new_hc.healthy_threshold
  76. self.unhealthy_threshold = new_hc.unhealthy_threshold
  77. self.timeout = new_hc.timeout