Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/boto/ec2/snapshot.py @ 0:d30785e31577 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:18:57 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d30785e31577 |
---|---|
1 # Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/ | |
2 # Copyright (c) 2010, Eucalyptus Systems, Inc. | |
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 Represents an EC2 Elastic Block Store Snapshot | |
25 """ | |
26 from boto.ec2.ec2object import TaggedEC2Object | |
27 from boto.ec2.zone import Zone | |
28 | |
29 | |
30 class Snapshot(TaggedEC2Object): | |
31 """ | |
32 Represents an EBS snapshot. | |
33 :ivar id: The unique ID of the snapshot. | |
34 :ivar volume_id: The ID of the volume this snapshot was created | |
35 from. | |
36 :ivar status: The status of the snapshot. | |
37 :ivar progress: The percent complete of the snapshot. | |
38 :ivar start_time: The timestamp of when the snapshot was created. | |
39 :ivar owner_id: The id of the account that owns the snapshot. | |
40 :ivar owner_alias: The alias of the account that owns the snapshot. | |
41 :ivar volume_size: The size (in GB) of the volume the snapshot was created from. | |
42 :ivar description: The description of the snapshot. | |
43 :ivar encrypted: True if this snapshot is encrypted | |
44 """ | |
45 | |
46 AttrName = 'createVolumePermission' | |
47 | |
48 def __init__(self, connection=None): | |
49 super(Snapshot, self).__init__(connection) | |
50 self.id = None | |
51 self.volume_id = None | |
52 self.status = None | |
53 self.progress = None | |
54 self.start_time = None | |
55 self.owner_id = None | |
56 self.owner_alias = None | |
57 self.volume_size = None | |
58 self.description = None | |
59 self.encrypted = None | |
60 | |
61 def __repr__(self): | |
62 return 'Snapshot:%s' % self.id | |
63 | |
64 def endElement(self, name, value, connection): | |
65 if name == 'snapshotId': | |
66 self.id = value | |
67 elif name == 'volumeId': | |
68 self.volume_id = value | |
69 elif name == 'status': | |
70 self.status = value | |
71 elif name == 'startTime': | |
72 self.start_time = value | |
73 elif name == 'ownerId': | |
74 self.owner_id = value | |
75 elif name == 'ownerAlias': | |
76 self.owner_alias = value | |
77 elif name == 'volumeSize': | |
78 try: | |
79 self.volume_size = int(value) | |
80 except: | |
81 self.volume_size = value | |
82 elif name == 'description': | |
83 self.description = value | |
84 elif name == 'encrypted': | |
85 self.encrypted = (value.lower() == 'true') | |
86 else: | |
87 setattr(self, name, value) | |
88 | |
89 def _update(self, updated): | |
90 self.progress = updated.progress | |
91 self.status = updated.status | |
92 | |
93 def update(self, validate=False, dry_run=False): | |
94 """ | |
95 Update the data associated with this snapshot by querying EC2. | |
96 | |
97 :type validate: bool | |
98 :param validate: By default, if EC2 returns no data about the | |
99 snapshot the update method returns quietly. If | |
100 the validate param is True, however, it will | |
101 raise a ValueError exception if no data is | |
102 returned from EC2. | |
103 """ | |
104 rs = self.connection.get_all_snapshots([self.id], dry_run=dry_run) | |
105 if len(rs) > 0: | |
106 self._update(rs[0]) | |
107 elif validate: | |
108 raise ValueError('%s is not a valid Snapshot ID' % self.id) | |
109 return self.progress | |
110 | |
111 def delete(self, dry_run=False): | |
112 return self.connection.delete_snapshot(self.id, dry_run=dry_run) | |
113 | |
114 def get_permissions(self, dry_run=False): | |
115 attrs = self.connection.get_snapshot_attribute( | |
116 self.id, | |
117 self.AttrName, | |
118 dry_run=dry_run | |
119 ) | |
120 return attrs.attrs | |
121 | |
122 def share(self, user_ids=None, groups=None, dry_run=False): | |
123 return self.connection.modify_snapshot_attribute(self.id, | |
124 self.AttrName, | |
125 'add', | |
126 user_ids, | |
127 groups, | |
128 dry_run=dry_run) | |
129 | |
130 def unshare(self, user_ids=None, groups=None, dry_run=False): | |
131 return self.connection.modify_snapshot_attribute(self.id, | |
132 self.AttrName, | |
133 'remove', | |
134 user_ids, | |
135 groups, | |
136 dry_run=dry_run) | |
137 | |
138 def reset_permissions(self, dry_run=False): | |
139 return self.connection.reset_snapshot_attribute( | |
140 self.id, | |
141 self.AttrName, | |
142 dry_run=dry_run | |
143 ) | |
144 | |
145 def create_volume(self, zone, size=None, volume_type=None, iops=None, | |
146 dry_run=False): | |
147 """ | |
148 Create a new EBS Volume from this Snapshot | |
149 | |
150 :type zone: string or :class:`boto.ec2.zone.Zone` | |
151 :param zone: The availability zone in which the Volume will be created. | |
152 | |
153 :type size: int | |
154 :param size: The size of the new volume, in GiB. (optional). Defaults to | |
155 the size of the snapshot. | |
156 | |
157 :type volume_type: string | |
158 :param volume_type: The type of the volume. (optional). Valid | |
159 values are: standard | io1 | gp2. | |
160 | |
161 :type iops: int | |
162 :param iops: The provisioned IOPs you want to associate with | |
163 this volume. (optional) | |
164 """ | |
165 if isinstance(zone, Zone): | |
166 zone = zone.name | |
167 return self.connection.create_volume( | |
168 size, | |
169 zone, | |
170 self.id, | |
171 volume_type, | |
172 iops, | |
173 self.encrypted, | |
174 dry_run=dry_run | |
175 ) | |
176 | |
177 | |
178 class SnapshotAttribute(object): | |
179 def __init__(self, parent=None): | |
180 self.snapshot_id = None | |
181 self.attrs = {} | |
182 | |
183 def startElement(self, name, attrs, connection): | |
184 return None | |
185 | |
186 def endElement(self, name, value, connection): | |
187 if name == 'createVolumePermission': | |
188 self.name = 'create_volume_permission' | |
189 elif name == 'group': | |
190 if 'groups' in self.attrs: | |
191 self.attrs['groups'].append(value) | |
192 else: | |
193 self.attrs['groups'] = [value] | |
194 elif name == 'userId': | |
195 if 'user_ids' in self.attrs: | |
196 self.attrs['user_ids'].append(value) | |
197 else: | |
198 self.attrs['user_ids'] = [value] | |
199 elif name == 'snapshotId': | |
200 self.snapshot_id = value | |
201 else: | |
202 setattr(self, name, value) |