def _add_node(self, item, user, check=True): #self.logger.debug("Adding node %s %s", item.RequestedNewNodeId, item.BrowseName) result = ua.AddNodesResult() if not user == User.Admin: result.StatusCode = ua.StatusCode(ua.StatusCodes.BadUserAccessDenied) return result if item.RequestedNewNodeId.has_null_identifier(): # If Identifier of requested NodeId is null we generate a new NodeId using # the namespace of the nodeid, this is an extention of the spec to allow # to requests the server to generate a new nodeid in a specified namespace #self.logger.debug("RequestedNewNodeId has null identifier, generating Identifier") item.RequestedNewNodeId = self._aspace.generate_nodeid(item.RequestedNewNodeId.NamespaceIndex) else: if item.RequestedNewNodeId in self._aspace: self.logger.warning("AddNodesItem: Requested NodeId %s already exists", item.RequestedNewNodeId) result.StatusCode = ua.StatusCode(ua.StatusCodes.BadNodeIdExists) return result if item.ParentNodeId.is_null(): # self.logger.info("add_node: while adding node %s, requested parent node is null %s %s", # item.RequestedNewNodeId, item.ParentNodeId, item.ParentNodeId.is_null()) if check: result.StatusCode = ua.StatusCode(ua.StatusCodes.BadParentNodeIdInvalid) return result parentdata = self._aspace.get(item.ParentNodeId) if parentdata is None and not item.ParentNodeId.is_null(): self.logger.info("add_node: while adding node %s, requested parent node %s does not exists", item.RequestedNewNodeId, item.ParentNodeId) result.StatusCode = ua.StatusCode(ua.StatusCodes.BadParentNodeIdInvalid) return result nodedata = NodeData(item.RequestedNewNodeId) self._add_node_attributes(nodedata, item, add_timestamps=check) # now add our node to db self._aspace[nodedata.nodeid] = nodedata if parentdata is not None: self._add_ref_from_parent(nodedata, item, parentdata) self._add_ref_to_parent(nodedata, item, parentdata) # add type definition if item.TypeDefinition != ua.NodeId(): self._add_type_definition(nodedata, item) result.StatusCode = ua.StatusCode() result.AddedNodeId = nodedata.nodeid return result
def _add_node(self, item, user, check=True): # self.logger.debug("Adding node %s %s", item.RequestedNewNodeId, item.BrowseName) result = ua.AddNodesResult() if not user.role == UserRole.Admin: result.StatusCode = ua.StatusCode( ua.StatusCodes.BadUserAccessDenied) return result if item.RequestedNewNodeId.has_null_identifier(): # If Identifier of requested NodeId is null we generate a new NodeId using # the namespace of the nodeid, this is an extention of the spec to allow # to requests the server to generate a new nodeid in a specified namespace # self.logger.debug("RequestedNewNodeId has null identifier, generating Identifier") item.RequestedNewNodeId = self._aspace.generate_nodeid( item.RequestedNewNodeId.NamespaceIndex) else: if item.RequestedNewNodeId in self._aspace: self.logger.warning( "AddNodesItem: Requested NodeId %s already exists", item.RequestedNewNodeId) result.StatusCode = ua.StatusCode( ua.StatusCodes.BadNodeIdExists) return result if item.ParentNodeId.is_null(): # self.logger.info("add_node: while adding node %s, requested parent node is null %s %s", # item.RequestedNewNodeId, item.ParentNodeId, item.ParentNodeId.is_null()) if check: result.StatusCode = ua.StatusCode( ua.StatusCodes.BadParentNodeIdInvalid) return result parentdata = self._aspace.get(item.ParentNodeId) if parentdata is None and not item.ParentNodeId.is_null(): self.logger.info( "add_node: while adding node %s, requested parent node %s does not exists", item.RequestedNewNodeId, item.ParentNodeId) result.StatusCode = ua.StatusCode( ua.StatusCodes.BadParentNodeIdInvalid) return result if item.ParentNodeId in self._aspace: for ref in self._aspace[item.ParentNodeId].references: # Check if the Parent has a "HasChild" Reference (or subtype of it) with the Node if ref.ReferenceTypeId.Identifier in [ ua.ObjectIds.HasChild, ua.ObjectIds.HasComponent, ua.ObjectIds.HasProperty, ua.ObjectIds.HasSubtype, ua.ObjectIds.HasOrderedComponent ] and ref.IsForward: if item.BrowseName.Name == ref.BrowseName.Name: self.logger.warning( f"AddNodesItem: Requested Browsename {item.BrowseName.Name}" f" already exists in Parent Node. ParentID:{item.ParentNodeId} --- " f"ItemId:{item.RequestedNewNodeId}") result.StatusCode = ua.StatusCode( ua.StatusCodes.BadBrowseNameDuplicated) return result nodedata = NodeData(item.RequestedNewNodeId) self._add_node_attributes(nodedata, item, add_timestamps=check) # now add our node to db self._aspace[nodedata.nodeid] = nodedata if parentdata is not None: self._add_ref_from_parent(nodedata, item, parentdata) self._add_ref_to_parent(nodedata, item, parentdata) # add type definition if item.TypeDefinition != ua.NodeId(): self._add_type_definition(nodedata, item) result.StatusCode = ua.StatusCode() result.AddedNodeId = nodedata.nodeid return result