Beispiel #1
0
 def delete(self, request, container, object_name):
     try:
         api.swift.swift_delete_object(request, container, object_name)
     except exceptions.Conflict as e:
         # In case the given object is pseudo folder
         # It cannot be deleted if it's not empty.
         return rest_utils.JSONResponse(str(e), 409)
Beispiel #2
0
 def post(self, request, container, object_name):
     dest_container = request.DATA['dest_container']
     dest_name = request.DATA['dest_name']
     try:
         result = api.swift.swift_copy_object(request, container,
                                              object_name, dest_container,
                                              dest_name)
     except exceptions.AlreadyExists as e:
         return rest_utils.JSONResponse(str(e), 409)
     return rest_utils.CreatedResponse(
         u'/api/swift/containers/%s/object/%s' %
         (dest_container, result.name))
Beispiel #3
0
    def get(self, request):
        policy_targets = client.policy_target_list(
            request, tenant_id=request.user.tenant_id)

        proxy_group_ids = [
            pt.get('proxy_group_id') for pt in policy_targets
            if pt.get('proxy_group_id')
        ]

        try:
            policy_target_objects = []

            for policy_target in policy_targets:
                if not self.is_proxy_group(policy_target, proxy_group_ids):
                    subnet_objects = []

                    for subnet_id in policy_target.subnets:
                        try:
                            subnet = api.neutron.subnet_get(request, subnet_id)
                            allocation_pool_objects = []

                            allocation_pools = subnet['allocation_pools']
                            if allocation_pools:
                                for allocation_pool in allocation_pools:
                                    allocation_pool_object = {
                                        "start": allocation_pool['start'],
                                        "end": allocation_pool['end']
                                    }
                                    allocation_pool_objects.append(
                                        allocation_pool_object)

                            subnet_object = {
                                "cidr": subnet['cidr'],
                                "allocation_pools": allocation_pool_objects
                            }
                            subnet_objects.append(subnet_object)
                        except Exception:
                            LOG.exception("Unable to retrieve subnet.")

                    policy_target_object = {
                        "id": policy_target.id,
                        "name_or_id": policy_target.name_or_id,
                        "subnets": subnet_objects
                    }
                    policy_target_objects.append(policy_target_object)

            return rest_utils.JSONResponse(policy_target_objects)
        except Exception:
            msg = _("Failed to retrieve groups")
            LOG.error(msg)
            exceptions.handle(request, msg, redirect=shortcuts.redirect)
Beispiel #4
0
    def post(self, request, container):
        metadata = {}

        if 'is_public' in request.DATA:
            metadata['is_public'] = request.DATA['is_public']

        # This will raise an exception if the container already exists
        try:
            api.swift.swift_create_container(request,
                                             container,
                                             metadata=metadata)
        except exceptions.AlreadyExists as e:
            # 409 Conflict
            return rest_utils.JSONResponse(str(e), 409)

        return rest_utils.CreatedResponse(
            u'/api/swift/containers/%s' % container, )
Beispiel #5
0
    def post(self, request, container, object_name):
        """Create or replace an object or pseudo-folder

        :param request:
        :param container:
        :param object_name:

        If the object_name (ie. POST path) ends in a '/' then a folder is
        created, rather than an object. Any file content passed along with
        the request will be ignored in that case.

        POST parameter:

        :param file: the file data for the upload.

        :return:
        """
        form = UploadObjectForm(request.POST, request.FILES)
        if not form.is_valid():
            raise rest_utils.AjaxError(500, 'Invalid request')

        data = form.clean()

        if object_name[-1] == '/':
            try:
                result = api.swift.swift_create_pseudo_folder(
                    request,
                    container,
                    object_name
                )
            except exceptions.AlreadyExists as e:
                return rest_utils.JSONResponse(str(e), 409)
        else:
            result = api.swift.swift_upload_object(
                request,
                container,
                object_name,
                data['file']
            )

        return rest_utils.CreatedResponse(
            u'/api/swift/containers/%s/object/%s' % (container, result.name)
        )
Beispiel #6
0
 def delete(self, request, container):
     try:
         api.swift.swift_delete_container(request, container)
     except exceptions.Conflict as e:
         # It cannot be deleted if it's not empty.
         return rest_utils.JSONResponse(str(e), 409)
Beispiel #7
0
 def get(self, request):
     data = api.prediction.get_data(request)
     return rest_utils.JSONResponse(data)