示例#1
0
    def delete(self, image_id, cust_id):
        image_logic, utils = di.resolver.unpack(CustomerController)
        auth.authorize(request, "tenant:delete")

        try:
            LOG.info("TenantController - delete tenant: " + str(cust_id))

            result = image_logic.delete_customer(image_id, cust_id, request.transaction_id)

            LOG.info("TenantController - tenant deleted: " + str(result))

            event_details = 'Image {} tenant {} deleted'.format(
                image_id, cust_id)
            utils.audit_trail('delete tenant', request.transaction_id,
                              request.headers, image_id,
                              event_details=event_details)

        except ErrorStatus as exception:
            LOG.log_exception("TenantController - Failed to delete tenant", exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)
        except Exception as exception:
            LOG.log_exception("TenantController - Failed to delete tenant", exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
示例#2
0
    def put(self, image_id, enabled):
        image_logic, utils = di.resolver.unpack(EnabledController)
        auth.authorize(request, "image:enable")
        try:
            LOG.info("EnabledController - received enabled = {}".format(
                enabled.enabled))
            result = image_logic.enable_image(image_id, enabled.enabled * 1,
                                              request.transaction_id)
            status = "activated"
            if not enabled.enabled:
                status = "deactivated"
            LOG.info(
                "EnabledController - Image was successfully {}".format(status))

            event_details = 'Image {} {}'.format(
                image_id, 'active' if enabled.enabled else 'inactive')
            utils.audit_trail('activate image',
                              request.transaction_id,
                              request.headers,
                              image_id,
                              event_details=event_details)
            return result

        except ErrorStatus as exception:
            LOG.log_exception("Failed in EnableImage", exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception("Failed in EnableImage", exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
示例#3
0
    def delete(self, image_id, region_name):
        image_logic, utils = di.resolver.unpack(RegionController)
        auth.authorize(request, "region:delete")
        try:
            LOG.info("RegionController - delete region: " + str(region_name))

            result = image_logic.delete_region(image_id, region_name,
                                               request.transaction_id)

            LOG.info("RegionController - region deleted: " + str(result))

            event_details = 'Image {} region {} deleted'.format(
                image_id, region_name)
            utils.audit_trail('delete region',
                              request.transaction_id,
                              request.headers,
                              image_id,
                              event_details=event_details)

        except ErrorStatus as exception:  # include NotFoundError
            LOG.log_exception("RegionController - Failed to delete region",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)
        except Exception as exception:
            LOG.log_exception("RegionController - Failed to delete region",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=exception.message)
示例#4
0
文件: images.py 项目: RaigaX9/ranger
    def delete(self, image_uuid):
        image_logic, utils = di.resolver.unpack(ImageController)
        LOG.info("Got image delete request")
        auth.authorize(request, "image:delete")
        try:
            LOG.info("ImageController - delete image: image id:" + image_uuid)
            image_logic.delete_image_by_uuid(image_uuid,
                                             request.transaction_id)
            LOG.info("ImageController - delete image finished well: ")

            event_details = 'Image {} deleted'.format(image_uuid)
            utils.audit_trail('delete image',
                              request.transaction_id,
                              request.headers,
                              image_uuid,
                              event_details=event_details)

        except ErrorStatus as exp:
            LOG.log_exception("ImageController - Failed to delete image", exp)
            raise err_utils.get_error(request.transaction_id,
                                      message=exp.message,
                                      status_code=exp.status_code)

        except Exception as exp:
            LOG.log_exception("ImageController - Failed to delete image", exp)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exp))
示例#5
0
    def put(self, image_id, cust_wrapper):
        image_logic, utils = di.resolver.unpack(CustomerController)
        auth.authorize(request, "tenant:update")
        try:
            LOG.info("CustomerController - replace tenants: " + str(cust_wrapper))

            result = image_logic.replace_customers(image_id, cust_wrapper, request.transaction_id)

            LOG.info("CustomerController - tenants replaced: " + str(result))

            event_details = 'Image {} tenants: {} updated'.format(
                image_id, cust_wrapper.customers)
            utils.audit_trail('replace tenants', request.transaction_id,
                              request.headers, image_id,
                              event_details=event_details)
            return result

        except ErrorStatus as exception:
            LOG.log_exception("TenantController - Failed to replace tenants", exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)
        except Exception as exception:
            LOG.log_exception("TenantController - Failed to replace tenants", exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
示例#6
0
    def post(self, image_id, region_name,
             metadata_wrapper):  # add metadata to region
        metadata_logic, utils = di.resolver.unpack(MetadataController)
        auth.authorize(request, "metadata:create")

        try:
            LOG.info("MetadataController - add metadata: " +
                     str(metadata_wrapper))

            metadata_logic.add_metadata(image_id, region_name,
                                        metadata_wrapper)

            LOG.info("MetadataController - metadata added")
            return "OK"

        except ErrorStatus as exception:
            LOG.log_exception("MetadataController - Failed to add metadata",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)
        except Exception as exception:
            LOG.log_exception("MetadataController - Failed to add metadata",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=exception.message)
示例#7
0
    def post(self, image_id, enabled):
        image_logic, utils = di.resolver.unpack(EnabledController)
        auth.authorize(request, "image:enable")
        try:
            LOG.debug("method not allowed only put allowed")
            raise ErrorStatus(405,
                              "method not allowed only 'put' method allowed")
            return None

        except ErrorStatus as exception:
            LOG.log_exception("Failed in EnableImage", exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception("Failed in EnableImage", exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
示例#8
0
文件: images.py 项目: RaigaX9/ranger
    def put(self, image_id, image_wrapper):
        image_logic, utils = di.resolver.unpack(ImageController)
        auth.authorize(request, "image:update")
        try:
            LOG.info("ImageController - UpdateImage: " +
                     str(image_wrapper.image.name))
            try:
                result = image_logic.update_image(image_wrapper, image_id,
                                                  request.transaction_id)
            except oslo_db.exception.DBDuplicateEntry as exception:
                raise ErrorStatus(
                    409.2,
                    'The field {0} already exists'.format(exception.columns))

            LOG.info("ImageController - UpdateImage finished well: " +
                     str(image_wrapper.image.name))

            event_details = 'Image {} {} {}, visibility: {}, created in regions: {} with tenants: {}'.format(
                image_id, image_wrapper.image.name, image_wrapper.image.url,
                image_wrapper.image.visibility,
                [r.name for r in image_wrapper.image.regions],
                image_wrapper.image.customers)
            utils.audit_trail('update image',
                              request.transaction_id,
                              request.headers,
                              image_id,
                              event_details=event_details)
            return result

        except ErrorStatus as exception:
            LOG.log_exception("Failed in UpdateImage", exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception("ImageController - Failed to UpdateImage",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
示例#9
0
文件: images.py 项目: RaigaX9/ranger
    def get(self, image_uuid):
        image_logic, utils = di.resolver.unpack(ImageController)
        LOG.info(
            "ImageController - GetImageDetails: uuid is {}".format(image_uuid))
        auth.authorize(request, "image:get_one")

        try:
            return image_logic.get_image_by_uuid(image_uuid)

        except ErrorStatus as exception:
            LOG.log_exception("ImageController - Failed to GetImageDetails",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception("ImageController - Failed to GetImageDetails",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
示例#10
0
    def put(self, image_id, region_wrapper):  # add regions to image
        image_logic, utils = di.resolver.unpack(RegionController)
        auth.authorize(request, "region:update")
        try:
            if not region_wrapper.regions:
                raise ErrorStatus(400,
                                  " bad resquest please provide correct json")
            LOG.info("RegionController - replace regions: " +
                     str(region_wrapper))

            result = image_logic.replace_regions(image_id, region_wrapper,
                                                 request.transaction_id)

            LOG.info("RegionController - regions replaced: " + str(result))

            event_details = 'Image {} regions: {} updated'.format(
                image_id, [r.name for r in region_wrapper.regions])
            utils.audit_trail('replace regions',
                              request.transaction_id,
                              request.headers,
                              image_id,
                              event_details=event_details)
            return result

        except ErrorStatus as exception:
            LOG.log_exception("RegionController - Failed to replace region",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)
        except Exception as exception:
            LOG.log_exception("RegionController - Failed to replace region",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=exception.message)
示例#11
0
文件: images.py 项目: RaigaX9/ranger
    def get_all(self, visibility=None, region=None, tenant=None):
        image_logic, utils = di.resolver.unpack(ImageController)
        auth.authorize(request, "image:list")

        try:
            LOG.info("ImageController - GetImagelist")

            result = image_logic.get_image_list_by_params(
                visibility, region, tenant)
            return result

        except ErrorStatus as exception:
            LOG.log_exception("ImageController - Failed to GetImagelist",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception("ImageController - Failed to GetImagelist",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=str(exception))
示例#12
0
文件: images.py 项目: RaigaX9/ranger
    def post(self, invalid_extra_param=None, image_wrapper=None):
        image_logic, utils = di.resolver.unpack(ImageController)
        uuid = "FailedToGetFromUUIDGen"
        auth.authorize(request, "image:create")

        if not image_wrapper:
            raise err_utils.get_error(request.transaction_id,
                                      message="Body not supplied",
                                      status_code=400)

        if invalid_extra_param:
            raise err_utils.get_error(
                request.transaction_id,
                message="URL has invalid extra param '{}' ".format(
                    invalid_extra_param),
                status_code=405)
        try:
            LOG.info("ImageController - Create image: " +
                     str(image_wrapper.image.name))
            image_wrapper.image.owner = request.headers.get(
                'X-RANGER-Owner') or ''

            if not image_wrapper.image.id:
                uuid = utils.make_uuid()
            else:
                try:
                    uuid = utils.create_existing_uuid(image_wrapper.id)
                except TypeError:
                    raise ErrorStatus(409.1,
                                      message='Image UUID already exists')

            try:
                ret_image = image_logic.create_image(image_wrapper, uuid,
                                                     request.transaction_id)
            except oslo_db.exception.DBDuplicateEntry as exception:
                raise ErrorStatus(
                    409.2,
                    'The field {0} already exists'.format(exception.columns))

            LOG.info("ImageController - Image Created: " + str(ret_image))

            event_details = 'Image {} {} {}, visibility: {}, created in regions: {} with tenants: {}'.format(
                uuid, image_wrapper.image.name, image_wrapper.image.url,
                image_wrapper.image.visibility,
                [r.name for r in image_wrapper.image.regions],
                image_wrapper.image.customers)
            utils.audit_trail('create image',
                              request.transaction_id,
                              request.headers,
                              uuid,
                              event_details=event_details)
            return ret_image

        except ErrorStatus as exception:
            LOG.log_exception("ImageController - Failed to CreateImage",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      message=exception.message,
                                      status_code=exception.status_code)

        except Exception as exception:
            LOG.log_exception("ImageController - Failed to CreateImage",
                              exception)
            raise err_utils.get_error(request.transaction_id,
                                      status_code=500,
                                      error_details=exception.message)