Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(706)

Side by Side Diff: third_party/gsutil/boto/ec2/blockdevicemapping.py

Issue 12042069: Scripts to download files from google storage based on sha1 sums (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Removed gsutil/tests and gsutil/docs Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright (c) 2009-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 #
23
24
25 class BlockDeviceType(object):
26 """
27 Represents parameters for a block device.
28 """
29
30 def __init__(self,
31 connection=None,
32 ephemeral_name=None,
33 no_device=False,
34 volume_id=None,
35 snapshot_id=None,
36 status=None,
37 attach_time=None,
38 delete_on_termination=False,
39 size=None,
40 volume_type=None,
41 iops=None):
42 self.connection = connection
43 self.ephemeral_name = ephemeral_name
44 self.no_device = no_device
45 self.volume_id = volume_id
46 self.snapshot_id = snapshot_id
47 self.status = status
48 self.attach_time = attach_time
49 self.delete_on_termination = delete_on_termination
50 self.size = size
51 self.volume_type = volume_type
52 self.iops = iops
53
54 def startElement(self, name, attrs, connection):
55 pass
56
57 def endElement(self, name, value, connection):
58 if name == 'volumeId':
59 self.volume_id = value
60 elif name == 'virtualName':
61 self.ephemeral_name = value
62 elif name == 'NoDevice':
63 self.no_device = (value == 'true')
64 elif name == 'snapshotId':
65 self.snapshot_id = value
66 elif name == 'volumeSize':
67 self.size = int(value)
68 elif name == 'status':
69 self.status = value
70 elif name == 'attachTime':
71 self.attach_time = value
72 elif name == 'deleteOnTermination':
73 self.delete_on_termination = (value == 'true')
74 elif name == 'volumeType':
75 self.volume_type = value
76 elif name == 'iops':
77 self.iops = int(value)
78 else:
79 setattr(self, name, value)
80
81 # for backwards compatibility
82 EBSBlockDeviceType = BlockDeviceType
83
84
85 class BlockDeviceMapping(dict):
86 """
87 Represents a collection of BlockDeviceTypes when creating ec2 instances.
88
89 Example:
90 dev_sda1 = BlockDeviceType()
91 dev_sda1.size = 100 # change root volume to 100GB instead of default
92 bdm = BlockDeviceMapping()
93 bdm['/dev/sda1'] = dev_sda1
94 reservation = image.run(..., block_device_map=bdm, ...)
95 """
96
97 def __init__(self, connection=None):
98 """
99 :type connection: :class:`boto.ec2.EC2Connection`
100 :param connection: Optional connection.
101 """
102 dict.__init__(self)
103 self.connection = connection
104 self.current_name = None
105 self.current_value = None
106
107 def startElement(self, name, attrs, connection):
108 if name == 'ebs' or name == 'virtualName':
109 self.current_value = BlockDeviceType(self)
110 return self.current_value
111
112 def endElement(self, name, value, connection):
113 if name == 'device' or name == 'deviceName':
114 self.current_name = value
115 elif name == 'item':
116 self[self.current_name] = self.current_value
117
118 def build_list_params(self, params, prefix=''):
119 i = 1
120 for dev_name in self:
121 pre = '%sBlockDeviceMapping.%d' % (prefix, i)
122 params['%s.DeviceName' % pre] = dev_name
123 block_dev = self[dev_name]
124 if block_dev.ephemeral_name:
125 params['%s.VirtualName' % pre] = block_dev.ephemeral_name
126 else:
127 if block_dev.no_device:
128 params['%s.Ebs.NoDevice' % pre] = 'true'
129 if block_dev.snapshot_id:
130 params['%s.Ebs.SnapshotId' % pre] = block_dev.snapshot_id
131 if block_dev.size:
132 params['%s.Ebs.VolumeSize' % pre] = block_dev.size
133 if block_dev.delete_on_termination:
134 params['%s.Ebs.DeleteOnTermination' % pre] = 'true'
135 else:
136 params['%s.Ebs.DeleteOnTermination' % pre] = 'false'
137 if block_dev.volume_type:
138 params['%s.Ebs.VolumeType' % pre] = block_dev.volume_type
139 if block_dev.iops is not None:
140 params['%s.Ebs.Iops' % pre] = block_dev.iops
141 i += 1
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698