예제 #1
0
    def get(self, request, provider_id, identity_id):
        """
        Returns a list of all instances
        """
        user = request.user
        esh_driver = prepare_driver(request, provider_id, identity_id)
        if not esh_driver:
            return invalid_creds(provider_id, identity_id)

        instance_list_method = esh_driver.list_instances

        if AccountProvider.objects.filter(identity__id=identity_id):
            # Instance list method changes when using the OPENSTACK provider
            instance_list_method = esh_driver.list_all_instances
        try:
            esh_instance_list = instance_list_method()
        except InvalidCredsError:
            return invalid_creds(provider_id, identity_id)

        core_instance_list = [
            convert_esh_instance(esh_driver, inst, provider_id, identity_id,
                                 user) for inst in esh_instance_list
        ]

        #TODO: Core/Auth checks for shared instances

        serialized_data = InstanceSerializer(core_instance_list,
                                             context={
                                                 'user': request.user
                                             },
                                             many=True).data
        response = Response(serialized_data)
        response['Cache-Control'] = 'no-cache'
        return response
예제 #2
0
    def put(self, request, provider_id, identity_id, machine_id):
        """
        TODO: Determine who is allowed to edit machines besides
            core_machine.owner
        """
        user = request.user
        data = request.DATA
        esh_driver = prepare_driver(request, provider_id, identity_id)
        if not esh_driver:
            return invalid_creds(provider_id, identity_id)
        esh_machine = esh_driver.get_machine(machine_id)
        core_machine = convert_esh_machine(esh_driver, esh_machine,
                                           provider_id)

        if not user.is_staff\
           and user is not core_machine.application.created_by:
            logger.error('Non-staff/non-owner trying to update a machine')
            return failure_response(
                status.HTTP_401_UNAUTHORIZED,
                'Only Staff and the machine Owner ' +
                'are allowed to change machine info.')
        core_machine.application.update(data)
        serializer = ProviderMachineSerializer(core_machine,
                                               data=data,
                                               partial=True)
        if serializer.is_valid():
            logger.info('metadata = %s' % data)
            update_machine_metadata(esh_driver, esh_machine, data)
            serializer.save()
            logger.info(serializer.data)
            return Response(serializer.data)
        return failure_response(status.HTTP_400_BAD_REQUEST, serializer.errors)
예제 #3
0
 def put(self, request, provider_id, identity_id, instance_id):
     """Authentication Required, update metadata about the instance"""
     user = request.user
     data = request.DATA
     #Ensure item exists on the server first
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_instance = esh_driver.get_instance(instance_id)
     if not esh_instance:
         return instance_not_found(instance_id)
     #Gather the DB related item and update
     core_instance = convert_esh_instance(esh_driver, esh_instance,
                                          provider_id, identity_id, user)
     serializer = InstanceSerializer(core_instance,
                                     data=data,
                                     context={"request": request})
     if serializer.is_valid():
         logger.info('metadata = %s' % data)
         update_instance_metadata(esh_driver, esh_instance, data)
         serializer.save()
         response = Response(serializer.data)
         logger.info('data = %s' % serializer.data)
         response['Cache-Control'] = 'no-cache'
         return response
     else:
         return Response(serializer.errors, status=status.HTTP_400)
예제 #4
0
파일: meta.py 프로젝트: nickeddy/atmosphere
 def get(self, request, provider_id=None, identity_id=None, action=None):
     """
     """
     if not action:
         errorObj = failureJSON([{
             'code': 400,
             'message': 'Action is not supported.'}])
         return Response(errorObj, status=status.HTTP_400_BAD_REQUEST)
     esh_driver = prepare_driver(request, identity_id)
     esh_meta = esh_driver.meta()
     try:
         if 'test_links' in action:
             test_links = esh_meta.test_links()
             return Response(test_links, status=status.HTTP_200_OK)
     except InvalidCredsError:
         logger.warn('Authentication Failed. Provider-id:%s Identity-id:%s'
                     % (provider_id, identity_id))
         errorObj = failureJSON([{
             'code': 401,
             'message': 'Identity/Provider Authentication Failed'}])
         return Response(errorObj, status=status.HTTP_401_UNAUTHORIZED)
     except NotImplemented, ne:
         logger.exception(ne)
         errorObj = failureJSON([{
             'code': 404,
             'message':
             'The requested resource %s is not available on this provider'
             % action}])
         return Response(errorObj, status=status.HTTP_404_NOT_FOUND)
