PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/boto-2.5.2/boto/ec2/autoscale/tag.py

#
Python | 84 lines | 53 code | 1 blank | 30 comment | 0 complexity | b35c266100fea548af2e883b51cb7931 MD5 | raw file
  1. # Copyright (c) 2012 Mitch Garnaat http://garnaat.org/
  2. # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a
  5. # copy of this software and associated documentation files (the
  6. # "Software"), to deal in the Software without restriction, including
  7. # without limitation the rights to use, copy, modify, merge, publish, dis-
  8. # tribute, sublicense, and/or sell copies of the Software, and to permit
  9. # persons to whom the Software is furnished to do so, subject to the fol-
  10. # lowing conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included
  13. # in all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  16. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
  17. # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  18. # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. # IN THE SOFTWARE.
  22. class Tag(object):
  23. """
  24. A name/value tag on an AutoScalingGroup resource.
  25. :ivar key: The key of the tag.
  26. :ivar value: The value of the tag.
  27. :ivar propagate_at_launch: Boolean value which specifies whether the
  28. new tag will be applied to instances launched after the tag is created.
  29. :ivar resource_id: The name of the autoscaling group.
  30. :ivar resource_type: The only supported resource type at this time
  31. is "auto-scaling-group".
  32. """
  33. def __init__(self, connection=None, key=None, value=None,
  34. propagate_at_launch=False, resource_id=None,
  35. resource_type='auto-scaling-group'):
  36. self.connection = connection
  37. self.key = key
  38. self.value = value
  39. self.propagate_at_launch = propagate_at_launch
  40. self.resource_id = resource_id
  41. self.resource_type = resource_type
  42. def __repr__(self):
  43. return 'Tag(%s=%s)' % (self.key, self.value)
  44. def startElement(self, name, attrs, connection):
  45. pass
  46. def endElement(self, name, value, connection):
  47. if name == 'Key':
  48. self.key = value
  49. elif name == 'Value':
  50. self.value = value
  51. elif name == 'PropogateAtLaunch':
  52. if value.lower() == 'true':
  53. self.propogate_at_launch = True
  54. else:
  55. self.propogate_at_launch = False
  56. elif name == 'ResourceId':
  57. self.resource_id = value
  58. elif name == 'ResourceType':
  59. self.resource_type = value
  60. def build_params(self, params, i):
  61. """
  62. Populates a dictionary with the name/value pairs necessary
  63. to identify this Tag in a request.
  64. """
  65. prefix = 'Tags.member.%d.' % i
  66. params[prefix+'ResourceId'] = self.resource_id
  67. params[prefix+'ResourceType'] = self.resource_type
  68. params[prefix+'Key'] = self.key
  69. params[prefix+'Value'] = self.value
  70. if self.propagate_at_launch:
  71. params[prefix+'PropagateAtLaunch'] = 'true'
  72. else:
  73. params[prefix+'PropagateAtLaunch'] = 'false'
  74. def delete(self):
  75. return self.connection.delete_tags([self])