Commit 8dfd7cfe authored by Ivan Tyagov's avatar Ivan Tyagov

Use erp5_url rather than IP / port.

parent ec62bf62
...@@ -22,25 +22,23 @@ a = parser.add_argument ...@@ -22,25 +22,23 @@ a = parser.add_argument
a('--ip', help='The IP address on which the OPCUA Server runs', default="127.0.0.1") a('--ip', help='The IP address on which the OPCUA Server runs', default="127.0.0.1")
a('--port', help='The port on which the OPCUA Server runs', default="4840") a('--port', help='The port on which the OPCUA Server runs', default="4840")
a('--xml', help='Path of XML to configure Server. See asyncua doc for more details.', default=None) a('--xml', help='Path of XML to configure Server. See asyncua doc for more details.', default=None)
a('--erp5-ip', help='IP of ERP5 instance to which data shall be send.', default=None) a('--erp5-url', help='URL of ERP5 instance to which data shall be send.', default=None)
a('--erp5-port', help='Port of ERP5 instance to which data shall be send.', default=None)
args = parser.parse_args() args = parser.parse_args()
ip = args.ip ip = args.ip
port = args.port port = args.port
xml = args.xml xml = args.xml
erp5_ip = args.erp5_ip erp5_url = args.erp5_url
erp5_port = args.erp5_port
ERP5_REQUEST_API = "ERP5Site_handleOPCUARequest" ERP5_REQUEST_API = "ERP5Site_handleOPCUARequest"
@dataclass(frozen=True) @dataclass(frozen=True)
class ERP5Handler(asyncua.common.subscription.SubHandler): class ERP5Handler(asyncua.common.subscription.SubHandler):
ip: str url: str
port: str
session: requests.Session = field(default_factory=requests.Session) session: requests.Session = field(default_factory=requests.Session)
@property @property
def uri(self): def uri(self):
return f"http://{self.ip}:{self.port}/erp5/%s" %ERP5_REQUEST_API if self.url is not None:
return f"%s/%s" %(self.url, ERP5_REQUEST_API)
def call(self, **data): def call(self, **data):
params = urllib.parse.quote_plus(json.dumps({k: str(v) for k, v in data.items()})) params = urllib.parse.quote_plus(json.dumps({k: str(v) for k, v in data.items()}))
...@@ -53,8 +51,8 @@ class ERP5Handler(asyncua.common.subscription.SubHandler): ...@@ -53,8 +51,8 @@ class ERP5Handler(asyncua.common.subscription.SubHandler):
self.call(event=event) self.call(event=event)
erp5_handler = None erp5_handler = None
if erp5_ip is not None and erp5_port is not None: if erp5_url is not None:
erp5_handler = ERP5Handler(erp5_ip, erp5_port) erp5_handler = ERP5Handler(erp5_url)
class InternalSession(asyncua.server.internal_session.InternalSession): class InternalSession(asyncua.server.internal_session.InternalSession):
async def read(self, params): async def read(self, params):
...@@ -94,7 +92,7 @@ async def main(): ...@@ -94,7 +92,7 @@ async def main():
while True: while True:
await asyncio.sleep(1) await asyncio.sleep(1)
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.ERROR)
asyncio.run(main(), debug=True) asyncio.run(main(), debug=True)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment