Пример #1
0
    def __init__(self):
        self.logger = logging.getLogger(__name__)
        self.endpoints = []
        self._channel_id_counter = 5
        self.allow_remote_admin = True

        self.aspace = AddressSpace()
        self.attribute_service = AttributeService(self.aspace)
        self.view_service = ViewService(self.aspace)
        self.method_service = MethodService(self.aspace)
        self.node_mgt_service = NodeManagementService(self.aspace)
        standard_address_space.fill_address_space(self.node_mgt_service)
        #standard_address_space.fill_address_space_from_disk(self.aspace)

        self.loop = utils.ThreadLoop()
        self.subscription_service = SubscriptionService(self.loop, self.aspace)

        # create a session to use on server side
        self.isession = InternalSession(self,
                                        self.aspace,
                                        self.subscription_service,
                                        "Internal",
                                        user=User.Admin)
        self.current_time_node = Node(
            self.isession,
            ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
        uries = ["http://opcfoundation.org/UA/"]
        ns_node = Node(self.isession,
                       ua.NodeId(ua.ObjectIds.Server_NamespaceArray))
        ns_node.set_value(uries)
Пример #2
0
    def __init__(self):
        self.logger = logging.getLogger(__name__)
        self.endpoints = []
        self._channel_id_counter = 5
        self.allow_remote_admin = True

        self.aspace = AddressSpace()
        self.attribute_service = AttributeService(self.aspace)
        self.view_service = ViewService(self.aspace)
        self.method_service = MethodService(self.aspace)
        self.node_mgt_service = NodeManagementService(self.aspace)
        standard_address_space.fill_address_space(self.node_mgt_service)  # import address space from code generated from xml
        #standard_address_space.fill_address_space_from_disk(self.aspace)  # import address space from save db to disc

        # import address space directly from xml, this has preformance impact so disabled
        #importer = xmlimporter.XmlImporter(self.node_mgt_service)
        #importer.import_xml("/home/olivier/python-opcua/schemas/Opc.Ua.NodeSet2.xml")

        self.loop = utils.ThreadLoop()
        self.subscription_service = SubscriptionService(self.loop, self.aspace)

        # create a session to use on server side
        self.isession = InternalSession(self, self.aspace, self.subscription_service, "Internal", user=User.Admin)
        self.current_time_node = Node(self.isession, ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
        uries = ["http://opcfoundation.org/UA/"]
        ns_node = Node(self.isession, ua.NodeId(ua.ObjectIds.Server_NamespaceArray))
        ns_node.set_value(uries)
Пример #3
0
    def __init__(self):
        self.logger = logging.getLogger(__name__)
        self.endpoints = []
        self._channel_id_counter = 5
        self.allow_remote_admin = True
        self.disabled_clock = False  # for debugging we may want to disable clock that writes too much in log
        self._known_servers = {}  # used if we are a discovery server

        self.aspace = AddressSpace()
        self.attribute_service = AttributeService(self.aspace)
        self.view_service = ViewService(self.aspace)
        self.method_service = MethodService(self.aspace)
        self.node_mgt_service = NodeManagementService(self.aspace)
        # import address space from code generated from xml
        standard_address_space.fill_address_space(self.node_mgt_service)
        # import address space from save db to disc
        #standard_address_space.fill_address_space_from_disk(self.aspace)

        # import address space directly from xml, this has preformance impact so disabled
        #importer = xmlimporter.XmlImporter(self.node_mgt_service)
        #importer.import_xml("/home/olivier/python-opcua/schemas/Opc.Ua.NodeSet2.xml")

        self.loop = utils.ThreadLoop()
        self.subscription_service = SubscriptionService(self.loop, self.aspace)

        # create a session to use on server side
        self.isession = InternalSession(self,
                                        self.aspace,
                                        self.subscription_service,
                                        "Internal",
                                        user=User.Admin)
        self.current_time_node = Node(
            self.isession,
            ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
        uries = ["http://opcfoundation.org/UA/"]
        ns_node = Node(self.isession,
                       ua.NodeId(ua.ObjectIds.Server_NamespaceArray))
        ns_node.set_value(uries)
Пример #4
0
 def __init__(self):
     self.logger = logging.getLogger(__name__)
     self.endpoints = []
     self._channel_id_counter = 5
     self.aspace = AddressSpace()
     self.load_standard_address_space()
     self.loop = ThreadLoop()
     self.submanager = SubscriptionManager(self.loop, self.aspace)
     # create a session to use on server side
     self.isession = InternalSession(self, self.aspace, self.submanager, "Internal") 
     self._timer = None
     self.current_time_node = Node(self.isession, ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
     uries = ["http://opcfoundation.org/UA/"]
     ns_node = Node(self.isession, ua.NodeId(ua.ObjectIds.Server_NamespaceArray))
     ns_node.set_value(uries)
Пример #5
0
    def __init__(self):
        self.logger = logging.getLogger(__name__)
        self.endpoints = []
        self._channel_id_counter = 5

        self.aspace = AddressSpace()
        self.attribute_service = AttributeService(self.aspace)
        self.view_service = ViewService(self.aspace)
        self.method_service = MethodService(self.aspace)
        self.node_mgt_service = NodeManagementService(self.aspace)
        standard_address_space.fill_address_space(self.node_mgt_service)
        #standard_address_space.fill_address_space_from_disk(self.aspace)

        self.loop = utils.ThreadLoop()
        self.subscription_service = SubscriptionService(self.loop, self.aspace)

        # create a session to use on server side
        self.isession = InternalSession(self, self.aspace, self.subscription_service, "Internal", user=User.Admin)
        self.current_time_node = Node(self.isession, ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
        uries = ["http://opcfoundation.org/UA/"]
        ns_node = Node(self.isession, ua.NodeId(ua.ObjectIds.Server_NamespaceArray))
        ns_node.set_value(uries)
Пример #6
0
class InternalServer(object):
    def __init__(self):
        self.logger = logging.getLogger(__name__)
        self.endpoints = []
        self._channel_id_counter = 5
        self.allow_remote_admin = True

        self.aspace = AddressSpace()
        self.attribute_service = AttributeService(self.aspace)
        self.view_service = ViewService(self.aspace)
        self.method_service = MethodService(self.aspace)
        self.node_mgt_service = NodeManagementService(self.aspace)
        standard_address_space.fill_address_space(
            self.node_mgt_service
        )  # import address space from code generated from xml
        #standard_address_space.fill_address_space_from_disk(self.aspace)  # import address space from save db to disc

        # import address space directly from xml, this has preformance impact so disabled
        #importer = xmlimporter.XmlImporter(self.node_mgt_service)
        #importer.import_xml("/home/olivier/python-opcua/schemas/Opc.Ua.NodeSet2.xml")

        self.loop = utils.ThreadLoop()
        self.subscription_service = SubscriptionService(self.loop, self.aspace)

        # create a session to use on server side
        self.isession = InternalSession(self,
                                        self.aspace,
                                        self.subscription_service,
                                        "Internal",
                                        user=User.Admin)
        self.current_time_node = Node(
            self.isession,
            ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
        uries = ["http://opcfoundation.org/UA/"]
        ns_node = Node(self.isession,
                       ua.NodeId(ua.ObjectIds.Server_NamespaceArray))
        ns_node.set_value(uries)

    def load_address_space(self, path):
        self.aspace.load(path)

    def dump_address_space(self, path):
        self.aspace.dump(path)

    def start(self):
        self.logger.info("starting internal server")
        self.loop.start()
        Node(self.isession,
             ua.NodeId(ua.ObjectIds.Server_ServerStatus_State)).set_value(0)
        Node(self.isession,
             ua.NodeId(ua.ObjectIds.Server_ServerStatus_StartTime)).set_value(
                 datetime.now())
        self._set_current_time()

    def stop(self):
        self.logger.info("stopping internal server")
        self.loop.stop()

    def _set_current_time(self):
        self.current_time_node.set_value(datetime.now())
        self.loop.call_later(1, self._set_current_time)

    def get_new_channel_id(self):
        self._channel_id_counter += 1
        return self._channel_id_counter

    def add_endpoint(self, endpoint):
        self.endpoints.append(endpoint)

    def get_endpoints(self, params=None, sockname=None):
        self.logger.info("get endpoint")
        if sockname:
            #return to client the ip address it has access to
            edps = []
            for edp in self.endpoints:
                edp1 = copy(edp)
                url = urlparse(edp1.EndpointUrl)
                url = url._replace(netloc=sockname[0] + ":" + str(sockname[1]))
                edp1.EndpointUrl = url.geturl()
                edps.append(edp1)
                return edps
        return self.endpoints[:]

    def find_servers(self, params):
        #FIXME: implement correctly
        servers = []
        for edp in self.endpoints:
            servers.append(edp.Server)
        return servers

    def create_session(self, name, user=User.Anonymous):
        return InternalSession(self,
                               self.aspace,
                               self.subscription_service,
                               name,
                               user=user)
Пример #7
0
class InternalServer(object):
    def __init__(self):
        self.logger = logging.getLogger(__name__)
        self.endpoints = []
        self._channel_id_counter = 5
        self.allow_remote_admin = True
        self.disabled_clock = False  # for debugging we may want to disable clock that writes too much in log
        self._known_servers = {}  # used if we are a discovery server

        self.aspace = AddressSpace()
        self.attribute_service = AttributeService(self.aspace)
        self.view_service = ViewService(self.aspace)
        self.method_service = MethodService(self.aspace)
        self.node_mgt_service = NodeManagementService(self.aspace)
        # import address space from code generated from xml
        standard_address_space.fill_address_space(self.node_mgt_service)
        # import address space from save db to disc
        #standard_address_space.fill_address_space_from_disk(self.aspace)

        # import address space directly from xml, this has preformance impact so disabled
        #importer = xmlimporter.XmlImporter(self.node_mgt_service)
        #importer.import_xml("/home/olivier/python-opcua/schemas/Opc.Ua.NodeSet2.xml")

        self.loop = utils.ThreadLoop()
        self.subscription_service = SubscriptionService(self.loop, self.aspace)

        # create a session to use on server side
        self.isession = InternalSession(self,
                                        self.aspace,
                                        self.subscription_service,
                                        "Internal",
                                        user=User.Admin)
        self.current_time_node = Node(
            self.isession,
            ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
        uries = ["http://opcfoundation.org/UA/"]
        ns_node = Node(self.isession,
                       ua.NodeId(ua.ObjectIds.Server_NamespaceArray))
        ns_node.set_value(uries)

    def load_address_space(self, path):
        self.aspace.load(path)

    def dump_address_space(self, path):
        self.aspace.dump(path)

    def start(self):
        self.logger.info("starting internal server")
        for edp in self.endpoints:
            self._known_servers[edp.Server.ApplicationUri] = ServerDesc(
                edp.Server)
        self.loop.start()
        Node(self.isession,
             ua.NodeId(ua.ObjectIds.Server_ServerStatus_State)).set_value(0)
        Node(self.isession,
             ua.NodeId(ua.ObjectIds.Server_ServerStatus_StartTime)).set_value(
                 datetime.now())
        if not self.disabled_clock:
            self._set_current_time()

    def stop(self):
        self.logger.info("stopping internal server")
        self.loop.stop()

    def _set_current_time(self):
        self.current_time_node.set_value(datetime.now())
        self.loop.call_later(1, self._set_current_time)

    def get_new_channel_id(self):
        self._channel_id_counter += 1
        return self._channel_id_counter

    def add_endpoint(self, endpoint):
        self.endpoints.append(endpoint)

    def get_endpoints(self, params=None, sockname=None):
        self.logger.info("get endpoint")
        if sockname:
            #return to client the ip address it has access to
            edps = []
            for edp in self.endpoints:
                edp1 = copy(edp)
                url = urlparse(edp1.EndpointUrl)
                url = url._replace(netloc=sockname[0] + ":" + str(sockname[1]))
                edp1.EndpointUrl = url.geturl()
                edps.append(edp1)
                return edps
        return self.endpoints[:]

    def find_servers(self, params):
        if not params.ServerUris:
            return [desc.Server for desc in self._known_servers.values()]
        servers = []
        for serv in self._known_servers.values():
            serv_uri = serv.Server.ApplicationUri.split(":")
            for uri in params.ServerUris:
                uri = uri.split(":")
                if serv_uri[:len(uri)] == uri:
                    servers.append(serv.Server)
                    break
        return servers

    def register_server(self, server, conf=None):
        appdesc = ua.ApplicationDescription()
        appdesc.ApplicationUri = server.ServerUri
        appdesc.ProductUri = server.ProductUri
        appdesc.ApplicationName = server.ServerNames[
            0]  # FIXME: select name from client locale
        appdesc.ApplicationType = server.ServerType
        appdesc.GatewayServerUri = server.GatewayServerUri
        appdesc.DiscoveryUrls = server.DiscoveryUrls  # FIXME: select discovery uri using reachability from client network
        self._known_servers[server.ServerUri] = ServerDesc(appdesc, conf)

    def register_server2(self, params):
        return self.register_server(params.Server,
                                    params.DiscoveryConfiguration)

    def create_session(self, name, user=User.Anonymous):
        return InternalSession(self,
                               self.aspace,
                               self.subscription_service,
                               name,
                               user=user)
Пример #8
0
class InternalServer(object):

    def __init__(self):
        self.logger = logging.getLogger(__name__)
        self.endpoints = []
        self._channel_id_counter = 5

        self.aspace = AddressSpace()
        self.attribute_service = AttributeService(self.aspace)
        self.view_service = ViewService(self.aspace)
        self.method_service = MethodService(self.aspace)
        self.node_mgt_service = NodeManagementService(self.aspace)
        standard_address_space.fill_address_space(self.node_mgt_service)
        #standard_address_space.fill_address_space_from_disk(self.aspace)

        self.loop = utils.ThreadLoop()
        self.subscription_service = SubscriptionService(self.loop, self.aspace)

        # create a session to use on server side
        self.isession = InternalSession(self, self.aspace, self.subscription_service, "Internal", user=User.Admin)
        self.current_time_node = Node(self.isession, ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
        uries = ["http://opcfoundation.org/UA/"]
        ns_node = Node(self.isession, ua.NodeId(ua.ObjectIds.Server_NamespaceArray))
        ns_node.set_value(uries)

    def load_address_space(self, path):
        self.aspace.load(path)

    def dump_address_space(self, path):
        self.aspace.dump(path)

    def start(self):
        self.logger.info("starting internal server")
        self.loop.start()
        Node(self.isession, ua.NodeId(ua.ObjectIds.Server_ServerStatus_State)).set_value(0)
        Node(self.isession, ua.NodeId(ua.ObjectIds.Server_ServerStatus_StartTime)).set_value(datetime.now())
        self._set_current_time()

    def stop(self):
        self.logger.info("stopping internal server")
        self.loop.stop()

    def _set_current_time(self):
        self.current_time_node.set_value(datetime.now())
        self.loop.call_later(1, self._set_current_time)

    def get_new_channel_id(self):
        self._channel_id_counter += 1
        return self._channel_id_counter

    def add_endpoint(self, endpoint):
        self.endpoints.append(endpoint)

    def get_endpoints(self, params=None, sockname=None):
        self.logger.info("get endpoint")
        if sockname:
            #return to client the ip address it has access to
            edps = []
            for edp in self.endpoints:
                edp1 = copy(edp)
                url = urlparse(edp1.EndpointUrl)
                url = url._replace(netloc=sockname[0] + ":" + str(sockname[1]))
                edp1.EndpointUrl = url.geturl()
                edps.append(edp1)
                return edps
        return self.endpoints[:]

    def find_servers(self, params):
        #FIXME: implement correctly
        servers = []
        for edp in self.endpoints:
            servers.append(edp.Server)
        return servers
        

    def create_session(self, name, user=User.Anonymous):
        return InternalSession(self, self.aspace, self.subscription_service, name, user=user)
Пример #9
0
class InternalServer(object):
    def __init__(self):
        self.logger = logging.getLogger(__name__)
        self.endpoints = []
        self._channel_id_counter = 5
        self.aspace = AddressSpace()
        self.load_standard_address_space()
        self.loop = ThreadLoop()
        self.submanager = SubscriptionManager(self.loop, self.aspace)
        # create a session to use on server side
        self.isession = InternalSession(self, self.aspace, self.submanager, "Internal") 
        self._timer = None
        self.current_time_node = Node(self.isession, ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
        uries = ["http://opcfoundation.org/UA/"]
        ns_node = Node(self.isession, ua.NodeId(ua.ObjectIds.Server_NamespaceArray))
        ns_node.set_value(uries)

    def load_address_space(self, path):
        self.aspace.load(path)

    def dump_address_space(self, path):
        self.aspace.dump(path)

    def load_standard_address_space(self):
        create_standard_address_space_Part3(self.aspace)
        create_standard_address_space_Part4(self.aspace)
        create_standard_address_space_Part5(self.aspace)
        create_standard_address_space_Part8(self.aspace)
        create_standard_address_space_Part9(self.aspace)
        create_standard_address_space_Part10(self.aspace)
        create_standard_address_space_Part11(self.aspace)
        create_standard_address_space_Part13(self.aspace)

    def start(self): 
        self.logger.info("starting internal server")
        self.loop.start()
        Node(self.isession, ua.NodeId(ua.ObjectIds.Server_ServerStatus_State)).set_value(0)
        Node(self.isession, ua.NodeId(ua.ObjectIds.Server_ServerStatus_StartTime)).set_value(datetime.now())
        self._set_current_time()

    def stop(self):
        self.logger.info("stopping internal server")
        self.loop.stop()

    def _set_current_time(self):
        self.current_time_node.set_value(datetime.now())
        self.loop.call_later(1, self._set_current_time)

    def get_new_channel_id(self):
        self._channel_id_counter += 1
        return self._channel_id_counter

    def add_endpoint(self, endpoint):
        self.endpoints.append(endpoint)

    def get_endpoints(self, params=None):
        self.logger.info("get endpoint")
        #FIXME check params
        return self.endpoints[:]
    
    def create_session(self, name):
        return InternalSession(self, self.aspace, self.submanager, name)
Пример #10
0
class InternalServer(object):

    def __init__(self):
        self.logger = logging.getLogger(__name__)
        self.endpoints = []
        self._channel_id_counter = 5
        self.allow_remote_admin = True
        self.disabled_clock = False  # for debugging we may want to disable clock that writes too much in log
        self._known_servers = {}  # used if we are a discovery server

        self.aspace = AddressSpace()
        self.attribute_service = AttributeService(self.aspace)
        self.view_service = ViewService(self.aspace)
        self.method_service = MethodService(self.aspace)
        self.node_mgt_service = NodeManagementService(self.aspace)
        # import address space from code generated from xml
        standard_address_space.fill_address_space(self.node_mgt_service)  
        # import address space from save db to disc
        #standard_address_space.fill_address_space_from_disk(self.aspace)  

        # import address space directly from xml, this has preformance impact so disabled
        #importer = xmlimporter.XmlImporter(self.node_mgt_service)
        #importer.import_xml("/home/olivier/python-opcua/schemas/Opc.Ua.NodeSet2.xml")

        self.loop = utils.ThreadLoop()
        self.subscription_service = SubscriptionService(self.loop, self.aspace)

        # create a session to use on server side
        self.isession = InternalSession(self, self.aspace, self.subscription_service, "Internal", user=User.Admin)
        self.current_time_node = Node(self.isession, ua.NodeId(ua.ObjectIds.Server_ServerStatus_CurrentTime))
        uries = ["http://opcfoundation.org/UA/"]
        ns_node = Node(self.isession, ua.NodeId(ua.ObjectIds.Server_NamespaceArray))
        ns_node.set_value(uries)

    def load_address_space(self, path):
        self.aspace.load(path)

    def dump_address_space(self, path):
        self.aspace.dump(path)

    def start(self):
        self.logger.info("starting internal server")
        self.loop.start()
        Node(self.isession, ua.NodeId(ua.ObjectIds.Server_ServerStatus_State)).set_value(0)
        Node(self.isession, ua.NodeId(ua.ObjectIds.Server_ServerStatus_StartTime)).set_value(datetime.now())
        if not self.disabled_clock:
            self._set_current_time()

    def stop(self):
        self.logger.info("stopping internal server")
        self.loop.stop()

    def _set_current_time(self):
        self.current_time_node.set_value(datetime.now())
        self.loop.call_later(1, self._set_current_time)

    def get_new_channel_id(self):
        self._channel_id_counter += 1
        return self._channel_id_counter

    def add_endpoint(self, endpoint):
        self.endpoints.append(endpoint)

    def get_endpoints(self, params=None, sockname=None):
        self.logger.info("get endpoint")
        if sockname:
            #return to client the ip address it has access to
            edps = []
            for edp in self.endpoints:
                edp1 = copy(edp)
                url = urlparse(edp1.EndpointUrl)
                url = url._replace(netloc=sockname[0] + ":" + str(sockname[1]))
                edp1.EndpointUrl = url.geturl()
                edps.append(edp1)
                return edps
        return self.endpoints[:]

    def find_servers(self, params):
        #FIXME: implement filtering from parmams.uri 
        servers = []
        for edp in self.endpoints:
            servers.append(edp.Server)
        return servers + [desc.Server for desc in self._known_servers.values()]

    def register_server(self, server, conf=None):
        appdesc = ua.ApplicationDescription()
        appdesc.ApplicationUri = server.ServerUri
        appdesc.ProductUri = server.ProductUri
        appdesc.ApplicationName = server.ServerNames[0]  # FIXME: select name from client locale
        appdesc.ApplicationType = server.ServerType
        appdesc.GatewayServerUri = server.GatewayServerUri
        appdesc.DiscoveryUrls = server.DiscoveryUrls  # FIXME: select discovery uri using reachability from client network
        self._known_servers[server.ServerUri] = ServerDesc(appdesc, conf)

    def register_server2(self, params):
        return self.register_server(params.Server, params.DiscoveryConfiguration)

    def create_session(self, name, user=User.Anonymous):
        return InternalSession(self, self.aspace, self.subscription_service, name, user=user)