Ejemplo n.º 1
0
 def post_instance_action(self, request, pk=None):
     user = request.user
     instance_id = pk
     instance = find_instance(instance_id)
     identity = instance.created_by_identity
     action_params = request.data
     action = action_params.pop('action')
     try:
         result_obj = run_instance_action(user, identity, instance_id, action, action_params)
         api_response = {
             'result': 'success',
             'message': 'The requested action <%s> was run successfully' % (action,),
             'object': result_obj,
         }
         response = Response(api_response, status=status.HTTP_200_OK)
         return response
     except (socket_error, ConnectionFailure):
         return connection_failure(identity)
     except InstanceDoesNotExist as dne:
         return failure_response(
             status.HTTP_404_NOT_FOUND,
             'Instance %s no longer exists' % (dne.message,))
     except InvalidCredsError:
         return invalid_creds(identity)
     except HypervisorCapacityError as hce:
         return over_capacity(hce)
     except ProviderNotActive as pna:
         return inactive_provider(pna)
     except (OverQuotaError, OverAllocationError) as oqe:
         return over_quota(oqe)
     except SizeNotAvailable as snae:
         return size_not_available(snae)
     except (socket_error, ConnectionFailure):
         return connection_failure(identity)
     except InvalidCredsError:
         return invalid_creds(identity)
     except VolumeMountConflict as vmc:
         return mount_failed(vmc)
     except NotImplemented:
         return failure_response(
             status.HTTP_409_CONFLICT,
             "The requested action %s is not available on this provider."
             % action_params['action'])
     except ActionNotAllowed:
         return failure_response(
             status.HTTP_409_CONFLICT,
             "The requested action %s has been explicitly "
             "disabled on this provider." % action_params['action'])
     except Exception as exc:
         logger.exception("Exception occurred processing InstanceAction")
         message = exc.message
         if message.startswith('409 Conflict'):
             return failure_response(
                 status.HTTP_409_CONFLICT,
                 message)
         return failure_response(
             status.HTTP_403_FORBIDDEN,
             "The requested action %s encountered "
             "an irrecoverable exception: %s"
             % (action_params['action'], message))
Ejemplo n.º 2
0
 def post_instance_action(self, request, pk=None):
     user = request.user
     instance_id = pk
     instance = find_instance(instance_id)
     identity = instance.created_by_identity
     action_params = dict(request.data)
     action = action_params.pop('action')
     if type(action) == list:
         action = action[0]
     try:
         result_obj = run_instance_action(user, identity, instance_id, action, action_params)
         api_response = {
             'result': 'success',
             'message': 'The requested action <%s> was run successfully' % (action,),
             'object': result_obj,
         }
         response = Response(api_response, status=status.HTTP_200_OK)
         return response
     except (socket_error, ConnectionFailure):
         return connection_failure(identity)
     except InstanceDoesNotExist as dne:
         return failure_response(
             status.HTTP_404_NOT_FOUND,
             'Instance %s no longer exists' % (dne.message,))
     except LibcloudInvalidCredsError:
         return invalid_creds(identity)
     except HypervisorCapacityError as hce:
         return over_capacity(hce)
     except ProviderNotActive as pna:
         return inactive_provider(pna)
     except (OverQuotaError, OverAllocationError) as oqe:
         return over_quota(oqe)
     except SizeNotAvailable as snae:
         return size_not_available(snae)
     except (socket_error, ConnectionFailure):
         return connection_failure(identity)
     except VolumeMountConflict as vmc:
         return mount_failed(vmc)
     except NotImplemented:
         return failure_response(
             status.HTTP_409_CONFLICT,
             "The requested action %s is not available on this provider."
             % action)
     except ActionNotAllowed:
         return failure_response(
             status.HTTP_409_CONFLICT,
             "The requested action %s has been explicitly "
             "disabled on this provider." % action)
     except Exception as exc:
         logger.exception("Exception occurred processing InstanceAction")
         message = exc.message
         if message.startswith('409 Conflict'):
             return failure_response(
                 status.HTTP_409_CONFLICT,
                 message)
         return failure_response(
             status.HTTP_403_FORBIDDEN,
             "The requested action %s encountered "
             "an irrecoverable exception: %s"
             % (action, message))
