From 2ec12b6c645d9537c0aa4e508ea6885752a55580 Mon Sep 17 00:00:00 2001 From: "Zhang Rong(Jon)" Date: Thu, 26 May 2022 14:42:22 +0800 Subject: [PATCH] Support distributed cloud with or without SSL 1. keep the http scheme for the sub cloud without SSL 2. Use the insecure parameter for the sub-cloud with SSL, and use the https Issue-ID: INF-275 Signed-off-by: Zhang Rong(Jon) Change-Id: I105877e2a2d9f316a08b2f58eb096a1ff29bd0e9 --- README.md | 2 +- o2common/config/config.py | 21 +++++++-------------- o2ims/adapter/clients/ocloud_client.py | 30 +++++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 7d357a5..e2e74e0 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ git clone --depth 1 --branch master https://opendev.org/starlingx/config.git git clone --depth 1 --branch master https://opendev.org/starlingx/distcloud-client.git cd config git checkout bca406d1 -patch -p1 < ../../cgtsclient-insecure.patch +patch -p1 < ../../cgtsclient-insecure.patch cd - ``` diff --git a/o2common/config/config.py b/o2common/config/config.py index 5fb1053..b8186b8 100644 --- a/o2common/config/config.py +++ b/o2common/config/config.py @@ -73,7 +73,8 @@ def get_smo_o2endpoint(): return smo_o2endpoint -def get_stx_access_info(region_name="RegionOne", subcloud_hostname: str = ""): +def get_stx_access_info(region_name="RegionOne", subcloud_hostname: str = "", + sub_is_https: bool = False): # authurl = os.environ.get("STX_AUTH_URL", "http://192.168.204.1:5000/v3") # username = os.environ.get("STX_USERNAME", "admin") # pswd = os.environ.get("STX_PASSWORD", "passwd1") @@ -85,15 +86,6 @@ def get_stx_access_info(region_name="RegionOne", subcloud_hostname: str = ""): api_key=os.environ.get('OS_PASSWORD', "fakepasswd1"), project_name=os.environ.get('OS_PROJECT_NAME', "admin"), ) - # dc_client_args = dict( - # auth_url=os.environ['OS_AUTH_URL'], - # username=os.environ['OS_USERNAME'], - # api_key=os.environ['OS_PASSWORD'], - # project_name=os.environ['OS_PROJECT_NAME'], - # user_domain_name=os.environ['OS_USER_DOMAIN_NAME'], - # project_domain_name=os.environ['OS_PROJECT_NAME'], - # project_domain_id=os.environ['OS_PROJECT_DOMAIN_ID'] - # ) except KeyError: logger.error('Please source your RC file before execution, ' 'e.g.: `source ~/downloads/admin-rc.sh`') @@ -110,12 +102,13 @@ def get_stx_access_info(region_name="RegionOne", subcloud_hostname: str = ""): # new_auth_url = new_auth_url._replace( # netloc=new_auth_url.netloc.replace(str(new_auth_url.port), # "18002")) - new_auth_url = new_auth_url._replace( - scheme=new_auth_url.scheme. - replace(new_auth_url.scheme, 'https')) + if sub_is_https: + new_auth_url = new_auth_url._replace( + scheme=new_auth_url.scheme. + replace(new_auth_url.scheme, 'https')) + os_client_args['insecure'] = True os_client_args['os_auth_url'] = new_auth_url.geturl() os_client_args['os_endpoint_type'] = 'public' - os_client_args['insecure'] = True # os_client_args['system_url'] = os_client_args['os_auth_url'] os_client_args['os_password'] = os_client_args.pop('os_api_key') os_client_args['os_region_name'] = region_name diff --git a/o2ims/adapter/clients/ocloud_client.py b/o2ims/adapter/clients/ocloud_client.py index d7abd87..e963987 100644 --- a/o2ims/adapter/clients/ocloud_client.py +++ b/o2ims/adapter/clients/ocloud_client.py @@ -24,12 +24,17 @@ from o2ims.domain.resource_type import ResourceTypeEnum # from dcmanagerclient.api import client from cgtsclient.client import get_client as get_stx_client +from cgtsclient.exc import EndpointException from dcmanagerclient.api.client import client as get_dc_client from o2common.helper import o2logging logger = o2logging.get_logger(__name__) +CGTSCLIENT_ENDPOINT_ERROR_MSG = \ + 'Must provide Keystone credentials or user-defined endpoint and token' + + class StxOcloudClient(BaseClient): def __init__(self, driver=None): super().__init__() @@ -191,10 +196,24 @@ class StxClientImp(object): subcloud_additional_details(subcloud_id) logger.debug('subcloud name: %s, oam_floating_ip: %s' % (subcloud[0].name, subcloud[0].oam_floating_ip)) - os_client_args = config.get_stx_access_info( - region_name=subcloud[0].name, - subcloud_hostname=subcloud[0].oam_floating_ip) - config_client = get_stx_client(**os_client_args) + try: + os_client_args = config.get_stx_access_info( + region_name=subcloud[0].name, + subcloud_hostname=subcloud[0].oam_floating_ip) + logger.warning(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: + os_client_args = config.get_stx_access_info( + region_name=subcloud[0].name, sub_is_https=True, + subcloud_hostname=subcloud[0].oam_floating_ip) + logger.warning(os_client_args) + config_client = get_stx_client(**os_client_args) + else: + raise ValueError('Stx endpoint exception: %s' % msg) + else: + raise ValueError('cgtsclient get subcloud client failed') return config_client def setStxClient(self, resource_pool_id): @@ -243,8 +262,9 @@ class StxClientImp(object): subclouds = self.getSubcloudList() logger.debug('subclouds numbers: %s' % len(subclouds)) for subcloud in subclouds: - subcloud_stxclient = self.getSubcloudClient(subcloud.subcloud_id) try: + subcloud_stxclient = self.getSubcloudClient( + subcloud.subcloud_id) systems = subcloud_stxclient.isystem.list() logger.debug('systems:' + str(systems[0].to_dict())) pools.append(systems[0]) -- 2.16.6