DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
set_connectivity_service_port.py
Go to the documentation of this file.
1import conffwk
2import confmodel_dal
3from daqconf.utils import find_free_port
4
5import re
6
7def set_connectivity_service_port(oksfile, session_name, connsvc_port=0):
8 """Script to set the value of the Connectivity Service port in the specified Session of the specified
9 OKS database file. If the new port is not specified, it is set to a random available port number."""
10 db = conffwk.Configuration("oksconflibs:" + oksfile)
11 if session_name == "":
12 print(f"Error: the session name needs to be specified")
13 return 0
14 else:
15 try:
16 session = db.get_dal("Session", session_name)
17 except:
18 print(f"Error could not find Session {session_name} in file {oksfile}")
19 return 0
20
21 schemafiles = [
22 "schema/confmodel/dunedaq.schema.xml"
23 ]
24 dal = conffwk.dal.module("dal", schemafiles)
25
26 if connsvc_port == 0:
27 new_port = find_free_port()
28 else:
29 new_port = connsvc_port
30
31 if session.connectivity_service is not None:
32 session.connectivity_service.service.port = new_port
33 db.update_dal(session.connectivity_service.service)
34
35 for app in session.infrastructure_applications:
36 if app.className() == "ConnectionService":
37 index = 0
38 for clparam in app.commandline_parameters:
39 if "gunicorn" in clparam:
40 pattern = re.compile(r'(.*0\.0\.0\.0)\:\d+(.*)')
41 app.commandline_parameters[index] = pattern.sub(f'\\1:{new_port}\\2', clparam)
42 #print(f"{app}")
43 db.update_dal(app)
44 break
45 index += 1
46
47 db.commit()
48 return new_port
module(name, schema, other_dals=[], backend='oksconflibs', db=None)
Definition dal.py:673