예제 #5
0
    def put(self, request, provider_id, identity_id, machine_id):
        """
        TODO: Determine who is allowed to edit machines besides
            core_machine.owner
        """
        user = request.user
        data = request.DATA
        esh_driver = prepare_driver(request, provider_id, identity_id)
        if not esh_driver:
            return invalid_creds(provider_id, identity_id)
        esh_machine = esh_driver.get_machine(machine_id)
        core_machine = convert_esh_machine(esh_driver, esh_machine, provider_id)

        if not user.is_staff\
           and user is not core_machine.application.created_by:
            logger.error('Non-staff/non-owner trying to update a machine')
            return failure_response(
                status.HTTP_401_UNAUTHORIZED,
                'Only Staff and the machine Owner '
                + 'are allowed to change machine info.')
        core_machine.application.update(data)
        serializer = ProviderMachineSerializer(core_machine,
                                               data=data, partial=True)
        if serializer.is_valid():
            logger.info('metadata = %s' % data)
            update_machine_metadata(esh_driver, esh_machine, data)
            serializer.save()
            logger.info(serializer.data)
            return Response(serializer.data)
        return failure_response(
            status.HTTP_400_BAD_REQUEST,
            serializer.errors)
예제 #6
0
    def put(self, request, provider_id, identity_id, instance_id):
        """
        TODO:
            Options for put
            - Instance status change (suspend,resume,etc.)
            - DB changes (Name, tags)
        """
        user = request.user
        data = request.DATA
        #Ensure item exists on the server first
        esh_driver = prepare_driver(request, identity_id)
        try:
            esh_instance = esh_driver.get_instance(instance_id)
        except InvalidCredsError:
            return invalid_creds(provider_id, identity_id)

        if not esh_instance:
            return instance_not_found(instance_id)

        #Gather the DB related item and update
        core_instance = convert_esh_instance(esh_driver, esh_instance,
                                           provider_id, identity_id, user)
        serializer = InstanceSerializer(core_instance, data=data)
        if serializer.is_valid():
            logger.info('metadata = %s' % data)
            update_instance_metadata(esh_driver, esh_instance, data)
            serializer.save()
            response = Response(serializer.data)
            logger.info('data = %s' % serializer.data)
            response['Cache-Control'] = 'no-cache'
            return response
        else:
            return Response(serializer.errors, status=status.HTTP_400)
예제 #7
0
 def put(self, request, provider_id, identity_id, instance_id):
     """
     TODO:
         Options for put
         - Instance status change (suspend,resume,etc.)
         - DB changes (Name, tags)
     """
     user = request.user
     data = request.DATA
     #Ensure item exists on the server first
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_instance = esh_driver.get_instance(instance_id)
     if not esh_instance:
         return instance_not_found(instance_id)
     #Gather the DB related item and update
     core_instance = convert_esh_instance(esh_driver, esh_instance,
                                          provider_id, identity_id, user)
     serializer = InstanceSerializer(core_instance, data=data)
     if serializer.is_valid():
         logger.info('metadata = %s' % data)
         update_instance_metadata(esh_driver, esh_instance, data)
         serializer.save()
         response = Response(serializer.data)
         logger.info('data = %s' % serializer.data)
         response['Cache-Control'] = 'no-cache'
         return response
     else:
         return Response(serializer.errors, status=status.HTTP_400)
예제 #8
0
 def delete(self, request, provider_id, identity_id, volume_id):
     """
     Destroys the volume and updates the DB
     """
     user = request.user
     #Ensure volume exists
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_volume = esh_driver.get_volume(volume_id)
     if not esh_volume:
         return volume_not_found(volume_id)
     core_volume = convert_esh_volume(esh_volume, provider_id,
                                      identity_id, user)
     #Delete the object, update the DB
     esh_driver.destroy_volume(esh_volume)
     core_volume.end_date = datetime.now()
     core_volume.save()
     #Return the object
     serialized_data = VolumeSerializer(core_volume,
                                        context={'user':request.user},
             
             ).data
     response = Response(serialized_data)
     return response
예제 #9
0
    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)
예제 #10
0
 def patch(self, request, provider_id, identity_id, instance_id):
     """
     """
     user = request.user
     data = request.DATA
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_instance = esh_driver.get_instance(instance_id)
     if not esh_instance:
         return instance_not_found(instance_id)
     #Gather the DB related item and update
     core_instance = convert_esh_instance(esh_driver, esh_instance,
                                          provider_id, identity_id, user)
     serializer = InstanceSerializer(core_instance, data=data, partial=True)
     if serializer.is_valid():
         logger.info('metadata = %s' % data)
         update_instance_metadata(esh_driver, esh_instance, data)
         serializer.save()
         response = Response(serializer.data)
         logger.info('data = %s' % serializer.data)
         response['Cache-Control'] = 'no-cache'
         return response
     else:
         return Response(
             serializer.errors,
             status=status.HTTP_400_BAD_REQUEST)
