DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
daqconf
python
daqconf
set_rc_controller_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
import
sys
5
6
def
set_rc_controller_port
(oksfile, session_name, rc_port=0):
7
"""
8
Script to set the value of the RC Controller Service port used by the specified Session
9
in the specified OKS database file. If the new port is not specified,
10
it is set to a random available k8s NodePort.
11
"""
12
try
:
13
db =
conffwk.Configuration
(
"oksconflibs:"
+ oksfile)
14
except
Exception
as
e:
15
print(f
"Error: Could not open OKS file {oksfile}. Make sure OKS_CONFLIBS_PATH is set."
)
16
print(f
"Details: {e}"
)
17
return
0
18
19
if
not
session_name:
20
print(
"Error: The session name needs to be specified"
)
21
return
0
22
else
:
23
try
:
24
session = db.get_dal(
"Session"
, session_name)
25
except
Exception:
26
print(f
"Error: Could not find Session '{session_name}' in file '{oksfile}'"
)
27
return
0
28
29
# Find a new port if one isn't specified
30
k8s_min_port, k8s_max_port = 30000, 32767
31
if
rc_port == 0:
32
new_port = find_free_port(k8s_min_port, k8s_max_port)
33
print(f
"Found free Kubernetes NodePort: {new_port}"
)
34
else
:
35
new_port = rc_port
36
if
not
(k8s_min_port <= new_port <= k8s_max_port):
37
print(f
"Warning: Port {new_port} is outside the standard k8s NodePort range ({k8s_min_port}-{k8s_max_port})."
)
38
39
# Traverse from Session -> Segment -> Controller -> Service
40
service_to_update =
None
41
try
:
42
if
not
hasattr(session,
'segment'
)
or
session.segment
is
None
:
43
print(f
"Error: Session '{session_name}' has no 'segment' defined."
)
44
return
0
45
46
segment = session.segment
47
if
not
hasattr(segment,
'controller'
)
or
segment.controller
is
None
:
48
print(f
"Error: Segment '{segment.id}' has no 'controller' defined."
)
49
return
0
50
51
controller = segment.controller
52
if
not
hasattr(controller,
'exposes_service'
)
or
not
controller.exposes_service:
53
# Check if the attribute exists AND if the list is not empty
54
print(f
"Error: Controller '{controller.id}' has no 'exposes_service' defined or the list is empty."
)
55
return
0
56
57
service_list = controller.exposes_service
58
59
if
len(service_list) > 1:
60
print(f
"Warning: Controller '{controller.id}' exposes multiple services. Only updating the first one ('{service_list[0].id}')."
)
61
62
service_to_update = service_list[0]
63
64
if
service_to_update
is
None
:
65
print(f
"Error: Controller '{controller.id}' has a null service in its 'exposes_service' list."
)
66
return
0
67
68
except
Exception
as
e:
69
print(f
"Error: Failed to navigate object graph from Session '{session_name}'."
)
70
print(f
"Details: {e}"
)
71
return
0
72
73
# Update the Service
74
if
service_to_update:
75
service_to_update.port = new_port
76
db.update_dal(service_to_update)
77
print(f
"Updated RC Controller Service '{service_to_update.id}' to use port {new_port}"
)
78
79
db.commit()
80
print(f
"Successfully configured RC controller port for session '{session_name}'."
)
81
return
new_port
82
else
:
83
# This case is mostly covered by the checks above, but serves as a fallback.
84
print(f
"Error: Could not find the RC Controller Service for session '{session_name}'."
)
85
return
0
86
conffwk.Configuration.Configuration
Definition
Configuration.py:29
set_rc_controller_port
Definition
set_rc_controller_port.py:1
Generated on
for DUNE-DAQ by
1.17.0