예제 #1
0
파일: root.py 프로젝트: RaigaX9/ranger
    def delete(self, resource):
        """handle json input.

        :param resource: input json
        :return: 200 if valid json
        :return: 405 not allowed for not valid resource to delete
        :return: 400 for bad request
        """
        operation = 'delete'
        my_logger.info("delete resource ")
        jsondata = resource.service_template.model
        my_logger.debug("parse json & get yaml file!!! {}".format(jsondata))
        jsondata = ast.literal_eval(jsondata)
        resource_uuid = resource.service_template.tracking.tracking_id
        resource_type = resource.service_template.resource.resource_type
        if resource_type not in resources_operation_list or operation not in \
                resources_operation_list[resource_type]:
            raise NotAllowedError("delete Not allowed for this"
                                  " resource %s" % resource_type)
        try:
            resource_id = ResourceService.main(jsondata, resource_uuid,
                                               resource_type, operation)
            return resource_id
        except ConflictValue as e:
            my_logger.error("the request blocked need to wait"
                            " for previous operation to be done ")
            raise LockedEntity(e.message)
        except Exception as e:
            my_logger.error("error :- %s " % str(e.message))
            raise ClientSideError(e.message)
예제 #2
0
 def test_delete_flavor_not_valid_uuid_gen(self, tranid, result, sotdata,
                                           sotupload, database):
     """delete flavor uuid gen raise an error."""
     status_model = StatusModel(status=[result])
     status_model.regions = None
     result.return_value = status_model
     with self.assertRaises(ResourceService.ErrorMesage):
         resource_id = ResourceService.main(flavorjsondata, uuid, 'flavor',
                                            'delete')
예제 #3
0
파일: root.py 프로젝트: RaigaX9/ranger
    def put(self, resource):
        """Handle HTTP POST request.

        :param Customer (json in request body):
        :return: result (json format ... {'Cusetomer':{'id':'',
        'links':{'own':'how host url'},'created':'1234567890'}}
        the response will be 201 created if success
        :return 409 for conflict
        :return 400 bad request
        handle json input
        """
        my_logger.info("modify resource")
        jsondata = resource.service_template.model
        my_logger.debug("parse json & get yaml file!!! {}".format(jsondata))
        uuid = resource.service_template.tracking.tracking_id
        resource_type = resource.service_template.resource.resource_type
        base_url = pecan.request.application_url
        jsondata = ast.literal_eval(jsondata)

        try:
            resource_id = ResourceService.main(jsondata, uuid, resource_type,
                                               'modify')
            my_logger.debug("data sent!.")
            site_link = "%s/v1/rds/%s/%s" % (base_url, resource_type,
                                             resource_id)
            res = Result(
                **{
                    resource_type:
                    CreatedResource(id=resource_id,
                                    updated='%d' % (time.time() * 1000),
                                    links=Links(site_link))
                })
            return res
        except ConflictValue as e:
            my_logger.error("the request blocked need to wait "
                            "for previous operation to be done ")
            raise LockedEntity(e.message)
        except Exception as e:
            my_logger.error("error :- %s " % str(e.message))
            raise ClientSideError(e.message)