예제 #11
0
    def get(self, request, provider_id, identity_id):
        """
        Returns a list of all instances
        """
        user = request.user
        esh_driver = prepare_driver(request, provider_id, identity_id)
        if not esh_driver:
            return invalid_creds(provider_id, identity_id)

        instance_list_method = esh_driver.list_instances

        if AccountProvider.objects.filter(identity__id=identity_id):
            # Instance list method changes when using the OPENSTACK provider
            instance_list_method = esh_driver.list_all_instances
        try:
            esh_instance_list = instance_list_method()
        except InvalidCredsError:
            return invalid_creds(provider_id, identity_id)

        core_instance_list = [convert_esh_instance(esh_driver,
                                                   inst,
                                                   provider_id,
                                                   identity_id,
                                                   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
예제 #12
0
 def get(self, request, provider_id, identity_id, instance_id):
     """
     Authentication Required, get instance details.
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_instance = esh_driver.get_instance(instance_id)
     if not esh_instance:
         try:
             core_inst = CoreInstance.objects.get(
                 provider_alias=instance_id,
                 provider_machine__provider__id=provider_id,
                 created_by_identity__id=identity_id)
             core_inst.end_date_all()
         except CoreInstance.DoesNotExist:
             pass
         return instance_not_found(instance_id)
     core_instance = convert_esh_instance(esh_driver, esh_instance,
                                          provider_id, identity_id, user)
     serialized_data = InstanceSerializer(core_instance,
                                          context={"request":request}).data
     response = Response(serialized_data)
     response['Cache-Control'] = 'no-cache'
     return response
예제 #13
0
파일: volume.py 프로젝트: eandhy/atmosphere
 def get(self, request, provider_id, identity_id, volume_id):
     """
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_volume = esh_driver.get_volume(volume_id)
     if not esh_volume:
         try:
             core_volume = CoreVolume.objects.get(alias=volume_id,
                                                  provider__id=provider_id)
             core_volume.end_date = datetime.now()
             core_volume.save()
         except CoreVolume.DoesNotExist:
             pass
         return volume_not_found(volume_id)
     core_volume = convert_esh_volume(esh_volume, provider_id, identity_id,
                                      user)
     serialized_data = VolumeSerializer(core_volume,
                                        context={
                                            'request': request
                                        }).data
     response = Response(serialized_data)
     return response
예제 #14
0
 def put(self, request, provider_id, identity_id, volume_id):
     """
     Updates DB values for volume
     """
     user = request.user
     data = request.DATA
     #Ensure volume exists
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_volume = esh_driver.get_volume(volume_id)
     if not esh_volume:
         return volume_not_found(volume_id)
     core_volume = convert_esh_volume(esh_volume, provider_id,
                                      identity_id, user)
     serializer = VolumeSerializer(core_volume, data=data,
                                   context={'request': request})
     if serializer.is_valid():
         serializer.save()
         response = Response(serializer.data)
         return response
     else:
         failure_response(
             status.HTTP_400_BAD_REQUEST,
             serializer.errors)
예제 #15
0
 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)
예제 #16
0
    def patch(self, request, provider_id, identity_id, machine_id):
        """
        TODO: Determine who is allowed to edit machines besides
            coreMachine.owner
        """
        user = request.user
        data = request.DATA
        esh_driver = prepare_driver(request, identity_id)
        esh_machine = esh_driver.get_machine(machine_id)
        coreMachine = convert_esh_machine(esh_driver, esh_machine, provider_id)

        if not user.is_staff and user is not coreMachine.application.created_by:
            logger.warn('%s is Non-staff/non-owner trying to update a machine'
                        % (user.username))
            errorObj = failureJSON([{
                'code': 401,
                'message':
                'Only Staff and the machine Owner '
                + 'are allowed to change machine info.'}])
            return Response(errorObj, status=status.HTTP_401_UNAUTHORIZED)

        coreMachine.application.update(request.DATA)
        serializer = ProviderMachineSerializer(coreMachine,
                                               data=data, partial=True)
        if serializer.is_valid():
            logger.info('metadata = %s' % data)
            update_machine_metadata(esh_driver, esh_machine, data)
            serializer.save()
            logger.info(serializer.data)
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #17
0
 def put(self, request, provider_id, identity_id, volume_id):
     """
     Updates DB values for volume
     """
     user = request.user
     data = request.DATA
     #Ensure volume exists
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_volume = esh_driver.get_volume(volume_id)
     if not esh_volume:
         return volume_not_found(volume_id)
     core_volume = convert_esh_volume(esh_volume, provider_id, identity_id,
                                      user)
     serializer = VolumeSerializer(
         core_volume,
         data=data,
         context={'user': request.user},
     )
     if serializer.is_valid():
         serializer.save()
         response = Response(serializer.data)
         return response
     else:
         failure_response(status.HTTP_400_BAD_REQUEST, serializer.errors)
예제 #18
0
def get_core_instance(request, provider_id, identity_id, instance_id):
    user = request.user
    esh_driver = prepare_driver(request, provider_id, identity_id)
    esh_instance = get_esh_instance(request, provider_id, identity_id, instance_id)
    core_instance = convert_esh_instance(esh_driver, esh_instance,
                                         provider_id, identity_id, user)
    return core_instance
예제 #19
0
 def delete(self, request, provider_id, identity_id, volume_id):
     """
     Destroys the volume and updates the DB
     """
     user = request.user
     #Ensure volume exists
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_volume = esh_driver.get_volume(volume_id)
     if not esh_volume:
         return volume_not_found(volume_id)
     core_volume = convert_esh_volume(esh_volume, provider_id, identity_id,
                                      user)
     #Delete the object, update the DB
     esh_driver.destroy_volume(esh_volume)
     core_volume.end_date = datetime.now()
     core_volume.save()
     #Return the object
     serialized_data = VolumeSerializer(
         core_volume,
         context={
             'user': request.user
         },
     ).data
     response = Response(serialized_data)
     return response
예제 #20
0
    def patch(self, request, provider_id, identity_id, instance_id):
        """
        """
        user = request.user
        data = request.DATA
        #Ensure item exists on the server first
        esh_driver = prepare_driver(request, identity_id)
        try:
            esh_instance = esh_driver.get_instance(instance_id)
        except InvalidCredsError:
            return invalid_creds(provider_id, identity_id)

        if not esh_instance:
            return instance_not_found(instance_id)

        #Gather the DB related item and update
        core_instance = convert_esh_instance(esh_driver, esh_instance,
                                           provider_id, identity_id, user)
        serializer = InstanceSerializer(core_instance, data=data, partial=True)
        if serializer.is_valid():
            logger.info('metadata = %s' % data)
            update_instance_metadata(esh_driver, esh_instance, data)
            serializer.save()
            response = Response(serializer.data)
            logger.info('data = %s' % serializer.data)
            response['Cache-Control'] = 'no-cache'
            return response
        else:
            return Response(
                serializer.errors,
                status=status.HTTP_400_BAD_REQUEST)
예제 #21
0
    def get(self, request, provider_id, identity_id):
        """
        Retrieves list of volumes and updates the DB
        """
        user = request.user
        esh_driver = prepare_driver(request, provider_id, identity_id)
        if not esh_driver:
            return invalid_creds(provider_id, identity_id)
        volume_list_method = esh_driver.list_volumes

        if AccountProvider.objects.filter(identity__id=identity_id):
            # Instance list method changes when using the OPENSTACK provider
            volume_list_method = esh_driver.list_all_volumes

        esh_volume_list = volume_list_method()

        core_volume_list = [
            convert_esh_volume(volume, provider_id, identity_id, user)
            for volume in esh_volume_list
        ]
        serializer = VolumeSerializer(core_volume_list,
                                      context={'user': request.user},
                                      many=True)
        response = Response(serializer.data)
        return response
예제 #22
0
    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)
