Exemple #1
0
    def create_cloned_volume(self, volume, srcvol_ref):
        ebs_snap = None
        ebs_vol = None
        try:
            src_vol = self._find(srcvol_ref['id'], self._conn.get_all_volumes)
            ebs_snap = self._conn.create_snapshot(src_vol.id)

            if self._wait_for_snapshot(ebs_snap.id, 'completed') is False:
                raise APITimeout(service='EC2')

            ebs_vol = self._conn.create_volume(size=volume.size,
                                               zone=self._zone,
                                               snapshot=ebs_snap.id)
            if self._wait_for_create(ebs_vol.id, 'available') is False:
                raise APITimeout(service='EC2')
            if self._wait_for_tags_creation(ebs_vol.id, volume) is False:
                raise APITimeout(service='EC2')
        except NotFound:
            raise VolumeNotFound(srcvol_ref['id'])
        except Exception as ex:
            message = "create_cloned_volume failed! volume: {0}, reason: {1}"
            LOG.error(message.format(volume.id, ex))
            if ebs_vol:
                self._conn.delete_volume(ebs_vol.id)
            raise VolumeBackendAPIException(data=message.format(volume.id, ex))
        finally:
            if ebs_snap:
                self._conn.delete_snapshot(ebs_snap.id)
Exemple #2
0
 def create_volume(self, volume):
     size = volume['size']
     ec2_conn = self._ec2_client(volume.obj_context,
                                 project_id=volume.project_id)
     ebs_vol = ec2_conn.create_volume(Size=size, AvailabilityZone=self.az)
     vol_id = ebs_vol['VolumeId']
     if not self._wait_for_create(ec2_conn, vol_id, 'available'):
         raise APITimeout(service='EC2')
     if not self._wait_for_tags_creation(ec2_conn, vol_id, volume):
         raise APITimeout(service='EC2')
Exemple #3
0
 def clone_image(self, context, volume, image_location, image_meta,
                 image_service):
     image_id = image_meta['properties']['aws_image_id']
     snapshot_id = self._get_snapshot_id(image_id)
     ebs_vol = self._conn.create_volume(size=volume.size,
                                        zone=self._zone,
                                        snapshot=snapshot_id)
     if self._wait_for_create(ebs_vol.id, 'available') is False:
         raise APITimeout(service='EC2')
     if self._wait_for_tags_creation(ebs_vol.id, volume) is False:
         raise APITimeout(service='EC2')
     metadata = volume['metadata']
     metadata['new_volume_id'] = ebs_vol.id
     return dict(metadata=metadata), True
Exemple #4
0
 def clone_image(self, context, volume, image_location, image_meta,
                 image_service):
     ec2_conn = self._ec2_client(context, project_id=volume.project_id)
     image_id = image_meta['properties']['aws_image_id']
     snapshot_id = self._get_snapshot_id(ec2_conn, image_id)
     ebs_vol = ec2_conn.create_volume(Size=volume.size,
                                      AvailabilityZone=self.az,
                                      SnapshotId=snapshot_id)
     vol_id = ebs_vol['VolumeId']
     if not self._wait_for_create(ec2_conn, vol_id, 'available'):
         raise APITimeout(service='EC2')
     if not self._wait_for_tags_creation(ec2_conn, vol_id, volume, True):
         raise APITimeout(service='EC2')
     metadata = volume['metadata']
     metadata['new_volume_id'] = vol_id
     return dict(metadata=metadata), True
Exemple #5
0
    def create_snapshot(self, snapshot):
        vol_id = snapshot['volume_id']
        ec2_conn = self._ec2_client(snapshot.obj_context,
                                    project_id=snapshot.project_id)
        try:
            ebs_vol = self._find(vol_id, ec2_conn.describe_volumes)
        except NotFound:
            raise VolumeNotFound(volume_id=vol_id)

        ebs_snap = ec2_conn.create_snapshot(VolumeId=ebs_vol['VolumeId'])
        if not self._wait_for_create(
                ec2_conn, ebs_snap['SnapshotId'], 'completed',
                is_snapshot=True):
            raise APITimeout(service='EC2')
        if not self._wait_for_tags_creation(ec2_conn, ebs_snap['SnapshotId'],
                                            snapshot, True, True):
            raise APITimeout(service='EC2')
