| OLD | NEW |
| 1 # Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/ | 1 # Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/ |
| 2 # Copyright (c) 2010, Eucalyptus Systems, Inc. | 2 # Copyright (c) 2010, Eucalyptus Systems, Inc. |
| 3 # | 3 # |
| 4 # Permission is hereby granted, free of charge, to any person obtaining a | 4 # Permission is hereby granted, free of charge, to any person obtaining a |
| 5 # copy of this software and associated documentation files (the | 5 # copy of this software and associated documentation files (the |
| 6 # "Software"), to deal in the Software without restriction, including | 6 # "Software"), to deal in the Software without restriction, including |
| 7 # without limitation the rights to use, copy, modify, merge, publish, dis- | 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 | 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- | 9 # persons to whom the Software is furnished to do so, subject to the fol- |
| 10 # lowing conditions: | 10 # lowing conditions: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 def __init__(self, connection=None): | 55 def __init__(self, connection=None): |
| 56 EC2Object.__init__(self, connection) | 56 EC2Object.__init__(self, connection) |
| 57 self.tags = TagSet() | 57 self.tags = TagSet() |
| 58 | 58 |
| 59 def startElement(self, name, attrs, connection): | 59 def startElement(self, name, attrs, connection): |
| 60 if name == 'tagSet': | 60 if name == 'tagSet': |
| 61 return self.tags | 61 return self.tags |
| 62 else: | 62 else: |
| 63 return None | 63 return None |
| 64 | 64 |
| 65 def add_tag(self, key, value=None): | 65 def add_tag(self, key, value=''): |
| 66 """ | 66 """ |
| 67 Add a tag to this object. Tag's are stored by AWS and can be used | 67 Add a tag to this object. Tag's are stored by AWS and can be used |
| 68 to organize and filter resources. Adding a tag involves a round-trip | 68 to organize and filter resources. Adding a tag involves a round-trip |
| 69 to the EC2 service. | 69 to the EC2 service. |
| 70 | 70 |
| 71 :type key: str | 71 :type key: str |
| 72 :param key: The key or name of the tag being stored. | 72 :param key: The key or name of the tag being stored. |
| 73 | 73 |
| 74 :type value: str | 74 :type value: str |
| 75 :param value: An optional value that can be stored with the tag. | 75 :param value: An optional value that can be stored with the tag. |
| 76 If you want only the tag name and no value, the |
| 77 value should be the empty string. |
| 76 """ | 78 """ |
| 77 status = self.connection.create_tags([self.id], {key : value}) | 79 status = self.connection.create_tags([self.id], {key : value}) |
| 78 if self.tags is None: | 80 if self.tags is None: |
| 79 self.tags = TagSet() | 81 self.tags = TagSet() |
| 80 self.tags[key] = value | 82 self.tags[key] = value |
| 81 | 83 |
| 82 def remove_tag(self, key, value=None): | 84 def remove_tag(self, key, value=None): |
| 83 """ | 85 """ |
| 84 Remove a tag from this object. Removing a tag involves a round-trip | 86 Remove a tag from this object. Removing a tag involves a round-trip |
| 85 to the EC2 service. | 87 to the EC2 service. |
| 86 | 88 |
| 87 :type key: str | 89 :type key: str |
| 88 :param key: The key or name of the tag being stored. | 90 :param key: The key or name of the tag being stored. |
| 89 | 91 |
| 90 :type value: str | 92 :type value: str |
| 91 :param value: An optional value that can be stored with the tag. | 93 :param value: An optional value that can be stored with the tag. |
| 92 If a value is provided, it must match the value | 94 If a value is provided, it must match the value |
| 93 currently stored in EC2. If not, the tag will not | 95 currently stored in EC2. If not, the tag will not |
| 94 be removed. | 96 be removed. If a value of None is provided, all |
| 97 tags with the specified name will be deleted. |
| 98 NOTE: There is an important distinction between |
| 99 a value of '' and a value of None. |
| 95 """ | 100 """ |
| 96 if value: | 101 if value: |
| 97 tags = {key : value} | 102 tags = {key : value} |
| 98 else: | 103 else: |
| 99 tags = [key] | 104 tags = [key] |
| 100 status = self.connection.delete_tags([self.id], tags) | 105 status = self.connection.delete_tags([self.id], tags) |
| 101 if key in self.tags: | 106 if key in self.tags: |
| 102 del self.tags[key] | 107 del self.tags[key] |
| OLD | NEW |