def destroy(self, request, pk=None): user = self.request.user try: instance = Instance.objects.get( Q(id=pk) if isinstance(pk, int) else Q(provider_alias=pk) ) identity_uuid = str(instance.created_by_identity.uuid) identity = Identity.objects.get(uuid=identity_uuid) provider_uuid = str(identity.provider.uuid) destroy_instance.delay(instance.provider_alias, user, identity_uuid) # We must invalidate the cache while we still depend on api.v1.instance invalidate_cached_instances(identity=identity) serializer = InstanceSerializer( instance, context={'request': self.request}, data={}, partial=True ) if not serializer.is_valid(): return Response( "Errors encountered during delete: %s" % serializer.errors, status=status.HTTP_400_BAD_REQUEST ) return Response(status=status.HTTP_204_NO_CONTENT) except VolumeAttachConflict as exc: message = exc.message return failure_response(status.HTTP_409_CONFLICT, message) except (socket_error, ConnectionFailure): return connection_failure(provider_uuid, identity_uuid) except LibcloudInvalidCredsError: return invalid_creds(provider_uuid, identity_uuid) except InstanceDoesNotExist as dne: return failure_response( status.HTTP_404_NOT_FOUND, 'Instance %s no longer exists' % (dne.message, ) ) except Exception as exc: logger.exception( "Encountered a generic exception. " "Returning 409-CONFLICT" ) return failure_response(status.HTTP_409_CONFLICT, str(exc.message))
def destroy_instance_task(user, instance, identity_uuid, *args, **kwargs): if not instance: raise InstanceDoesNotExist(instance_id=identity_uuid) return destroy_instance.delay( instance.alias, user, identity_uuid, *args, **kwargs)
def destroy_instance_task(instance, identity_uuid, *args, **kwargs): return destroy_instance.delay( instance.alias, identity_uuid, *args, **kwargs)
def destroy_instance_task(instance, identity_id, *args, **kwargs): destroy_instance.delay(instance.alias, identity_id, *args, **kwargs)
def destroy_instance_task(user, instance, identity_uuid, *args, **kwargs): if not instance: raise InstanceDoesNotExist() return destroy_instance.delay( instance.alias, user, identity_uuid, *args, **kwargs )
def destroy_instance_task(instance, identity_id, *args, **kwargs): destroy_instance.delay(identity_id, instance.alias, *args, **kwargs)