PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/boto-2.5.2/boto/ec2/launchspecification.py

#
Python | 96 lines | 61 code | 12 blank | 23 comment | 5 complexity | fec2126cc129a247881757fd701e6846 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
22"""
23Represents a launch specification for Spot instances.
24"""
25
26from boto.ec2.ec2object import EC2Object
27from boto.resultset import ResultSet
28from boto.ec2.blockdevicemapping import BlockDeviceMapping
29from boto.ec2.group import Group
30
31class GroupList(list):
32
33    def startElement(self, name, attrs, connection):
34        pass
35
36    def endElement(self, name, value, connection):
37        if name == 'groupId':
38            self.append(value)
39            
40class LaunchSpecification(EC2Object):
41    
42    def __init__(self, connection=None):
43        EC2Object.__init__(self, connection)
44        self.key_name = None
45        self.instance_type = None
46        self.image_id = None
47        self.groups = []
48        self.placement = None
49        self.kernel = None
50        self.ramdisk = None
51        self.monitored = False
52        self.subnet_id = None
53        self._in_monitoring_element = False
54        self.block_device_mapping = None
55
56    def __repr__(self):
57        return 'LaunchSpecification(%s)' % self.image_id
58
59    def startElement(self, name, attrs, connection):
60        if name == 'groupSet':
61            self.groups = ResultSet([('item', Group)])
62            return self.groups
63        elif name == 'monitoring':
64            self._in_monitoring_element = True
65        elif name == 'blockDeviceMapping':
66            self.block_device_mapping = BlockDeviceMapping()
67            return self.block_device_mapping
68        else:
69            return None
70
71    def endElement(self, name, value, connection):
72        if name == 'imageId':
73            self.image_id = value
74        elif name == 'keyName':
75            self.key_name = value
76        elif name == 'instanceType':
77            self.instance_type = value
78        elif name == 'availabilityZone':
79            self.placement = value
80        elif name == 'placement':
81            pass
82        elif name == 'kernelId':
83            self.kernel = value
84        elif name == 'ramdiskId':
85            self.ramdisk = value
86        elif name == 'subnetId':
87            self.subnet_id = value
88        elif name == 'state':
89            if self._in_monitoring_element:
90                if value == 'enabled':
91                    self.monitored = True
92                self._in_monitoring_element = False
93        else:
94            setattr(self, name, value)
95
96