DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
set_connectivity_service_port Namespace Reference

Functions

 set_connectivity_service_port (oksfile, session_name, connsvc_port=0)
 

Function Documentation

◆ set_connectivity_service_port()

set_connectivity_service_port.set_connectivity_service_port ( oksfile,
session_name,
connsvc_port = 0 )
Script to set the value of the Connectivity Service port in the specified Session of the specified
OKS database file. If the new port is not specified, it is set to a random available port number.

Definition at line 7 of file set_connectivity_service_port.py.

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 def find_free_port():
28 with socket.socket() as s:
29 s.bind(("", 0))
30 s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
31 port = s.getsockname()[1]
32 s.close()
33 return port
34
35 new_port = find_free_port()
36 else:
37 new_port = connsvc_port
38
39 if session.connectivity_service is not None:
40 session.connectivity_service.service.port = new_port
41 db.update_dal(session.connectivity_service.service)
42
43 for app in session.infrastructure_applications:
44 if app.className() == "ConnectionService":
45 index = 0
46 for clparam in app.commandline_parameters:
47 if "gunicorn" in clparam:
48 pattern = re.compile(r'(.*0\.0\.0\.0)\:\d+(.*)')
49 app.commandline_parameters[index] = pattern.sub(f'\\1:{new_port}\\2', clparam)
50 #print(f"{app}")
51 db.update_dal(app)
52 break
53 index += 1
54
55 db.commit()
56 return new_port
module(name, schema, other_dals=[], backend='oksconflibs', db=None)
Definition dal.py:673