예제 #23
0
 def get(self, request, provider_id, identity_id, action=None):
     """
     """
     if not action:
         return failure_response(status.HTTP_400_BAD_REQUEST,
                                 'Action is not supported.')
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_meta = esh_driver.meta()
     try:
         if 'test_links' in action:
             test_links = esh_meta.test_links()
             return Response(test_links, status=status.HTTP_200_OK)
     except InvalidCredsError:
         logger.warn(
             'Authentication Failed. Provider-id:%s Identity-id:%s' %
             (provider_id, identity_id))
         return failure_response(status.HTTP_401_UNAUTHORIZED,
                                 'Identity/Provider Authentication Failed')
     except NotImplemented, ne:
         logger.exception(ne)
         return failure_response(
             status.HTTP_404_NOT_FOUND,
             'The requested resource %s is not available on this provider' %
             action)
예제 #24
0
 def get(self, request, provider_id, identity_id, instance_id):
     """
     Authentication Required, get instance details.
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_instance = esh_driver.get_instance(instance_id)
     if not esh_instance:
         try:
             core_inst = CoreInstance.objects.get(
                 provider_alias=instance_id,
                 provider_machine__provider__id=provider_id,
                 created_by_identity__id=identity_id)
             core_inst.end_date_all()
         except CoreInstance.DoesNotExist:
             pass
         return instance_not_found(instance_id)
     core_instance = convert_esh_instance(esh_driver, esh_instance,
                                          provider_id, identity_id, user)
     serialized_data = InstanceSerializer(core_instance,
                                          context={
                                              "request": request
                                          }).data
     response = Response(serialized_data)
     response['Cache-Control'] = 'no-cache'
     return response
예제 #25
0
 def get(self, request, provider_id, identity_id, action=None):
     """
     """
     if not action:
         return failure_response(
             status.HTTP_400_BAD_REQUEST,
             'Action is not supported.'
         )
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_meta = esh_driver.meta()
     try:
         if 'test_links' in action:
             test_links = esh_meta.test_links()
             return Response(test_links, status=status.HTTP_200_OK)
     except InvalidCredsError:
         logger.warn('Authentication Failed. Provider-id:%s Identity-id:%s'
                     % (provider_id, identity_id))
         return failure_response(
             status.HTTP_401_UNAUTHORIZED,
             'Identity/Provider Authentication Failed')
     except NotImplemented, ne:
         logger.exception(ne)
         return failure_response(
             status.HTTP_404_NOT_FOUND,
             'The requested resource %s is not available on this provider'
             % action)
예제 #26
0
    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)
예제 #27
0
 def put(self, request, provider_id, identity_id, instance_id):
     """Authentication Required, update metadata about the instance"""
     user = request.user
     data = request.DATA
     #Ensure item exists on the server first
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_instance = esh_driver.get_instance(instance_id)
     if not esh_instance:
         return instance_not_found(instance_id)
     #Gather the DB related item and update
     core_instance = convert_esh_instance(esh_driver, esh_instance,
                                          provider_id, identity_id, user)
     serializer = InstanceSerializer(core_instance, data=data,
                                     context={"request":request})
     if serializer.is_valid():
         logger.info('metadata = %s' % data)
         update_instance_metadata(esh_driver, esh_instance, data)
         serializer.save()
         response = Response(serializer.data)
         logger.info('data = %s' % serializer.data)
         response['Cache-Control'] = 'no-cache'
         return response
     else:
         return Response(serializer.errors, status=status.HTTP_400)
예제 #28
0
def get_core_instance(request, provider_id, identity_id, instance_id):
    user = request.user
    esh_driver = prepare_driver(request, provider_id, identity_id)
    esh_instance = get_esh_instance(request, provider_id, identity_id,
                                    instance_id)
    core_instance = convert_esh_instance(esh_driver, esh_instance, provider_id,
                                         identity_id, user)
    return core_instance
예제 #29
0
def provider_filtered_machines(request, provider_id,
                               identity_id, request_user=None):
    """
    Return all filtered machines. Uses the most common,
    default filtering method.
    """
    esh_driver = prepare_driver(request, provider_id, identity_id)
    if not esh_driver:
        return invalid_creds(provider_id, identity_id)
    return list_filtered_machines(esh_driver, provider_id, request_user)
예제 #30
0
 def get(self, request, provider_id, identity_id):
     """
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     serialized_data = []
     response = Response(serialized_data)
     return response
