X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2common%2Fconfig%2Fconfig.py;h=6e5d19fdadb023c6f7a5a5c7f3750b6255b54037;hb=0db2760f4162fe223e992d00e0dfa2e839a01900;hp=5fb10532f48734829840e9c85ef9581de65619f3;hpb=576ad21504bb3e50546b349c63ebec7bd0c805ab;p=pti%2Fo2.git diff --git a/o2common/config/config.py b/o2common/config/config.py index 5fb1053..6e5d19f 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 @@ -170,3 +163,61 @@ def get_helm_cli(): def get_system_controller_as_respool(): return True + + +def gen_k8s_config_dict(cluster_api_endpoint, cluster_ca_cert, admin_user, + admin_client_cert, admin_client_key): + # KUBECONFIG environment variable + # reference: + # https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/ + data = { + 'apiVersion': 'v1', + 'clusters': [ + { + 'cluster': { + 'server': + cluster_api_endpoint, + 'certificate-authority-data': + cluster_ca_cert, + }, + 'name': 'inf-cluster' + }], + 'contexts': [ + { + 'context': { + 'cluster': 'inf-cluster', + 'user': 'kubernetes-admin' + }, + 'name': 'kubernetes-admin@inf-cluster' + } + ], + 'current-context': 'kubernetes-admin@inf-cluster', + 'kind': 'Config', + 'preferences': {}, + 'users': [ + { + 'name': admin_user, + 'user': { + 'client-certificate-data': + admin_client_cert, + 'client-key-data': + admin_client_key, + } + }] + } + + return data + + +def get_helmcli_access(): + host_external = os.environ.get("API_HOST_EXTERNAL_FLOATING") + host = "127.0.0.1" if host_external is None or host_external == '' \ + else host_external + port = "10022" if host_external is None or host_external == '' \ + else "30022" + + helm_host_with_port = host+':'+port + helm_user = 'helm' + helm_pass = os.environ.get("HELM_USER_PASSWD") + + return helm_host_with_port, helm_user, helm_pass