6 """Script to set the value of the Connectivity Service port in the specified Session of the specified
7 OKS database file. If the new port is not specified, it is set to a random available k8s NodePort."""
10 print(
"Error: the session name needs to be specified")
14 session = db.get_dal(
"Session", session_name)
16 print(f
"Error: could not find Session {session_name} in file {oksfile}")
19 k8s_min_port, k8s_max_port = 30000, 32767
21 new_port = find_free_port(k8s_min_port, k8s_max_port)
22 print(f
"Found free Kubernetes NodePort: {new_port}")
24 new_port = connsvc_port
25 if not (k8s_min_port <= new_port <= k8s_max_port):
26 print(f
"Warning: Port {new_port} is outside the standard k8s NodePort range ({k8s_min_port}-{k8s_max_port}).")
29 if session.connectivity_service
is not None:
30 session.connectivity_service.service.port = new_port
31 db.update_dal(session.connectivity_service.service)
32 print(f
"Updated Connectivity Service '{session.connectivity_service.service.id}' to use port {new_port}")
34 print(f
"Error: Session '{session_name}' has no connectivity_service defined. Skipping Service object update.")
38 if hasattr(session,
'environment')
and session.environment
is not None:
40 for item
in session.environment:
41 if item.className() ==
'VariableSet':
42 for var
in item.contains:
43 if var.name ==
"CONNECTION_PORT":
44 var.value = str(new_port)
46 print(f
"Updated runtime environment variable '{var.id}' to '{new_port}'")
49 elif item.className() ==
'Variable':
50 if item.name ==
"CONNECTION_PORT":
51 item.value = str(new_port)
53 print(f
"Updated runtime environment variable '{item.id}' to '{new_port}'")
60 print(
"Error: Could not find a 'CONNECTION_PORT' variable in the session's environment.")
63 print(
"Error: Session has no 'environment' configured. Cannot update CONNECTION_PORT variable.")
67 print(f
"Successfully configured connectivity service port for session '{session_name}'.")