예제 #31
0
 def get(self, request, provider_id, identity_id):
     """
     Returns all available URLs based on the user profile.
     """
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     data = add_user_urls(request, provider_id, identity_id)
     if request.user.is_staff:
         add_staff_urls(request, provider_id, identity_id)
     return Response(data)
예제 #32
0
파일: volume.py 프로젝트: eandhy/atmosphere
 def get(self, request, provider_id, identity_id, snapshot_id):
     """
     """
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     snapshot = esh_driver._connection.get_snapshot(snapshot_id)
     if not snapshot:
         return snapshot_not_found(snapshot_id)
     response = Response(snapshot)
     return response
예제 #33
0
 def get(self, request, provider_id, identity_id):
     """
     Returns all available URLs based on the user profile.
     """
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     data = add_user_urls(request, provider_id, identity_id)
     if request.user.is_staff:
         add_staff_urls(request, provider_id, identity_id)
     return Response(data)
예제 #34
0
 def get(self, request, provider_id, identity_id, snapshot_id):
     """
     """
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     snapshot = esh_driver._connection.get_snapshot(snapshot_id)
     if not snapshot:
         return snapshot_not_found(snapshot_id)
     response = Response(snapshot)
     return response
예제 #35
0
파일: size.py 프로젝트: nickeddy/atmosphere
 def get(self, request, provider_id, identity_id, size_id):
     """
     Lookup the size information (Lookup using the given provider/identity)
     Update on server DB (If applicable)
     """
     user = request.user
     esh_driver = prepare_driver(request, identity_id)
     eshSize = esh_driver.get_size(size_id)
     coreSize = convert_esh_size(eshSize, provider_id)
     serialized_data = ProviderSizeSerializer(coreSize).data
     response = Response(serialized_data)
     return response
예제 #36
0
def provider_filtered_machines(request,
                               provider_id,
                               identity_id,
                               request_user=None):
    """
    Return all filtered machines. Uses the most common,
    default filtering method.
    """
    esh_driver = prepare_driver(request, provider_id, identity_id)
    if not esh_driver:
        return invalid_creds(provider_id, identity_id)
    return list_filtered_machines(esh_driver, provider_id, request_user)
예제 #37
0
 def get(self, request, provider_id, identity_id, machine_id):
     """
     Lookup the machine information
     (Lookup using the given provider/identity)
     Update on server (If applicable)
     """
     esh_driver = prepare_driver(request, identity_id)
     eshMachine = esh_driver.get_machine(machine_id)
     coreMachine = convert_esh_machine(esh_driver, eshMachine, provider_id)
     serialized_data = ProviderMachineSerializer(coreMachine).data
     response = Response(serialized_data)
     return response
