~cbehrens/nova/lp844160-build-works-with-zones

« back to all changes in this revision

Viewing changes to vendor/boto/boto/ec2/blockdevicemapping.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 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
 
 
23
class BlockDeviceType(object):
 
24
 
 
25
    def __init__(self, connection=None):
 
26
        self.connection = connection
 
27
        self.ephemeral_name = None
 
28
        self.volume_id = None
 
29
        self.snapshot_id = None
 
30
        self.status = None
 
31
        self.attach_time = None
 
32
        self.delete_on_termination = False
 
33
        self.size = None
 
34
 
 
35
    def startElement(self, name, attrs, connection):
 
36
        pass
 
37
 
 
38
    def endElement(self, name, value, connection):
 
39
        if name =='volumeId':
 
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':
 
48
            self.status = value
 
49
        elif name == 'attachTime':
 
50
            self.attach_time = value
 
51
        elif name == 'deleteOnTermination':
 
52
            if value == 'true':
 
53
                self.delete_on_termination = True
 
54
            else:
 
55
                self.delete_on_termination = False
 
56
        else:
 
57
            setattr(self, name, value)
 
58
 
 
59
# for backwards compatibility
 
60
EBSBlockDeviceType = BlockDeviceType
 
61
 
 
62
class BlockDeviceMapping(dict):
 
63
 
 
64
    def __init__(self, connection=None):
 
65
        dict.__init__(self)
 
66
        self.connection = connection
 
67
        self.current_name = None
 
68
        self.current_value = None
 
69
 
 
70
    def startElement(self, name, attrs, connection):
 
71
        if name == 'ebs':
 
72
            self.current_value = BlockDeviceType(self)
 
73
            return self.current_value
 
74
 
 
75
    def endElement(self, name, value, connection):
 
76
        if name == 'device' or name == 'deviceName':
 
77
            self.current_name = value
 
78
        elif name == 'item':
 
79
            self[self.current_name] = self.current_value
 
80
 
 
81
    def build_list_params(self, params, prefix=''):
 
82
        i = 1
 
83
        for dev_name in self:
 
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
 
89
            else:
 
90
                if block_dev.snapshot_id:
 
91
                    params['%s.Ebs.SnapshotId' % pre] = block_dev.snapshot_id
 
92
                if block_dev.size:
 
93
                    params['%s.Ebs.VolumeSize' % pre] = block_dev.size
 
94
                if block_dev.delete_on_termination:
 
95
                    params['%s.Ebs.DeleteOnTermination' % pre] = 'true'
 
96
                else:
 
97
                    params['%s.Ebs.DeleteOnTermination' % pre] = 'false'
 
98
            i += 1