PageRenderTime 24ms CodeModel.GetById 19ms app.highlight 3ms 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
23class Tag(object):
24    """
25    A name/value tag on an AutoScalingGroup resource.
26
27    :ivar key: The key of the tag.
28    :ivar value: The value of the tag.
29    :ivar propagate_at_launch: Boolean value which specifies whether the
30        new tag will be applied to instances launched after the tag is created.
31    :ivar resource_id: The name of the autoscaling group.
32    :ivar resource_type: The only supported resource type at this time
33        is "auto-scaling-group".
34    """
35    
36    def __init__(self, connection=None, key=None, value=None,
37                 propagate_at_launch=False, resource_id=None,
38                 resource_type='auto-scaling-group'):
39        self.connection = connection
40        self.key = key
41        self.value = value
42        self.propagate_at_launch = propagate_at_launch
43        self.resource_id = resource_id
44        self.resource_type = resource_type
45
46    def __repr__(self):
47        return 'Tag(%s=%s)' % (self.key, self.value)
48
49    def startElement(self, name, attrs, connection):
50        pass
51
52    def endElement(self, name, value, connection):
53        if name == 'Key':
54            self.key = value
55        elif name == 'Value':
56            self.value = value
57        elif name == 'PropogateAtLaunch':
58            if value.lower() == 'true':
59                self.propogate_at_launch = True
60            else:
61                self.propogate_at_launch = False
62        elif name == 'ResourceId':
63            self.resource_id = value
64        elif name == 'ResourceType':
65            self.resource_type = value
66
67    def build_params(self, params, i):
68        """
69        Populates a dictionary with the name/value pairs necessary
70        to identify this Tag in a request.
71        """
72        prefix = 'Tags.member.%d.' % i
73        params[prefix+'ResourceId'] = self.resource_id
74        params[prefix+'ResourceType'] = self.resource_type
75        params[prefix+'Key'] = self.key
76        params[prefix+'Value'] = self.value
77        if self.propagate_at_launch:
78            params[prefix+'PropagateAtLaunch'] = 'true'
79        else:
80            params[prefix+'PropagateAtLaunch'] = 'false'
81
82    def delete(self):
83        return self.connection.delete_tags([self])
84