def delete(self, request, provider_id, identity_id, instance_id): """Authentication Required, TERMINATE the instance. Be careful, there is no going back once you've deleted an instance. """ user = request.user esh_driver = prepare_driver(request, provider_id, identity_id) if not esh_driver: return invalid_creds(provider_id, identity_id) try: esh_instance = esh_driver.get_instance(instance_id) if not esh_instance: return instance_not_found(instance_id) task.destroy_instance_task(esh_instance, identity_id) existing_instance = esh_driver.get_instance(instance_id) if existing_instance: #Instance will be deleted soon... esh_instance = existing_instance if esh_instance.extra\ and 'task' not in esh_instance.extra: esh_instance.extra['task'] = 'queueing delete' core_instance = convert_esh_instance(esh_driver, esh_instance, provider_id, identity_id, user) if core_instance: core_instance.end_date_all() else: logger.warn("Unable to find core instance %s." % (instance_id)) serialized_data = InstanceSerializer(core_instance, context={"request":request}).data response = Response(serialized_data, status=status.HTTP_200_OK) response['Cache-Control'] = 'no-cache' return response except InvalidCredsError: return invalid_creds(provider_id, identity_id)
def delete(self, request, provider_id, identity_id, instance_id): """Authentication Required, TERMINATE the instance. Be careful, there is no going back once you've deleted an instance. """ user = request.user esh_driver = prepare_driver(request, provider_id, identity_id) if not esh_driver: return invalid_creds(provider_id, identity_id) try: esh_instance = esh_driver.get_instance(instance_id) if not esh_instance: return instance_not_found(instance_id) task.destroy_instance_task(esh_instance, identity_id) existing_instance = esh_driver.get_instance(instance_id) if existing_instance: #Instance will be deleted soon... esh_instance = existing_instance if esh_instance.extra\ and 'task' not in esh_instance.extra: esh_instance.extra['task'] = 'queueing delete' core_instance = convert_esh_instance(esh_driver, esh_instance, provider_id, identity_id, user) if core_instance: core_instance.end_date_all() serialized_data = InstanceSerializer(core_instance, context={ 'user': request.user }).data response = Response(serialized_data, status=status.HTTP_200_OK) response['Cache-Control'] = 'no-cache' return response except InvalidCredsError: return invalid_creds(provider_id, identity_id)
def delete(self, request, provider_id, identity_id, instance_id): user = request.user esh_driver = prepare_driver(request, identity_id) try: esh_instance = esh_driver.get_instance(instance_id) if not esh_instance: return instance_not_found(instance_id) task.destroy_instance_task(esh_instance, identity_id) existing_instance = esh_driver.get_instance(instance_id) if existing_instance: #Instance will be deleted soon... esh_instance = existing_instance if esh_instance.extra\ and 'task' not in esh_instance.extra: esh_instance.extra['task'] = 'queueing delete' core_instance = convert_esh_instance(esh_driver, esh_instance, provider_id, identity_id, user) if core_instance: core_instance.end_date_all() serialized_data = InstanceSerializer(core_instance).data response = Response(serialized_data, status=status.HTTP_200_OK) response['Cache-Control'] = 'no-cache' return response except InvalidCredsError: return invalid_creds(provider_id, identity_id)
def delete(self, request, provider_id, identity_id, instance_id): user = request.user esh_driver = prepare_driver(request, provider_id, identity_id) if not esh_driver: return invalid_creds(provider_id, identity_id) try: esh_instance = esh_driver.get_instance(instance_id) if not esh_instance: return instance_not_found(instance_id) task.destroy_instance_task(esh_instance, identity_id) existing_instance = esh_driver.get_instance(instance_id) if existing_instance: #Instance will be deleted soon... esh_instance = existing_instance if esh_instance.extra\ and 'task' not in esh_instance.extra: esh_instance.extra['task'] = 'queueing delete' core_instance = convert_esh_instance(esh_driver, esh_instance, provider_id, identity_id, user) if core_instance: core_instance.end_date_all() serialized_data = InstanceSerializer(core_instance).data response = Response(serialized_data, status=status.HTTP_200_OK) response['Cache-Control'] = 'no-cache' return response except InvalidCredsError: return invalid_creds(provider_id, identity_id)
def delete(self, request, provider_uuid, identity_uuid, instance_id): """Authentication Required, TERMINATE the instance. Be careful, there is no going back once you've deleted an instance. """ user = request.user esh_driver = prepare_driver(request, provider_uuid, identity_uuid) if not esh_driver: return invalid_creds(provider_uuid, identity_uuid) try: esh_instance = esh_driver.get_instance(instance_id) except (socket_error, ConnectionFailure): return connection_failure(provider_uuid, identity_uuid) except InvalidCredsError: return invalid_creds(provider_uuid, identity_uuid) except Exception as exc: logger.exception("Encountered a generic exception. " "Returning 409-CONFLICT") return failure_response(status.HTTP_409_CONFLICT, str(exc.message)) try: # Test that there is not an attached volume BEFORE we destroy task.destroy_instance_task(user, esh_instance, identity_uuid) invalidate_cached_instances(identity=Identity.objects.get(uuid=identity_uuid)) existing_instance = esh_driver.get_instance(instance_id) if existing_instance: # Instance will be deleted soon... esh_instance = existing_instance if esh_instance.extra and "task" not in esh_instance.extra: esh_instance.extra["task"] = "queueing delete" 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 InvalidCredsError: return invalid_creds(provider_uuid, identity_uuid) except Exception as exc: logger.exception("Encountered a generic exception. " "Returning 409-CONFLICT") return failure_response(status.HTTP_409_CONFLICT, str(exc.message)) try: core_instance = convert_esh_instance(esh_driver, esh_instance, provider_uuid, identity_uuid, user) if core_instance: core_instance.end_date_all() else: logger.warn("Unable to find core instance %s." % (instance_id)) serialized_data = InstanceSerializer(core_instance, context={"request": request}).data response = Response(serialized_data, status=status.HTTP_200_OK) response["Cache-Control"] = "no-cache" return response except (Identity.DoesNotExist) as exc: return failure_response(status.HTTP_400_BAD_REQUEST, "Invalid provider_uuid or identity_uuid.") except (socket_error, ConnectionFailure): return connection_failure(provider_uuid, identity_uuid) except InvalidCredsError: return invalid_creds(provider_uuid, identity_uuid)
def delete(self, request, provider_uuid, identity_uuid, instance_id): """Authentication Required, TERMINATE the instance. Be careful, there is no going back once you've deleted an instance. """ user = request.user esh_driver = prepare_driver(request, provider_uuid, identity_uuid) if not esh_driver: return invalid_creds(provider_uuid, identity_uuid) try: esh_instance = esh_driver.get_instance(instance_id) if not esh_instance: return instance_not_found(instance_id) #Test that there is not an attached volume BEFORE we destroy _check_volume_attachment(esh_driver, esh_instance) task.destroy_instance_task(esh_instance, identity_uuid) invalidate_cached_instances(identity=Identity.objects.get(uuid=identity_uuid)) existing_instance = esh_driver.get_instance(instance_id) if existing_instance: #Instance will be deleted soon... esh_instance = existing_instance if esh_instance.extra\ and 'task' not in esh_instance.extra: esh_instance.extra['task'] = 'queueing delete' core_instance = convert_esh_instance(esh_driver, esh_instance, provider_uuid, identity_uuid, user) if core_instance: core_instance.end_date_all() else: logger.warn("Unable to find core instance %s." % (instance_id)) serialized_data = InstanceSerializer(core_instance, context={"request":request}).data response = Response(serialized_data, status=status.HTTP_200_OK) response['Cache-Control'] = 'no-cache' return response except (Identity.DoesNotExist) as exc: return failure_response(status.HTTP_400_BAD_REQUEST, "Invalid provider_uuid or identity_uuid.") except VolumeAttachConflict as exc: message = exc.message return failure_response(status.HTTP_409_CONFLICT, message) except ConnectionFailure: return connection_failure(provider_uuid, identity_uuid) except InvalidCredsError: return invalid_creds(provider_uuid, identity_uuid)
def delete(self, request, provider_uuid, identity_uuid, instance_id): """Authentication Required, TERMINATE the instance. Be careful, there is no going back once you've deleted an instance. """ user = request.user esh_driver = prepare_driver(request, provider_uuid, identity_uuid) if not esh_driver: return invalid_creds(provider_uuid, identity_uuid) if not can_use_instance(user, instance_id, leader_required=True): return member_action_forbidden(user.username, instance_id) try: esh_instance = esh_driver.get_instance(instance_id) except (socket_error, ConnectionFailure): return connection_failure(provider_uuid, identity_uuid) except LibcloudInvalidCredsError: return invalid_creds(provider_uuid, identity_uuid) except Exception as exc: logger.exception("Encountered a generic exception. " "Returning 409-CONFLICT") return failure_response(status.HTTP_409_CONFLICT, str(exc.message)) try: # Test that there is not an attached volume BEFORE we destroy task.destroy_instance_task(user, esh_instance, identity_uuid) invalidate_cached_instances( identity=Identity.objects.get(uuid=identity_uuid)) existing_instance = esh_driver.get_instance(instance_id) 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 does not exist" % instance_id) except Exception as exc: logger.exception("Encountered a generic exception. " "Returning 409-CONFLICT") return failure_response(status.HTTP_409_CONFLICT, str(exc.message)) try: core_instance = None if existing_instance: # Instance will be deleted soon... esh_instance = existing_instance if esh_instance.extra\ and 'task' not in esh_instance.extra: esh_instance.extra['task'] = 'queueing delete' core_instance = convert_esh_instance(esh_driver, esh_instance, provider_uuid, identity_uuid, user) if not core_instance: logger.warn("Unable to find core instance %s." % (instance_id)) core_instance = CoreInstance.objects.filter( provider_alias=instance_id).first() serialized_data = InstanceSerializer( core_instance, context={"request": request}).data response = Response(serialized_data, status=status.HTTP_200_OK) response['Cache-Control'] = 'no-cache' return response except (Identity.DoesNotExist) as exc: return failure_response(status.HTTP_400_BAD_REQUEST, "Invalid provider_uuid or identity_uuid.") except (socket_error, ConnectionFailure): return connection_failure(provider_uuid, identity_uuid) except LibcloudInvalidCredsError: return invalid_creds(provider_uuid, identity_uuid)
def delete(self, request, provider_uuid, identity_uuid, instance_id): """Authentication Required, TERMINATE the instance. Be careful, there is no going back once you've deleted an instance. """ user = request.user esh_driver = prepare_driver(request, provider_uuid, identity_uuid) if not esh_driver: return invalid_creds(provider_uuid, identity_uuid) if not can_use_instance(user, instance_id, leader_required=True): return member_action_forbidden(user.username, instance_id) try: esh_instance = esh_driver.get_instance(instance_id) except (socket_error, ConnectionFailure): return connection_failure(provider_uuid, identity_uuid) except LibcloudInvalidCredsError: return invalid_creds(provider_uuid, identity_uuid) except Exception as exc: logger.exception("Encountered a generic exception. " "Returning 409-CONFLICT") return failure_response(status.HTTP_409_CONFLICT, str(exc.message)) try: # Test that there is not an attached volume BEFORE we destroy task.destroy_instance_task(user, esh_instance, identity_uuid) invalidate_cached_instances(identity=Identity.objects.get( uuid=identity_uuid)) existing_instance = esh_driver.get_instance(instance_id) 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)) try: if existing_instance: # Instance will be deleted soon... esh_instance = existing_instance if esh_instance.extra\ and 'task' not in esh_instance.extra: esh_instance.extra['task'] = 'queueing delete' core_instance = convert_esh_instance(esh_driver, esh_instance, provider_uuid, identity_uuid, user) if not core_instance: logger.warn("Unable to find core instance %s." % (instance_id)) core_instance = CoreInstance.objects.filter( provider_alias=instance_id).first() serialized_data = InstanceSerializer(core_instance, context={ "request": request }).data response = Response(serialized_data, status=status.HTTP_200_OK) response['Cache-Control'] = 'no-cache' return response except (Identity.DoesNotExist) as exc: return failure_response(status.HTTP_400_BAD_REQUEST, "Invalid provider_uuid or identity_uuid.") except (socket_error, ConnectionFailure): return connection_failure(provider_uuid, identity_uuid) except LibcloudInvalidCredsError: return invalid_creds(provider_uuid, identity_uuid)