DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
daqconf
python
daqconf
set_connectivity_service_port.py
Go to the documentation of this file.
1
import
conffwk
2
import
confmodel_dal
3
from
daqconf.utils
import
find_free_port
4
5
def
set_connectivity_service_port
(
6
oksfile: str, session_name: str, connsvc_port: int = 0
7
) -> int:
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 k8s NodePort."""
10
db =
conffwk.Configuration
(
"oksconflibs:"
+ oksfile)
11
if
not
session_name:
12
print(
"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
Exception:
18
print(f
"Error: could not find Session {session_name} in file {oksfile}"
)
19
return
0
20
21
k8s_min_port, k8s_max_port = 30000, 32767
22
if
connsvc_port == 0:
23
new_port = find_free_port(k8s_min_port, k8s_max_port)
24
print(f
"Found free Kubernetes NodePort: {new_port}"
)
25
else
:
26
new_port = connsvc_port
27
if
not
(k8s_min_port <= new_port <= k8s_max_port):
28
print(f
"Warning: Port {new_port} is outside the standard k8s NodePort range ({k8s_min_port}-{k8s_max_port})."
)
29
30
# Update the Service
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
print(f
"Updated Connectivity Service '{session.connectivity_service.service.id}' to use port {new_port}"
)
35
else
:
36
print(f
"Error: Session '{session_name}' has no connectivity_service defined. Skipping Service object update."
)
37
return
0
38
39
# Update the env var
40
if
hasattr(session,
'environment'
)
and
session.environment
is
not
None
:
41
found_var =
False
42
for
item
in
session.environment:
43
if
item.className() ==
'VariableSet'
:
44
for
var
in
item.contains:
45
if
var.name ==
"CONNECTION_PORT"
:
46
var.value = str(new_port)
47
db.update_dal(var)
48
print(f
"Updated runtime environment variable '{var.id}' to '{new_port}'"
)
49
found_var =
True
50
break
51
elif
item.className() ==
'Variable'
:
52
if
item.name ==
"CONNECTION_PORT"
:
53
item.value = str(new_port)
54
db.update_dal(item)
55
print(f
"Updated runtime environment variable '{item.id}' to '{new_port}'"
)
56
found_var =
True
57
58
if
found_var:
59
break
60
61
if
not
found_var:
62
print(
"Error: Could not find a 'CONNECTION_PORT' variable in the session's environment."
)
63
return
0
64
else
:
65
print(
"Error: Session has no 'environment' configured. Cannot update CONNECTION_PORT variable."
)
66
return
0
67
68
db.commit()
69
print(f
"Successfully configured connectivity service port for session '{session_name}'."
)
70
return
new_port
conffwk.Configuration.Configuration
Definition
Configuration.py:29
set_connectivity_service_port
Definition
set_connectivity_service_port.py:1
Generated on
for DUNE-DAQ by
1.17.0