Exemplo n.º 1
0
 def initialize_connection(self, volume, connector, initiator_data=None):
     try:
         ebs_vol = self._find(volume.id, self._conn.get_all_volumes)
     except NotFound:
         raise VolumeNotFound(volume_id=volume.id)
     conn_info = dict(data=dict(volume_id=ebs_vol.id))
     return conn_info
Exemplo n.º 2
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)
Exemplo n.º 3
0
 def initialize_connection(self, volume, connector, initiator_data=None):
     ec2_conn = self._ec2_client(volume.obj_context,
                                 project_id=volume.project_id)
     try:
         ebs_vol = self._find(volume.id, ec2_conn.describe_volumes)
     except NotFound:
         raise VolumeNotFound(volume_id=volume.id)
     conn_info = dict(data=dict(volume_id=ebs_vol['VolumeId']))
     return conn_info
Exemplo n.º 4
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')
Exemplo n.º 5
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']
            })
Exemplo n.º 6
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'])