def _create_from_snapshot(self, context, volume_ref, snapshot_id, **kwargs): volume_id = volume_ref['id'] snapshot_ref = self.db.snapshot_get(context, snapshot_id) model_update = self.driver.create_volume_from_snapshot( volume_ref, snapshot_ref) # NOTE(harlowja): Subtasks would be useful here since after this # point the volume has already been created and further failures # will not destroy the volume (although they could in the future). make_bootable = False try: originating_vref = self.db.volume_get(context, snapshot_ref['volume_id']) make_bootable = originating_vref.bootable except exception.CinderException as ex: LOG.exception( _("Failed fetching snapshot %(snapshot_id)s bootable" " flag using the provided glance snapshot " "%(snapshot_ref_id)s volume reference") % { 'snapshot_id': snapshot_id, 'snapshot_ref_id': snapshot_ref['volume_id'] }) raise exception.MetadataUpdateFailure(reason=ex) if make_bootable: self._handle_bootable_volume_glance_meta(context, volume_id, snapshot_id=snapshot_id) return model_update
def _create_from_snapshot(self, context, volume, snapshot_id, **kwargs): snapshot = objects.Snapshot.get_by_id(context, snapshot_id) try: model_update = self.driver.create_volume_from_snapshot(volume, snapshot) finally: self._cleanup_cg_in_volume(volume) # NOTE(harlowja): Subtasks would be useful here since after this # point the volume has already been created and further failures # will not destroy the volume (although they could in the future). make_bootable = False try: originating_vref = objects.Volume.get_by_id(context, snapshot.volume_id) make_bootable = originating_vref.bootable except exception.CinderException as ex: LOG.exception("Failed fetching snapshot %(snapshot_id)s bootable" " flag using the provided glance snapshot " "%(snapshot_ref_id)s volume reference", {'snapshot_id': snapshot_id, 'snapshot_ref_id': snapshot.volume_id}) raise exception.MetadataUpdateFailure(reason=ex) if make_bootable: self._handle_bootable_volume_glance_meta(context, volume, snapshot_id=snapshot_id) return model_update
def _enable_bootable_flag(self, context, volume_id): try: LOG.debug('Marking volume %s as bootable.', volume_id) self.db.volume_update(context, volume_id, {'bootable': True}) except exception.CinderException as ex: LOG.exception(_LE("Failed updating volume %(volume_id)s bootable " "flag to true"), {'volume_id': volume_id}) raise exception.MetadataUpdateFailure(reason=ex)
def _enable_bootable_flag(self, context, volume): try: LOG.debug('Marking volume %s as bootable.', volume.id) volume.bootable = True volume.save() except exception.CinderException as ex: LOG.exception("Failed updating volume %(volume_id)s bootable " "flag to true", {'volume_id': volume.id}) raise exception.MetadataUpdateFailure(reason=ex)