Пример #1
0
 def get(self, request, provider_uuid, identity_uuid):
     """
     Using provider and identity, getlist of machines
     TODO: Cache this request
     """
     try:
         request_user = request.user
         logger.debug("filtered_machine_list")
         filtered_machine_list = provider_filtered_machines(request,
                                                            provider_uuid,
                                                            identity_uuid,
                                                            request_user)
     except ProviderNotActive as pna:
         return inactive_provider(pna)
     except LibcloudInvalidCredsError:
         return invalid_creds(provider_uuid, identity_uuid)
     except LibcloudBadResponseError:
         return malformed_response(provider_uuid, identity_uuid)
     except (socket_error, ConnectionFailure):
         return connection_failure(provider_uuid, identity_uuid)
     except ObjectDoesNotExist:
         return invalid_provider_identity(provider_uuid, identity_uuid)
     except Exception as e:
         logger.exception("Unexpected exception for user:%s"
                          % request_user)
         return failure_response(status.HTTP_409_CONFLICT,
                                 e.message)
     serialized_data = ProviderMachineSerializer(filtered_machine_list,
                                                 request_user=request.user,
                                                 many=True).data
     response = Response(serialized_data)
     return response
Пример #2
0
 def get(self, request, provider_uuid, identity_uuid):
     """
     Using provider and identity, getlist of machines
     TODO: Cache this request
     """
     try:
         request_user = request.user
         logger.debug("filtered_machine_list")
         filtered_machine_list = provider_filtered_machines(
             request, provider_uuid, identity_uuid, request_user
         )
     except ProviderNotActive as pna:
         return inactive_provider(pna)
     except LibcloudInvalidCredsError:
         return invalid_creds(provider_uuid, identity_uuid)
     except LibcloudBadResponseError:
         return malformed_response(provider_uuid, identity_uuid)
     except (socket_error, ConnectionFailure):
         return connection_failure(provider_uuid, identity_uuid)
     except ObjectDoesNotExist:
         return invalid_provider_identity(provider_uuid, identity_uuid)
     except Exception as e:
         logger.exception("Unexpected exception for user:%s" % request_user)
         return failure_response(status.HTTP_409_CONFLICT, e.message)
     serialized_data = ProviderMachineSerializer(
         filtered_machine_list, request_user=request.user, many=True
     ).data
     response = Response(serialized_data)
     return response
Пример #3
0
    def get(self, request, provider_uuid, identity_uuid):
        """
        Returns a list of all instances
        """
        user = request.user
        try:
            esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
        except ProviderNotActive as pna:
            return inactive_provider(pna)
        except Exception as e:
            return failure_response(
                status.HTTP_409_CONFLICT,
                e.message)
        if not esh_driver:
            return invalid_creds(provider_uuid, identity_uuid)
        identity = Identity.shared_with_user(user).get(uuid=identity_uuid)

        try:
            esh_instance_list = get_cached_instances(identity=identity)
        except LibcloudBadResponseError:
            return malformed_response(provider_uuid, identity_uuid)
        except (socket_error, ConnectionFailure):
            return connection_failure(provider_uuid, identity_uuid)
        except LibcloudInvalidCredsError:
            return invalid_creds(provider_uuid, identity_uuid)
        core_instance_list = [convert_esh_instance(esh_driver,
                                                   inst,
                                                   provider_uuid,
                                                   identity_uuid,
                                                   user)
                              for inst in esh_instance_list]
        # TODO: Core/Auth checks for shared instances
        serialized_data = InstanceSerializer(core_instance_list,
                                             context={"request": request},
                                             many=True).data
        response = Response(serialized_data)
        response['Cache-Control'] = 'no-cache'
        return response
Пример #4
0
    def get(self, request, provider_uuid, identity_uuid):
        """
        Returns a list of all instances
        """
        user = request.user
        try:
            esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
        except ProviderNotActive as pna:
            return inactive_provider(pna)
        except Exception as e:
            return failure_response(
                status.HTTP_409_CONFLICT,
                e.message)
        if not esh_driver:
            return invalid_creds(provider_uuid, identity_uuid)
        identity = Identity.shared_with_user(user).get(uuid=identity_uuid)

        try:
            esh_instance_list = get_cached_instances(identity=identity)
        except LibcloudBadResponseError:
            return malformed_response(provider_uuid, identity_uuid)
        except (socket_error, ConnectionFailure):
            return connection_failure(provider_uuid, identity_uuid)
        except LibcloudInvalidCredsError:
            return invalid_creds(provider_uuid, identity_uuid)
        core_instance_list = [convert_esh_instance(esh_driver,
                                                   inst,
                                                   provider_uuid,
                                                   identity_uuid,
                                                   user)
                              for inst in esh_instance_list]
        # TODO: Core/Auth checks for shared instances
        serialized_data = InstanceSerializer(core_instance_list,
                                             context={"request": request},
                                             many=True).data
        response = Response(serialized_data)
        response['Cache-Control'] = 'no-cache'
        return response