예제 #38
0
 def get(self, request, provider_id, identity_id, size_id):
     """
     Lookup the size information (Lookup using the given provider/identity)
     Update on server DB (If applicable)
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     core_size = convert_esh_size(esh_driver.get_size(size_id), provider_id)
     serialized_data = ProviderSizeSerializer(core_size).data
     response = Response(serialized_data)
     return response
예제 #39
0
 def get(self, request, provider_id, identity_id, volume_id):
     """
     """
     user = request.user
     esh_driver = prepare_driver(request, identity_id)
     esh_volume = esh_driver.get_volume(volume_id)
     if not esh_volume:
         errorObj = failureJSON([{'code': 404,
                                 'message': 'Volume does not exist'}])
         return Response(errorObj, status=status.HTTP_404_NOT_FOUND)
     core_volume = convert_esh_volume(esh_volume, provider_id, identity_id, user)
     serialized_data = VolumeSerializer(core_volume).data
     response = Response(serialized_data)
     return response
예제 #40
0
 def get(self, request, provider_id, identity_id, volume_id):
     """
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_volume = esh_driver.get_volume(volume_id)
     if not esh_volume:
         return volume_not_found(volume_id)
     core_volume = convert_esh_volume(esh_volume, provider_id,
                                      identity_id, user)
     serialized_data = VolumeSerializer(core_volume).data
     response = Response(serialized_data)
     return response
예제 #41
0
파일: flow.py 프로젝트: nickeddy/atmosphere
    def get(self, request, provider_id, identity_id):
        """
        Using provider and identity, getlist of machines
        TODO: Cache this request
        """
        user = request.user
        esh_driver = prepare_driver(request, identity_id)
        serialized_data = []
#        esh_size_list = esh_driver.list_sizes()
#        core_size_list = [convert_esh_size(size, provider_id, user)
#                          for size in esh_size_list]
#        serialized_data = ProviderSizeSerializer(core_size_list,
#        many=True).data

        response = Response(serialized_data)
        return response
예제 #42
0
 def get(self, request, provider_id, identity_id, machine_id):
     """
     Lookup the machine information
     (Lookup using the given provider/identity)
     Update on server (If applicable)
     """
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     #TODO: Need to determine that identity_id is ALLOWED to see machine_id.
     #     if not covered by calling as the users driver..
     esh_machine = esh_driver.get_machine(machine_id)
     core_machine = convert_esh_machine(esh_driver, esh_machine, provider_id)
     serialized_data = ProviderMachineSerializer(core_machine).data
     response = Response(serialized_data)
     return response
예제 #43
0
    def get(self, request, provider_id, identity_id):
        data = request.DATA
        user = User.objects.filter(username=request.user)

        if user and len(user) > 0:
            user = user[0]
        else:
            errorObj = failureJSON([{
                'code': 401,
                'message': 'User not found'}])
            return Response(errorObj, status=status.HTTP_401_UNAUTHORIZED)

        esh_driver = prepare_driver(request, identity_id)

        # Historic Machines
        all_machines_list = all_filtered_machines()

        if all_machines_list:
            history_machine_list =\
                [m for m in all_machines_list if
                 m.application.created_by.username == user.username]
            logger.warn(len(history_machine_list))
        else:
            history_machine_list = []

        page = request.QUERY_PARAMS.get('page')
        if page:
            paginator = Paginator(history_machine_list, 5)
            try:
                history_machine_page = paginator.page(page)
            except PageNotAnInteger:
                # If page is not an integer, deliver first page.
                history_machine_page = paginator.page(1)
            except EmptyPage:
                # Page is out of range.
                # deliver last page of results.
                history_machine_page = paginator.page(paginator.num_pages)
            serialized_data = \
                PaginatedProviderMachineSerializer(
                    history_machine_page).data
        else:
            serialized_data = ProviderMachineSerializer(
                history_machine_list).data

        response = Response(serialized_data)
        response['Cache-Control'] = 'no-cache'
        return response
예제 #44
0
    def get(self, request, provider_id, identity_id):
        data = request.DATA
        user = User.objects.filter(username=request.user)

        if user and len(user) > 0:
            user = user[0]
        else:
            return failure_response(status.HTTP_401_UNAUTHORIZED,
                                    "User not found.")
        esh_driver = prepare_driver(request, provider_id, identity_id)
        if not esh_driver:
            return invalid_creds(provider_id, identity_id)
        # Historic Machines
        all_machines_list = all_filtered_machines()
        if all_machines_list:
            history_machine_list =\
                [m for m in all_machines_list if
                 m.application.created_by.username == user.username]
        else:
            history_machine_list = []

        page = request.QUERY_PARAMS.get('page')
        if page or len(history_machine_list) == 0:
            paginator = Paginator(history_machine_list,
                                  5,
                                  allow_empty_first_page=True)
        else:
            paginator = Paginator(history_machine_list,
                                  len(histor_machine_list),
                                  allow_empty_first_page=True)
        try:
            history_machine_page = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            history_machine_page = paginator.page(1)
        except EmptyPage:
            # Page is out of range.
            # deliver last page of results.
            history_machine_page = paginator.page(paginator.num_pages)
        serialized_data = PaginatedProviderMachineSerializer(
            history_machine_page, context={
                'request': request
            }).data
        response = Response(serialized_data)
        response['Cache-Control'] = 'no-cache'
        return response
