Пример #1
0
    def patch(self, uuid, patch):
        """Update a deployable.
        :param uuid: UUID of a deployable.
        :param patch: a json PATCH document to apply to this deployable.
        """
        context = pecan.request.context
        obj_dep = objects.Deployable.get(context, uuid)

        try:
            api_dep = Deployable(
                **api_utils.apply_jsonpatch(obj_dep.as_dict(), patch))
        except api_utils.JSONPATCH_EXCEPTIONS as e:
            raise exception.PatchError(patch=patch, reason=e)

        # Update only the fields that have changed
        for field in objects.Deployable.fields:
            try:
                patch_val = getattr(api_dep, field)
            except AttributeError:
                # Ignore fields that aren't exposed in the API
                continue
            if patch_val == wtypes.Unset:
                patch_val = None
            if obj_dep[field] != patch_val:
                obj_dep[field] = patch_val

        new_dep = pecan.request.conductor_api.deployable_update(
            context, obj_dep)
        return Deployable.convert_with_links(new_dep)
Пример #2
0
    def patch(self, uuid, patch):
        """Update an accelerator.

        :param uuid: UUID of an accelerator.
        :param patch: a json PATCH document to apply to this accelerator.
        """
        obj_acc = self._resource or self._get_resource(uuid)
        try:
            api_acc = Accelerator(
                **api_utils.apply_jsonpatch(obj_acc.as_dict(), patch))
        except api_utils.JSONPATCH_EXCEPTIONS as e:
            raise exception.PatchError(patch=patch, reason=e)

        # Update only the fields that have changed
        for field in objects.Accelerator.fields:
            try:
                patch_val = getattr(api_acc, field)
            except AttributeError:
                # Ignore fields that aren't exposed in the API
                continue
            if patch_val == wtypes.Unset:
                patch_val = None
            if obj_acc[field] != patch_val:
                obj_acc[field] = patch_val

        context = pecan.request.context
        new_acc = pecan.request.conductor_api.accelerator_update(
            context, obj_acc)
        return Accelerator.convert_with_links(new_acc)
Пример #3
0
    def put(self, uuid, patch):
        """Update an port's property.
        : param uuid: UUID of a port.
        : param patch: a json PATCH document to apply to this port.
        """
        obj_port = self._resource or self._get_resource(uuid)
        try:
            api_port = Port(
                **api_utils.apply_jsonpatch(obj_port.as_dict(), patch))
        except api_utils.JSONPATCH_EXCEPTIONS as e:
            raise exception.PatchError(patch=patch, reason=e)

        #update only the fields that have changed.
        for field in objects.Port.fields:
            try:
                patch_val = getattr(api_port, field)
            except AttributeError:
                # Ignore fields that aren't exposed in the API
                continue

            if patch_val == wtypes.Unset:
                patch_val = None
            if obj_port[field] != patch_val:
                obj_port[field] = patch_val

        context = pecan.request.context
        new_port = pecan.request.conductor_api.port_update(context, obj_port)
        return Port.convert_with_links(new_port)
Пример #4
0
    def patch(self, uuid, patch):
        """Update a deployable.

        Usage: curl -X PATCH {ip}:{port}/v1/accelerators/deployables/
        {deployable_uuid} -d '[{"path":"/instance_uuid","value":
        {instance_uuid}, "op":"replace"}]'  -H "Content-type:
        application/json"

        :param uuid: UUID of a deployable.
        :param patch: a json PATCH document to apply to this deployable.
        """
        context = pecan.request.context
        reservations = None

        obj_dep = objects.Deployable.get(context, uuid)
        try:
            # TODO(xinran): need more discussion on quota's granularity.
            # Now we count by board.
            for p in patch:
                if p["path"] == "/instance_uuid" and p["op"] == "replace":
                    if not p["value"]:
                        obj_dep["assignable"] = True
                        reserve_opts = {obj_dep["board"]: -1}
                    else:
                        obj_dep["assignable"] = False
                        reserve_opts = {obj_dep["board"]: 1}
                    reservations = QUOTAS.reserve(context, reserve_opts)
            api_dep = Deployable(
                **api_utils.apply_jsonpatch(obj_dep.as_dict(), patch))
        except api_utils.JSONPATCH_EXCEPTIONS as e:
            QUOTAS.rollback(context, reservations, project_id=None)
            raise exception.PatchError(patch=patch, reason=e)

        QUOTAS.commit(context, reservations)

        # Update only the fields that have changed
        for field in objects.Deployable.fields:
            try:
                patch_val = getattr(api_dep, field)
            except AttributeError:
                # Ignore fields that aren't exposed in the API
                continue
            if patch_val == wtypes.Unset:
                patch_val = None
            if obj_dep[field] != patch_val:
                obj_dep[field] = patch_val

        new_dep = pecan.request.conductor_api.deployable_update(
            context, obj_dep)
        return Deployable.convert_with_links(new_dep)