Retrieve Region name from the API 15/14715/9
authorvpachchi <vineela.pachchipulusu@windriver.com>
Mon, 14 Jul 2025 07:05:16 +0000 (03:05 -0400)
committervpachchi <vineela.pachchipulusu@windriver.com>
Mon, 14 Jul 2025 16:07:49 +0000 (12:07 -0400)
TEST PLAN
PASS: warning message "public endpoint for platform service in
RegionOne region not found" is not seen

Change-Id: I446430df2739b1888f6c84bf93b38e410a05bf74
Signed-off-by: vpachchi <vineela.pachchipulusu@windriver.com>
charts/templates/deployment.yaml
charts/values.yaml
o2common/config/config.py
o2ims/adapter/clients/ocloud_client.py

index 5b7967e..61fe3c6 100644 (file)
@@ -1,4 +1,4 @@
-# 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.
@@ -133,8 +133,6 @@ spec:
               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
index ee88d9c..e6bd5c1 100644 (file)
@@ -1,5 +1,5 @@
 ---
-# 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.
@@ -77,7 +77,6 @@ ocloud:
   OS_AUTH_URL: ""
   OS_USERNAME: ""
   OS_PASSWORD: ""
-  OS_REGION_NAME: "RegionOne"
   K8S_KUBECONFIG: ""
   API_HOST_EXTERNAL_FLOATING: ""
   HELM_USER_PASSWD: "St8rlingX*"
index 74521b7..e4afd33 100644 (file)
@@ -1,4 +1,4 @@
-# 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.
@@ -15,6 +15,7 @@
 import os
 import sys
 import ipaddress
+import requests
 from urllib.parse import urlparse
 
 from o2common import config
@@ -66,9 +67,41 @@ def get_api_url():
     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():
@@ -169,7 +202,7 @@ def is_ipv6(address):
         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:
@@ -185,6 +218,9 @@ def get_stx_access_info(region_name=get_region_name(),
 
     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())
 
index 6cbeda7..ea1b67b 100644 (file)
@@ -1,4 +1,4 @@
-# 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.
@@ -231,18 +231,20 @@ class StxClientImp(object):
         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)