예제 #45
0
파일: size.py 프로젝트: nickeddy/atmosphere
 def get(self, request, provider_id, identity_id):
     """
     Using provider and identity, getlist of machines
     TODO: Cache this request
     """
     #TODO: Decide how we should pass this in (I.E. GET query string?)
     active = False
     user = request.user
     esh_driver = prepare_driver(request, identity_id)
     esh_size_list = esh_driver.list_sizes()
     all_size_list = [convert_esh_size(size, provider_id)
                      for size in esh_size_list]
     if active:
         all_size_list = [s for s in all_size_list if s.active()]
     serialized_data = ProviderSizeSerializer(all_size_list, many=True).data
     response = Response(serialized_data)
     return response
예제 #46
0
def provider_filtered_machines(request, provider_id, identity_id):
    """
    Return all filtered machines. Uses the most common,
    default filtering method.
    """
    esh_driver = prepare_driver(request, identity_id)
    esh_machine_list = esh_driver.list_machines()
    logger.info("Total machines from esh:%s" % len(esh_machine_list))
    esh_machine_list = esh_driver.filter_machines(
        esh_machine_list,
        black_list=['eki-', 'eri-'])
    core_machine_list = [convert_esh_machine(esh_driver, mach, provider_id)
                           for mach in esh_machine_list]
    filtered_machine_list = filter(filter_core_machine, core_machine_list)
    sorted_machine_list = sorted(filtered_machine_list,
                                 cmp=compare_core_machines)
    return sorted_machine_list
예제 #47
0
 def get(self, request, provider_id, identity_id, machine_id):
     """
     Lookup the machine information
     (Lookup using the given provider/identity)
     Update on server (If applicable)
     """
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     #TODO: Need to determine that identity_id is ALLOWED to see machine_id.
     #     if not covered by calling as the users driver..
     esh_machine = esh_driver.get_machine(machine_id)
     core_machine = convert_esh_machine(esh_driver, esh_machine,
                                        provider_id)
     serialized_data = ProviderMachineSerializer(core_machine).data
     response = Response(serialized_data)
     return response
예제 #48
0
def get_esh_instance(request, provider_id, identity_id, instance_id):
    esh_driver = prepare_driver(request, provider_id, identity_id)
    if not esh_driver:
        raise InvalidCredsError("Provider_id && identity_id "
                                "did not produce a valid combination")
    esh_instance = esh_driver.get_instance(instance_id)
    if not esh_instance:
        try:
            core_inst = CoreInstance.objects.get(
                provider_alias=instance_id,
                provider_machine__provider__id=provider_id,
                created_by_identity__id=identity_id)
            core_inst.end_date_all()
        except CoreInstance.DoesNotExist:
            pass
        return esh_instance
    return esh_instance
예제 #49
0
 def get(self, request, provider_id, identity_id, machine_id):
     """
     Details view for specific machine
     (Lookup using the given provider/identity)
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     #TODO: Need to determine that identity_id is ALLOWED to see machine_id.
     #     if not covered by calling as the users driver..
     esh_machine = esh_driver.get_machine(machine_id)
     core_machine = convert_esh_machine(esh_driver, esh_machine,
                                        provider_id, user)
     serialized_data = ProviderMachineSerializer(
         core_machine, request_user=request.user).data
     response = Response(serialized_data)
     return response
예제 #50
0
def get_esh_instance(request, provider_id, identity_id, instance_id):
    esh_driver = prepare_driver(request, provider_id, identity_id)
    if not esh_driver:
        raise InvalidCredsError(
                "Provider_id && identity_id "
                "did not produce a valid combination")
    esh_instance = esh_driver.get_instance(instance_id)
    if not esh_instance:
        try:
            core_inst = CoreInstance.objects.get(
                provider_alias=instance_id,
                provider_machine__provider__id=provider_id,
                created_by_identity__id=identity_id)
            core_inst.end_date_all()
        except CoreInstance.DoesNotExist:
            pass
        return esh_instance
    return esh_instance
예제 #51
0
 def get(self, request, provider_id, identity_id, instance_id):
     """
     Return the object belonging to this instance ID
     TODO: Filter out instances you shouldnt see (permissions..)
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_instance = esh_driver.get_instance(instance_id)
     if not esh_instance:
         return instance_not_found(instance_id)
     core_instance = convert_esh_instance(esh_driver, esh_instance,
                                          provider_id, identity_id, user)
     serialized_data = InstanceSerializer(core_instance).data
     response = Response(serialized_data)
     response['Cache-Control'] = 'no-cache'
     return response