Ejemplo n.º 3
0
 def post(self, request, provider_uuid, identity_uuid, instance_id):
     """Authentication Required, Attempt a specific instance action,
     including necessary parameters.
     """
     # Service-specific call to action
     action_params = request.data
     if not action_params.get('action', None):
         return failure_response(
             status.HTTP_400_BAD_REQUEST,
             'POST request to /action require a BODY with \'action\'.')
     result_obj = None
     user = request.user
     identity = Identity.objects.get(uuid=identity_uuid)
     action = action_params['action']
     try:
         result_obj = run_instance_action(user, identity, instance_id,
                                          action, action_params)
         result_obj = _further_process_result(request, action, result_obj)
         api_response = {
             'result':
             'success',
             'message':
             'The requested action <%s> was run successfully' %
             (action_params['action'], ),
             'object':
             result_obj,
         }
         response = Response(api_response, status=status.HTTP_200_OK)
         return response
     except (socket_error, ConnectionFailure):
         return connection_failure(provider_uuid, identity_uuid)
     except ProviderNotActive as pna:
         return inactive_provider(pna)
     except InstanceDoesNotExist as dne:
         return failure_response(
             status.HTTP_404_NOT_FOUND,
             'Instance %s no longer exists' % (dne.message, ))
     except LibcloudInvalidCredsError:
         return invalid_creds(provider_uuid, identity_uuid)
     except HypervisorCapacityError as hce:
         return over_capacity(hce)
     except OverQuotaError as oqe:
         return over_quota(oqe)
     except OverAllocationError as oae:
         return over_quota(oae)
     except SizeNotAvailable as snae:
         return size_not_available(snae)
     except (socket_error, ConnectionFailure):
         return connection_failure(provider_uuid, identity_uuid)
     except LibcloudInvalidCredsError:
         return invalid_creds(provider_uuid, identity_uuid)
     except VolumeMountConflict as vmc:
         return mount_failed(vmc)
     except NotImplemented:
         return failure_response(
             status.HTTP_409_CONFLICT,
             "The requested action %s is not available on this provider." %
             action_params['action'])
     except ActionNotAllowed:
         return failure_response(
             status.HTTP_409_CONFLICT,
             "The requested action %s has been explicitly "
             "disabled on this provider." % action_params['action'])
     except Exception as exc:
         logger.exception("Exception occurred processing InstanceAction")
         message = exc.message
         if message.startswith('409 Conflict'):
             return failure_response(status.HTTP_409_CONFLICT, message)
         return failure_response(
             status.HTTP_403_FORBIDDEN,
             "The requested action %s encountered "
             "an irrecoverable exception: %s" %
             (action_params['action'], message))
Ejemplo n.º 4
0
 def post(self, request, provider_uuid, identity_uuid, instance_id):
     """Authentication Required, Attempt a specific instance action,
     including necessary parameters.
     """
     # Service-specific call to action
     action_params = request.data
     if not action_params.get('action', None):
         return failure_response(
             status.HTTP_400_BAD_REQUEST,
             'POST request to /action require a BODY with \'action\'.')
     result_obj = None
     user = request.user
     identity = Identity.objects.get(uuid=identity_uuid)
     action = action_params['action']
     try:
         result_obj = run_instance_action(user, identity, instance_id, action, action_params)
         result_obj = _further_process_result(request, action, result_obj)
         api_response = {
             'result': 'success',
             'message': 'The requested action <%s> was run successfully' % (action_params['action'],),
             'object': result_obj,
         }
         response = Response(api_response, status=status.HTTP_200_OK)
         return response
     except (socket_error, ConnectionFailure):
         return connection_failure(provider_uuid, identity_uuid)
     except ProviderNotActive as pna:
         return inactive_provider(pna)
     except InstanceDoesNotExist as dne:
         return failure_response(
             status.HTTP_404_NOT_FOUND,
             'Instance %s no longer exists' % (dne.message,))
     except InvalidCredsError:
         return invalid_creds(provider_uuid, identity_uuid)
     except HypervisorCapacityError as hce:
         return over_capacity(hce)
     except OverQuotaError as oqe:
         return over_quota(oqe)
     except OverAllocationError as oae:
         return over_quota(oae)
     except SizeNotAvailable as snae:
         return size_not_available(snae)
     except (socket_error, ConnectionFailure):
         return connection_failure(provider_uuid, identity_uuid)
     except InvalidCredsError:
         return invalid_creds(provider_uuid, identity_uuid)
     except VolumeMountConflict as vmc:
         return mount_failed(vmc)
     except NotImplemented:
         return failure_response(
             status.HTTP_409_CONFLICT,
             "The requested action %s is not available on this provider."
             % action_params['action'])
     except ActionNotAllowed:
         return failure_response(
             status.HTTP_409_CONFLICT,
             "The requested action %s has been explicitly "
             "disabled on this provider." % action_params['action'])
     except Exception as exc:
         logger.exception("Exception occurred processing InstanceAction")
         message = exc.message
         if message.startswith('409 Conflict'):
             return failure_response(
                 status.HTTP_409_CONFLICT,
                 message)
         return failure_response(
             status.HTTP_403_FORBIDDEN,
             "The requested action %s encountered "
             "an irrecoverable exception: %s"
             % (action_params['action'], message))