-# Copyright (C) 2021-2023 Wind River Systems, Inc.
+# Copyright (C) 2021-2023,2025 Wind River Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
value: {{ .Values.ocloud.OS_PASSWORD }}
- name: OS_USERNAME
value: {{ .Values.ocloud.OS_USERNAME }}
- - name: OS_REGION_NAME
- value: {{ .Values.ocloud.OS_REGION_NAME }}
- name: PYTHONDONTWRITEBYTECODE
value: "1"
- name: REDIS_HOST
---
-# Copyright (C) 2021-2024 Wind River Systems, Inc.
+# Copyright (C) 2021-2025 Wind River Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
OS_AUTH_URL: ""
OS_USERNAME: ""
OS_PASSWORD: ""
- OS_REGION_NAME: "RegionOne"
K8S_KUBECONFIG: ""
API_HOST_EXTERNAL_FLOATING: ""
HELM_USER_PASSWD: "St8rlingX*"
-# Copyright (C) 2021-2025 Wind River Systems, Inc.
+# Copyright (C) 2021,2025 Wind River Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
import os
import sys
import ipaddress
+import requests
from urllib.parse import urlparse
from o2common import config
return f"https://{host}:{port}"
-def get_region_name():
- region_name = os.environ.get("OS_REGION_NAME", "RegionOne")
- return region_name
+def get_region_name(region_name=None):
+ if region_name:
+ return region_name
+
+ # For main STX client, fetch from API
+ auth_url = os.environ.get("OS_AUTH_URL")
+ if config.conf.OCLOUD.OS_AUTH_URL:
+ auth_url = config.conf.OCLOUD.OS_AUTH_URL
+
+ if auth_url:
+ try:
+ parsed_url = urlparse(auth_url)
+ ip_addr = parsed_url.hostname
+
+ if is_ipv6(ip_addr):
+ host = f'[{ip_addr}]'
+ else:
+ host = ip_addr
+
+ url = f"https://{host}:6385/v1/isystems/region_id"
+ response = requests.get(url, timeout=60, verify=False)
+
+ if response.status_code == 200:
+ data = response.json()
+ if "region_name" in data:
+ return data["region_name"]
+ else:
+ logger.error(f"Missing 'region_name' in response: {data}")
+ else:
+ logger.error(
+ f"Failed to fetch region: status {response.status_code}, "
+ f"body: {response.text}"
+ )
+ except Exception as e:
+ logger.warning(f"Failed to fetch region from API: {e}")
def get_stx_url():
return False
-def get_stx_access_info(region_name=get_region_name(),
+def get_stx_access_info(region_name=None,
subcloud_hostname: str = "",
sub_is_https: bool = False):
try:
os_client_args['insecure'] = CGTS_INSECURE_SSL
+ # Determine region name based on context
+ region_name = get_region_name(region_name)
+
if "" != subcloud_hostname:
orig_auth_url = urlparse(get_stx_url())
-# Copyright (C) 2022 Wind River Systems, Inc.
+# Copyright (C) 2022,2025 Wind River Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
if subcloud[0].oam_floating_ip == 'unavailable':
raise EnvironmentError(f"{subcloud[0].name} was unavailable")
try:
+ # Pass subcloud region name to get_region_name via
+ # get_stx_access_info
+ region_name = config.get_region_name(subcloud[0].region_name)
os_client_args = config.get_stx_access_info(
- region_name=subcloud[0].region_name,
+ region_name=region_name,
subcloud_hostname=subcloud[0].oam_floating_ip)
- # logger.info(os_client_args)
config_client = get_stx_client(**os_client_args)
except EndpointException as e:
msg = e.format_message()
if CGTSCLIENT_ENDPOINT_ERROR_MSG in msg:
+ region_name = config.get_region_name(subcloud[0].region_name)
os_client_args = config.get_stx_access_info(
- region_name=subcloud[0].region_name, sub_is_https=True,
+ region_name=region_name, sub_is_https=True,
subcloud_hostname=subcloud[0].oam_floating_ip)
- # logger.info(os_client_args)
config_client = get_stx_client(**os_client_args)
else:
raise ValueError('Stx endpoint exception: %s' % msg)