def patch(self, baymodel_uuid, patch): """Update an existing baymodel. :param baymodel_uuid: UUID of a baymodel. :param patch: a json PATCH document to apply to this baymodel. """ rpc_baymodel = objects.BayModel.get_by_uuid(pecan.request.context, baymodel_uuid) try: baymodel_dict = rpc_baymodel.as_dict() baymodel = BayModel(**api_utils.apply_jsonpatch( baymodel_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.BayModel.fields: try: patch_val = getattr(baymodel, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_baymodel[field] != patch_val: rpc_baymodel[field] = patch_val rpc_baymodel.save() return BayModel.convert_with_links(rpc_baymodel)
def patch(self, container_ident, patch): """Update an existing container. :param container_ident: UUID or name of a container. :param patch: a json PATCH document to apply to this container. """ rpc_container = api_utils.get_rpc_resource('Container', container_ident) try: container_dict = rpc_container.as_dict() container = Container(**api_utils.apply_jsonpatch( container_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.Container.fields: try: patch_val = getattr(container, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_container[field] != patch_val: rpc_container[field] = patch_val rpc_container.save() return Container.convert_with_links(rpc_container)
def patch(self, node_uuid, patch): """Update an existing node. :param node_uuid: UUID of a node. :param patch: a json PATCH document to apply to this node. """ rpc_node = objects.Node.get_by_uuid(pecan.request.context, node_uuid) try: node_dict = rpc_node.as_dict() node = Node(**api_utils.apply_jsonpatch(node_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.Node.fields: try: patch_val = getattr(node, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_node[field] != patch_val: rpc_node[field] = patch_val rpc_node.save() return Node.convert_with_links(rpc_node)
def patch(self, container_ident, patch): """Update an existing container. :param container_ident: UUID or name of a container. :param patch: a json PATCH document to apply to this container. """ rpc_container = api_utils.get_rpc_resource('Container', container_ident) try: container_dict = rpc_container.as_dict() container = Container( **api_utils.apply_jsonpatch(container_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.Container.fields: try: patch_val = getattr(container, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_container[field] != patch_val: rpc_container[field] = patch_val rpc_container.save() return Container.convert_with_links(rpc_container)
def patch(self, baymodel_uuid, patch): """Update an existing baymodel. :param baymodel_uuid: UUID of a baymodel. :param patch: a json PATCH document to apply to this baymodel. """ rpc_baymodel = objects.BayModel.get_by_uuid(pecan.request.context, baymodel_uuid) try: baymodel_dict = rpc_baymodel.as_dict() baymodel = BayModel( **api_utils.apply_jsonpatch(baymodel_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.BayModel.fields: try: patch_val = getattr(baymodel, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_baymodel[field] != patch_val: rpc_baymodel[field] = patch_val rpc_baymodel.save() return BayModel.convert_with_links(rpc_baymodel)
def patch(self, baymodel_uuid, patch): """Update an existing baymodel. :param baymodel_uuid: UUID of a baymodel. :param patch: a json PATCH document to apply to this baymodel. """ context = pecan.request.context rpc_baymodel = objects.BayModel.get_by_uuid(context, baymodel_uuid) try: baymodel_dict = rpc_baymodel.as_dict() baymodel = BayModel( **api_utils.apply_jsonpatch(baymodel_dict, patch)) except api_utils.JSONPATCH_EXCEPTIONS as e: raise exception.PatchError(patch=patch, reason=e) # check permissions when updating baymodel public flag if rpc_baymodel.public != baymodel.public: if not policy.enforce( context, "baymodel:publish", None, do_raise=False): raise exception.BaymodelPublishDenied() # Update only the fields that have changed for field in objects.BayModel.fields: try: patch_val = getattr(baymodel, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_baymodel[field] != patch_val: rpc_baymodel[field] = patch_val rpc_baymodel.save() return BayModel.convert_with_links(rpc_baymodel)
def patch(self, bay_ident, patch): """Update an existing bay. :param bay_ident: UUID or logical name of a bay. :param patch: a json PATCH document to apply to this bay. """ rpc_bay = api_utils.get_rpc_resource('Bay', bay_ident) try: bay_dict = rpc_bay.as_dict() bay = Bay(**api_utils.apply_jsonpatch(bay_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.Bay.fields: try: patch_val = getattr(bay, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_bay[field] != patch_val: rpc_bay[field] = patch_val res_bay = pecan.request.rpcapi.bay_update(rpc_bay) return Bay.convert_with_links(res_bay)
def patch(self, container_uuid, patch): """Update an existing container. :param container_uuid: UUID of a container. :param patch: a json PATCH document to apply to this container. """ if self.from_containers: raise exception.OperationNotPermitted rpc_container = objects.Container.get_by_uuid(pecan.request.context, container_uuid) try: container_dict = rpc_container.as_dict() container = Container(**api_utils.apply_jsonpatch( container_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.Container.fields: try: patch_val = getattr(container, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_container[field] != patch_val: rpc_container[field] = patch_val rpc_container.save() return Container.convert_with_links(rpc_container)
def patch(self, container_uuid, patch): """Update an existing container. :param container_uuid: UUID of a container. :param patch: a json PATCH document to apply to this container. """ if self.from_containers: raise exception.OperationNotPermitted rpc_container = objects.Container.get_by_uuid(pecan.request.context, container_uuid) try: container_dict = rpc_container.as_dict() container = Container( **api_utils.apply_jsonpatch(container_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.Container.fields: try: patch_val = getattr(container, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_container[field] != patch_val: rpc_container[field] = patch_val rpc_container.save() return Container.convert_with_links(rpc_container)
def patch(self, pod_uuid, patch): """Update an existing pod. :param pod_uuid: UUID of a pod. :param patch: a json PATCH document to apply to this pod. """ if self.from_pods: raise exception.OperationNotPermitted rpc_pod = objects.Pod.get_by_uuid(pecan.request.context, pod_uuid) try: pod_dict = rpc_pod.as_dict() pod = Pod(**api_utils.apply_jsonpatch(pod_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.Pod.fields: # ignore manifest_url as it was used for create pod if field == 'manifest_url': continue if field == 'manifest': continue try: patch_val = getattr(pod, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_pod[field] != patch_val: rpc_pod[field] = patch_val rpc_pod.save() return Pod.convert_with_links(rpc_pod)
def patch(self, container_uuid, patch): """Update an existing container. :param container_uuid: UUID of a container. :param patch: a json PATCH document to apply to this container. """ if self.from_containers: raise exception.OperationNotPermitted rpc_container = objects.Container.get_by_uuid(pecan.request.context, container_uuid) try: container_dict = rpc_container.as_dict() # NOTE(lucasagomes): # 1) Remove container_id because it's an internal value and # not present in the API object # 2) Add container_uuid container_dict['container_uuid'] = container_dict.pop( 'container_id', None) container = Container(**api_utils.apply_jsonpatch( container_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.Container.fields: try: patch_val = getattr(container, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_container[field] != patch_val: rpc_container[field] = patch_val if hasattr(pecan.request, 'rpcapi'): rpc_container = objects.Container.get_by_id(pecan.request.context, rpc_container.container_id) topic = pecan.request.rpcapi.get_topic_for(rpc_container) new_container = pecan.request.rpcapi.update_container( pecan.request.context, rpc_container, topic) return Container.convert_with_links(new_container) else: rpc_container.save() return Container.convert_with_links(rpc_container)
def patch(self, rc_ident, bay_ident, patch): """Update an existing rc. :param rc_ident: UUID or logical name of a ReplicationController. :param bay_ident: UUID or logical name of the Bay. :param patch: a json PATCH document to apply to this rc. """ rc_dict = {} rc_dict['manifest'] = None rc_dict['manifest_url'] = None try: rc = ReplicationController( **api_utils.apply_jsonpatch(rc_dict, patch)) if rc.manifest or rc.manifest_url: rc.parse_manifest() except api_utils.JSONPATCH_EXCEPTIONS as e: raise exception.PatchError(patch=patch, reason=e) rpc_rc = pecan.request.rpcapi.rc_update(rc_ident, bay_ident, rc.manifest) return ReplicationController.convert_with_links(rpc_rc)
def patch(self, rc_ident, patch): """Update an existing rc. :param rc_ident: UUID or logical name of a ReplicationController. :param patch: a json PATCH document to apply to this rc. """ if self.from_rcs: raise exception.OperationNotPermitted rpc_rc = api_utils.get_rpc_resource('ReplicationController', rc_ident) # Init manifest and manifest_url field because we don't store them # in database. rpc_rc['manifest'] = None rpc_rc['manifest_url'] = None try: rc_dict = rpc_rc.as_dict() rc = ReplicationController(**api_utils.apply_jsonpatch(rc_dict, patch)) if rc.manifest or rc.manifest_url: rc.parse_manifest() 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.ReplicationController.fields: try: patch_val = getattr(rc, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_rc[field] != patch_val: rpc_rc[field] = patch_val if rc.manifest or rc.manifest_url: pecan.request.rpcapi.rc_update(rpc_rc) else: rpc_rc.save() return ReplicationController.convert_with_links(rpc_rc)
def patch(self, pod_ident, patch): """Update an existing pod. :param pod_ident: UUID or logical name of a pod. :param patch: a json PATCH document to apply to this pod. """ if self.from_pods: raise exception.OperationNotPermitted rpc_pod = api_utils.get_rpc_resource('Pod', pod_ident) # Init manifest and manifest_url field because we don't store them # in database. rpc_pod['manifest'] = None rpc_pod['manifest_url'] = None try: pod_dict = rpc_pod.as_dict() pod = Pod(**api_utils.apply_jsonpatch(pod_dict, patch)) if pod.manifest or pod.manifest_url: pod.parse_manifest() 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.Pod.fields: try: patch_val = getattr(pod, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_pod[field] != patch_val: rpc_pod[field] = patch_val if pod.manifest or pod.manifest_url: pecan.request.rpcapi.pod_update(rpc_pod) else: rpc_pod.save() return Pod.convert_with_links(rpc_pod)
def patch(self, service_ident, patch): """Update an existing service. :param service_ident: UUID or logical name of a service. :param patch: a json PATCH document to apply to this service. """ if self.from_services: raise exception.OperationNotPermitted rpc_service = api_utils.get_rpc_resource("Service", service_ident) # Init manifest and manifest_url field because we don't store them # in database. rpc_service["manifest"] = None rpc_service["manifest_url"] = None try: service_dict = rpc_service.as_dict() service = Service(**api_utils.apply_jsonpatch(service_dict, patch)) if service.manifest or service.manifest_url: service.parse_manifest() 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.Service.fields: try: patch_val = getattr(service, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_service[field] != patch_val: rpc_service[field] = patch_val if service.manifest or service.manifest_url: pecan.request.rpcapi.service_update(rpc_service) else: rpc_service.save() return Service.convert_with_links(rpc_service)
def patch(self, rc_ident, bay_ident, patch): """Update an existing rc. :param rc_ident: UUID or logical name of a ReplicationController. :param bay_ident: UUID or logical name of the Bay. :param patch: a json PATCH document to apply to this rc. """ rc_dict = {} rc_dict['manifest'] = None rc_dict['manifest_url'] = None try: rc = ReplicationController(**api_utils.apply_jsonpatch(rc_dict, patch)) if rc.manifest or rc.manifest_url: rc.parse_manifest() except api_utils.JSONPATCH_EXCEPTIONS as e: raise exception.PatchError(patch=patch, reason=e) rpc_rc = pecan.request.rpcapi.rc_update(rc_ident, bay_ident, rc.manifest) return ReplicationController.convert_with_links(rpc_rc)
def patch(self, rc_uuid, patch): """Update an existing rc. :param rc_uuid: UUID of a ReplicationController. :param patch: a json PATCH document to apply to this rc. """ if self.from_rcs: raise exception.OperationNotPermitted rpc_rc = objects.ReplicationController.get_by_uuid( pecan.request.context, rc_uuid) try: rc_dict = rpc_rc.as_dict() rc = ReplicationController(**api_utils.apply_jsonpatch(rc_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.ReplicationController.fields: # ignore manifest_url as it was used for create rc if field == 'manifest_url': continue # ignore manifest as it was used for create rc if field == 'manifest': continue try: patch_val = getattr(rc, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_rc[field] != patch_val: rpc_rc[field] = patch_val rpc_rc.save() return ReplicationController.convert_with_links(rpc_rc)
def patch(self, rc_ident, bay_ident, patch): """Update an existing rc. :param rc_ident: UUID or logical name of a ReplicationController. :param bay_ident: UUID or logical name of the Bay. :param patch: a json PATCH document to apply to this rc. """ rpc_rc = api_utils.get_rpc_resource('ReplicationController', rc_ident) # Init manifest and manifest_url field because we don't store them # in database. rpc_rc['manifest'] = None rpc_rc['manifest_url'] = None try: rc_dict = rpc_rc.as_dict() rc = ReplicationController(**api_utils.apply_jsonpatch(rc_dict, patch)) if rc.manifest or rc.manifest_url: rc.parse_manifest() 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.ReplicationController.fields: try: patch_val = getattr(rc, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_rc[field] != patch_val: rpc_rc[field] = patch_val if rc.manifest or rc.manifest_url: pecan.request.rpcapi.rc_update(rpc_rc) else: rpc_rc.save() return ReplicationController.convert_with_links(rpc_rc)
def patch(self, pod_ident, bay_ident, patch): """Update an existing pod. :param pod_ident: UUID or logical name of a pod. :param bay_ident: UUID or logical name of the Bay. :param patch: a json PATCH document to apply to this pod. """ rpc_pod = api_utils.get_rpc_resource('Pod', pod_ident) # Init manifest and manifest_url field because we don't store them # in database. rpc_pod['manifest'] = None rpc_pod['manifest_url'] = None try: pod_dict = rpc_pod.as_dict() pod = Pod(**api_utils.apply_jsonpatch(pod_dict, patch)) if pod.manifest or pod.manifest_url: pod.parse_manifest() 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.Pod.fields: try: patch_val = getattr(pod, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_pod[field] != patch_val: rpc_pod[field] = patch_val if pod.manifest or pod.manifest_url: pecan.request.rpcapi.pod_update(rpc_pod) else: rpc_pod.save() return Pod.convert_with_links(rpc_pod)
def patch(self, rc_ident, patch): """Update an existing rc. :param rc_ident: UUID or logical name of a ReplicationController. :param patch: a json PATCH document to apply to this rc. """ if self.from_rcs: raise exception.OperationNotPermitted rpc_rc = api_utils.get_rpc_resource('ReplicationController', rc_ident) try: rc_dict = rpc_rc.as_dict() rc = ReplicationController(**api_utils.apply_jsonpatch(rc_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.ReplicationController.fields: # ignore manifest_url as it was used for create rc if field == 'manifest_url': continue # ignore manifest as it was used for create rc if field == 'manifest': continue try: patch_val = getattr(rc, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_rc[field] != patch_val: rpc_rc[field] = patch_val rpc_rc.save() return ReplicationController.convert_with_links(rpc_rc)
def patch(self, service_ident, patch): """Update an existing service. :param service_ident: UUID or logical name of a service. :param patch: a json PATCH document to apply to this service. """ rpc_service = api_utils.get_rpc_resource('Service', service_ident) # Init manifest and manifest_url field because we don't store them # in database. rpc_service['manifest'] = None rpc_service['manifest_url'] = None try: service_dict = rpc_service.as_dict() service = Service(**api_utils.apply_jsonpatch(service_dict, patch)) if service.manifest or service.manifest_url: service.parse_manifest() 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.Service.fields: try: patch_val = getattr(service, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_service[field] != patch_val: rpc_service[field] = patch_val if service.manifest or service.manifest_url: pecan.request.rpcapi.service_update(rpc_service) else: rpc_service.save() return Service.convert_with_links(rpc_service)
def patch(self, baymodel_uuid, patch): """Update an existing baymodel. :param baymodel_uuid: UUID of a baymodel. :param patch: a json PATCH document to apply to this baymodel. """ context = pecan.request.context rpc_baymodel = objects.BayModel.get_by_uuid(context, baymodel_uuid) try: baymodel_dict = rpc_baymodel.as_dict() baymodel = BayModel(**api_utils.apply_jsonpatch( baymodel_dict, patch)) except api_utils.JSONPATCH_EXCEPTIONS as e: raise exception.PatchError(patch=patch, reason=e) # check permissions when updating baymodel public flag if rpc_baymodel.public != baymodel.public: if not policy.enforce(context, "baymodel:publish", None, do_raise=False): raise exception.BaymodelPublishDenied() # Update only the fields that have changed for field in objects.BayModel.fields: try: patch_val = getattr(baymodel, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None if rpc_baymodel[field] != patch_val: rpc_baymodel[field] = patch_val rpc_baymodel.save() return BayModel.convert_with_links(rpc_baymodel)
def test_apply_jsonpatch(self, mock_jsonpatch): doc = {'bay_uuid': 'id', 'node_count': 1} patch = [{"path": "/node_count", "value": 2, "op": "replace"}] utils.apply_jsonpatch(doc, patch) mock_jsonpatch.assert_called_once_with(doc, patch)