PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Python | 87 lines | 40 code | 14 blank | 33 comment | 9 complexity | e8bfbfd0ad4d094a8e4683cee9c8dde8 MD5 | raw file
  1. # Copyright (c) 2010 Mitch Garnaat http://garnaat.org/
  2. # Copyright (c) 2010, Eucalyptus Systems, Inc.
  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 TagSet(dict):
  23. """
  24. A TagSet is used to collect the tags associated with a particular
  25. EC2 resource. Not all resources can be tagged but for those that
  26. can, this dict object will be used to collect those values. See
  27. :class:`boto.ec2.ec2object.TaggedEC2Object` for more details.
  28. """
  29. def __init__(self, connection=None):
  30. self.connection = connection
  31. self._current_key = None
  32. self._current_value = None
  33. def startElement(self, name, attrs, connection):
  34. if name == 'item':
  35. self._current_key = None
  36. self._current_value = None
  37. return None
  38. def endElement(self, name, value, connection):
  39. if name == 'key':
  40. self._current_key = value
  41. elif name == 'value':
  42. self._current_value = value
  43. elif name == 'item':
  44. self[self._current_key] = self._current_value
  45. class Tag(object):
  46. """
  47. A Tag is used when creating or listing all tags related to
  48. an AWS account. It records not only the key and value but
  49. also the ID of the resource to which the tag is attached
  50. as well as the type of the resource.
  51. """
  52. def __init__(self, connection=None, res_id=None, res_type=None,
  53. name=None, value=None):
  54. self.connection = connection
  55. self.res_id = res_id
  56. self.res_type = res_type
  57. self.name = name
  58. self.value = value
  59. def __repr__(self):
  60. return 'Tag:%s' % self.name
  61. def startElement(self, name, attrs, connection):
  62. return None
  63. def endElement(self, name, value, connection):
  64. if name == 'resourceId':
  65. self.res_id = value
  66. elif name == 'resourceType':
  67. self.res_type = value
  68. elif name == 'key':
  69. self.name = value
  70. elif name == 'value':
  71. self.value = value
  72. else:
  73. setattr(self, name, value)