Exemple #6
0
    def create_volume_from_snapshot(self, volume, snapshot):
        ec2_conn = self._ec2_client(volume.obj_context,
                                    project_id=volume.project_id)
        try:
            ebs_ss = self._find(snapshot['id'],
                                ec2_conn.describe_snapshots,
                                is_snapshot=True)
        except NotFound:
            LOG.error('Snapshot %s was not found' % snapshot['id'])
            raise
        ebs_vol = ec2_conn.create_volume(AvailabilityZone=self.az,
                                         SnapshotId=ebs_ss['SnapshotId'])
        vol_id = ebs_vol['VolumeId']

        if not self._wait_for_create(ec2_conn, vol_id, 'available'):
            raise APITimeout(service='EC2')
        if not self._wait_for_tags_creation(ec2_conn, vol_id, volume):
            raise APITimeout(service='EC2')
Exemple #7
0
 def create_volume(self, volume):
     size = volume['size']
     ebs_vol = self._conn.create_volume(size, self._zone)
     if self._wait_for_create(ebs_vol.id, 'available') is False:
         raise APITimeout(service='EC2')
     self._conn.create_tags(
         [ebs_vol.id], {
             'project_id': volume['project_id'],
             'uuid': volume['id'],
             'is_clone': False,
             'created_at': volume['created_at']
         })
Exemple #8
0
    def create_cloned_volume(self, volume, srcvol_ref):
        ebs_snap = None
        ebs_vol = None
        ec2_conn = self._ec2_client(volume.obj_context,
                                    project_id=volume.project_id)
        try:
            src_vol = self._find(srcvol_ref['id'], ec2_conn.describe_volumes)
            ebs_snap = ec2_conn.create_snapshot(VolumeId=src_vol['VolumeId'])

            if not self._wait_for_create(ec2_conn,
                                         ebs_snap['SnapshotId'],
                                         'completed',
                                         is_snapshot=True):
                raise APITimeout(service='EC2')

            ebs_vol = ec2_conn.create_volume(Size=volume.size,
                                             AvailabilityZone=self.az,
                                             SnapshotId=ebs_snap['SnapshotId'])
            vol_id = ebs_vol['VolumeId']

            if not self._wait_for_create(ec2_conn, vol_id, 'available'):
                raise APITimeout(service='EC2')
            if not self._wait_for_tags_creation(ec2_conn, vol_id, volume,
                                                True):
                raise APITimeout(service='EC2')
        except NotFound:
            raise VolumeNotFound(srcvol_ref['id'])
        except Exception as ex:
            message = "create_cloned_volume failed! volume: {0}, reason: {1}"
            LOG.error(message.format(volume.id, ex))
            if ebs_vol:
                ec2_conn.delete_volume(VolumeId=ebs_vol['VolumeId'])
            raise VolumeBackendAPIException(data=message.format(volume.id, ex))
        finally:
            if ebs_snap:
                ec2_conn.delete_snapshot(SnapshotId=ebs_snap['SnapshotId'])
Exemple #9
0
    def create_volume_from_snapshot(self, volume, snapshot):
        try:
            ebs_ss = self._find(snapshot['id'], self._conn.get_all_snapshots)
        except NotFound:
            LOG.error(_LE('Snapshot %s was not found'), snapshot['id'])
            raise
        ebs_vol = ebs_ss.create_volume(self._zone)

        if self._wait_for_create(ebs_vol.id, 'available') is False:
            raise APITimeout(service='EC2')
        self._conn.create_tags(
            [ebs_vol.id], {
                'project_id': volume['project_id'],
                'uuid': volume['id'],
                'is_clone': False,
                'created_at': volume['created_at'],
                'Name': volume['display_name']
            })
Exemple #10
0
    def create_snapshot(self, snapshot):
        os_vol = snapshot['volume']
        try:
            ebs_vol = self._find(os_vol['id'], self._conn.get_all_volumes)
        except NotFound:
            raise VolumeNotFound(os_vol['id'])

        ebs_snap = self._conn.create_snapshot(ebs_vol.id)
        if self._wait_for_snapshot(ebs_snap.id, 'completed') is False:
            raise APITimeout(service='EC2')

        self._conn.create_tags(
            [ebs_snap.id], {
                'project_id': snapshot['project_id'],
                'uuid': snapshot['id'],
                'is_clone': True,
                'created_at': snapshot['created_at']
            })