예제 #52
0
 def get(self, request, provider_id, identity_id, instance_id):
     """
     Authentication Required, get instance details.
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_instance = esh_driver.get_instance(instance_id)
     if not esh_instance:
         return instance_not_found(instance_id)
     core_instance = convert_esh_instance(esh_driver, esh_instance,
                                          provider_id, identity_id, user)
     serialized_data = InstanceSerializer(core_instance,
                                          context={"request":request}).data
     response = Response(serialized_data)
     response['Cache-Control'] = 'no-cache'
     return response
예제 #53
0
 def get(self, request, provider_id, identity_id, instance_id):
     """
     Authentication Required, get instance details.
     """
     user = request.user
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_instance = esh_driver.get_instance(instance_id)
     if not esh_instance:
         return instance_not_found(instance_id)
     core_instance = convert_esh_instance(esh_driver, esh_instance,
                                          provider_id, identity_id, user)
     serialized_data = InstanceSerializer(core_instance,
                                          context={'user':request.user}).data
     response = Response(serialized_data)
     response['Cache-Control'] = 'no-cache'
     return response
예제 #54
0
파일: volume.py 프로젝트: eandhy/atmosphere
 def post(self, request, provider_id, identity_id):
     """
     Creates a new volume and adds it to the DB
     """
     user = request.user
     driver = prepare_driver(request, provider_id, identity_id)
     if not driver:
         return invalid_creds(provider_id, identity_id)
     data = request.DATA
     missing_keys = valid_create_data(data)
     if missing_keys:
         return keys_not_found(missing_keys)
     #Pass arguments
     name = data.get('name')
     size = data.get('size')
     #Optional fields
     description = data.get('description')
     image_id = data.get('image')
     if image_id:
         image = driver.get_machine(image_id)
         image_size = image._connection.get_size(image._image)
         if int(size) > image_size + 4:
             return failure_response(
                 status.HTTP_400_BAD_REQUEST,
                 "Volumes created from images cannot exceed "
                 "more than 4GB greater than the size of "
                 "the image: %s GB" % image_size)
     else:
         image = None
     snapshot_id = data.get('snapshot')
     if snapshot_id:
         snapshot = driver._connection.ex_get_snapshot(image_id)
     else:
         snapshot = None
     try:
         success, esh_volume = create_volume(driver,
                                             identity_id,
                                             name,
                                             size,
                                             description,
                                             snapshot=snapshot,
                                             image=image)
     except OverQuotaError, oqe:
         return over_quota(oqe)
예제 #55
0
파일: volume.py 프로젝트: eandhy/atmosphere
    def post(self, request, provider_id, identity_id, volume_id=None):
        user = request.user
        data = request.DATA

        missing_keys = valid_launch_data(data)
        if missing_keys:
            return keys_not_found(missing_keys)

        esh_driver = prepare_driver(request, provider_id, identity_id)
        if not esh_driver:
            return invalid_creds(provider_id, identity_id)

        source = None
        name = data.pop('name')
        size_id = data.pop('size')

        (source_type, get_source,
         source_id) = self._select_source(esh_driver, data)
        if not get_source:
            return failure_response(
                status.HTTP_400_BAD_REQUEST,
                'Source could not be acquired. Did you send: ['
                'snapshot_id/volume_id/image_id] ?')
        source = get_source(source_id)
        if not source:
            return failure_response(
                status.HTTP_404_NOT_FOUND,
                "%s %s does not exist" % (source_type.title(), source_id))
        size = esh_driver.get_size(size_id)
        if not size:
            return failure_response(status.HTTP_404_NOT_FOUND,
                                    "Size %s does not exist" % (size_id, ))

        esh_instance = boot_volume(esh_driver, identity_id, name, size, source,
                                   source_type, **data)
        core_instance = convert_esh_instance(esh_driver, esh_instance,
                                             provider_id, identity_id, user)
        serialized_data = InstanceSerializer(core_instance,
                                             context={
                                                 'request': request
                                             }).data
        response = Response(serialized_data)
        return response
예제 #56
0
 def get(self, request, provider_id, identity_id, machine_id):
     user = request.user
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     #TODO: Need to determine that identity_id is ALLOWED to see machine_id.
     #     if not covered by calling as the users driver..
     esh_machine = esh_driver.get_machine(machine_id)
     core_machine = convert_esh_machine(esh_driver, esh_machine,
                                        provider_id, user)
     if not core_machine:
         return failure_response(
             status.HTTP_400_BAD_REQUEST,
             "Could not retrieve machine with ID = %s" % machine_id)
     if not core_machine.application.icon:
         return None
     app_icon = core_machine.application.icon
     image_name, image_ext = os.path.splitext(app_icon.name)
     return Response(app_icon.file)
예제 #57
0
 def get(self, request, provider_id, identity_id):
     """
     Using provider and identity, getlist of machines
     TODO: Cache this request
     """
     #TODO: Decide how we should pass this in (I.E. GET query string?)
     active = False
     user = request.user
     esh_driver = prepare_driver(request, provider_id, identity_id)
     if not esh_driver:
         return invalid_creds(provider_id, identity_id)
     esh_size_list = esh_driver.list_sizes()
     all_size_list = [convert_esh_size(size, provider_id)
                      for size in esh_size_list]
     if active:
         all_size_list = [s for s in all_size_list if s.active()]
     serialized_data = ProviderSizeSerializer(all_size_list, many=True).data
     response = Response(serialized_data)
     return response