| OLD | NEW |
| (Empty) | |
| 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 class Snapshot(TaggedEC2Object): |
| 30 |
| 31 AttrName = 'createVolumePermission' |
| 32 |
| 33 def __init__(self, connection=None): |
| 34 TaggedEC2Object.__init__(self, connection) |
| 35 self.id = None |
| 36 self.volume_id = None |
| 37 self.status = None |
| 38 self.progress = None |
| 39 self.start_time = None |
| 40 self.owner_id = None |
| 41 self.owner_alias = None |
| 42 self.volume_size = None |
| 43 self.description = None |
| 44 |
| 45 def __repr__(self): |
| 46 return 'Snapshot:%s' % self.id |
| 47 |
| 48 def endElement(self, name, value, connection): |
| 49 if name == 'snapshotId': |
| 50 self.id = value |
| 51 elif name == 'volumeId': |
| 52 self.volume_id = value |
| 53 elif name == 'status': |
| 54 self.status = value |
| 55 elif name == 'startTime': |
| 56 self.start_time = value |
| 57 elif name == 'ownerId': |
| 58 self.owner_id = value |
| 59 elif name == 'ownerAlias': |
| 60 self.owner_alias = value |
| 61 elif name == 'volumeSize': |
| 62 try: |
| 63 self.volume_size = int(value) |
| 64 except: |
| 65 self.volume_size = value |
| 66 elif name == 'description': |
| 67 self.description = value |
| 68 else: |
| 69 setattr(self, name, value) |
| 70 |
| 71 def _update(self, updated): |
| 72 self.progress = updated.progress |
| 73 self.status = updated.status |
| 74 |
| 75 def update(self, validate=False): |
| 76 """ |
| 77 Update the data associated with this snapshot by querying EC2. |
| 78 |
| 79 :type validate: bool |
| 80 :param validate: By default, if EC2 returns no data about the |
| 81 snapshot the update method returns quietly. If |
| 82 the validate param is True, however, it will |
| 83 raise a ValueError exception if no data is |
| 84 returned from EC2. |
| 85 """ |
| 86 rs = self.connection.get_all_snapshots([self.id]) |
| 87 if len(rs) > 0: |
| 88 self._update(rs[0]) |
| 89 elif validate: |
| 90 raise ValueError('%s is not a valid Snapshot ID' % self.id) |
| 91 return self.progress |
| 92 |
| 93 def delete(self): |
| 94 return self.connection.delete_snapshot(self.id) |
| 95 |
| 96 def get_permissions(self): |
| 97 attrs = self.connection.get_snapshot_attribute(self.id, self.AttrName) |
| 98 return attrs.attrs |
| 99 |
| 100 def share(self, user_ids=None, groups=None): |
| 101 return self.connection.modify_snapshot_attribute(self.id, |
| 102 self.AttrName, |
| 103 'add', |
| 104 user_ids, |
| 105 groups) |
| 106 |
| 107 def unshare(self, user_ids=None, groups=None): |
| 108 return self.connection.modify_snapshot_attribute(self.id, |
| 109 self.AttrName, |
| 110 'remove', |
| 111 user_ids, |
| 112 groups) |
| 113 |
| 114 def reset_permissions(self): |
| 115 return self.connection.reset_snapshot_attribute(self.id, |
| 116 self.AttrName) |
| 117 |
| 118 def create_volume(self, zone, size=None, volume_type=None, iops=None): |
| 119 """ |
| 120 Create a new EBS Volume from this Snapshot |
| 121 |
| 122 :type zone: string or :class:`boto.ec2.zone.Zone` |
| 123 :param zone: The availability zone in which the Volume will be created. |
| 124 |
| 125 :type size: int |
| 126 :param size: The size of the new volume, in GiB. (optional). Defaults to |
| 127 the size of the snapshot. |
| 128 |
| 129 :type volume_type: string |
| 130 :param volume_type: The type of the volume. (optional). Valid |
| 131 values are: standard | io1. |
| 132 |
| 133 :type iops: int |
| 134 :param iops: The provisioned IOPs you want to associate with |
| 135 this volume. (optional) |
| 136 """ |
| 137 if isinstance(zone, Zone): |
| 138 zone = zone.name |
| 139 return self.connection.create_volume(size, zone, self.id, volume_type, i
ops) |
| 140 |
| 141 |
| 142 class SnapshotAttribute: |
| 143 |
| 144 def __init__(self, parent=None): |
| 145 self.snapshot_id = None |
| 146 self.attrs = {} |
| 147 |
| 148 def startElement(self, name, attrs, connection): |
| 149 return None |
| 150 |
| 151 def endElement(self, name, value, connection): |
| 152 if name == 'createVolumePermission': |
| 153 self.name = 'create_volume_permission' |
| 154 elif name == 'group': |
| 155 if 'groups' in self.attrs: |
| 156 self.attrs['groups'].append(value) |
| 157 else: |
| 158 self.attrs['groups'] = [value] |
| 159 elif name == 'userId': |
| 160 if 'user_ids' in self.attrs: |
| 161 self.attrs['user_ids'].append(value) |
| 162 else: |
| 163 self.attrs['user_ids'] = [value] |
| 164 elif name == 'snapshotId': |
| 165 self.snapshot_id = value |
| 166 else: |
| 167 setattr(self, name, value) |
| 168 |
| 169 |
| 170 |
| OLD | NEW |