1
# Copyright (c) 2009 Mitch Garnaat http://garnaat.org/
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-
11
# The above copyright notice and this permission notice shall be included
12
# in all copies or substantial portions of the Software.
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
23
class BlockDeviceType(object):
25
def __init__(self, connection=None):
26
self.connection = connection
27
self.ephemeral_name = None
29
self.snapshot_id = None
31
self.attach_time = None
32
self.delete_on_termination = False
35
def startElement(self, name, attrs, connection):
38
def endElement(self, name, value, connection):
40
self.volume_id = value
41
elif name == 'virtualName':
42
self.ephemeral_name = value
43
elif name =='snapshotId':
44
self.snapshot_id = value
45
elif name == 'volumeSize':
46
self.size = int(value)
47
elif name == 'status':
49
elif name == 'attachTime':
50
self.attach_time = value
51
elif name == 'deleteOnTermination':
53
self.delete_on_termination = True
55
self.delete_on_termination = False
57
setattr(self, name, value)
59
# for backwards compatibility
60
EBSBlockDeviceType = BlockDeviceType
62
class BlockDeviceMapping(dict):
64
def __init__(self, connection=None):
66
self.connection = connection
67
self.current_name = None
68
self.current_value = None
70
def startElement(self, name, attrs, connection):
72
self.current_value = BlockDeviceType(self)
73
return self.current_value
75
def endElement(self, name, value, connection):
76
if name == 'device' or name == 'deviceName':
77
self.current_name = value
79
self[self.current_name] = self.current_value
81
def build_list_params(self, params, prefix=''):
84
pre = '%sBlockDeviceMapping.%d' % (prefix, i)
85
params['%s.DeviceName' % pre] = dev_name
86
block_dev = self[dev_name]
87
if block_dev.ephemeral_name:
88
params['%s.VirtualName' % pre] = block_dev.ephemeral_name
90
if block_dev.snapshot_id:
91
params['%s.Ebs.SnapshotId' % pre] = block_dev.snapshot_id
93
params['%s.Ebs.VolumeSize' % pre] = block_dev.size
94
if block_dev.delete_on_termination:
95
params['%s.Ebs.DeleteOnTermination' % pre] = 'true'
97
params['%s.Ebs.DeleteOnTermination' % pre] = 'false'