diff options
author | Tony Hansen <tony@att.com> | 2022-03-07 20:34:07 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-03-07 20:34:07 +0000 |
commit | 6c9c8cc2a1a289ef0b4172d387376d0367549fe3 (patch) | |
tree | 86d10ee475a012545bcfc8b256f928f1996dc6de /components/pm-subscription-handler/pmsh_service/mod/aai_client.py | |
parent | f67adad42f2c857ff76b52df39f0beb5c2cabee4 (diff) | |
parent | 5a2c43f2add2c6d4af8331a40b174684eac11b34 (diff) |
Merge "[PMSH] Cleaning up old App Config, subscription handler and it's subsequent calls"
Diffstat (limited to 'components/pm-subscription-handler/pmsh_service/mod/aai_client.py')
-rwxr-xr-x | components/pm-subscription-handler/pmsh_service/mod/aai_client.py | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/components/pm-subscription-handler/pmsh_service/mod/aai_client.py b/components/pm-subscription-handler/pmsh_service/mod/aai_client.py index d2aeb0f0..437a18f0 100755 --- a/components/pm-subscription-handler/pmsh_service/mod/aai_client.py +++ b/components/pm-subscription-handler/pmsh_service/mod/aai_client.py @@ -1,5 +1,5 @@ # ============LICENSE_START=================================================== -# Copyright (C) 2019-2021 Nordix Foundation. +# Copyright (C) 2019-2022 Nordix Foundation. # ============================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,8 +20,7 @@ from os import environ import requests from requests.auth import HTTPBasicAuth import mod.network_function -import mod.pmsh_utils -from mod import logger +from mod import logger, mdc_handler def get_pmsh_nfs_from_aai(app_conf, nf_filter): @@ -68,8 +67,8 @@ def _get_all_aai_nf_data(app_conf): }""" params = {'format': 'simple', 'nodesOnly': 'true'} response = session.put(aai_named_query_endpoint, headers=headers, - auth=HTTPBasicAuth(app_conf.aaf_creds.get('aaf_id'), - app_conf.aaf_creds.get('aaf_pass')), + auth=HTTPBasicAuth(app_conf.aaf_id, + app_conf.aaf_pass), data=data, params=params, verify=(app_conf.ca_cert_path if app_conf.enable_tls else False), cert=((app_conf.cert_path, @@ -102,7 +101,7 @@ def _get_aai_service_url(): raise -@mod.pmsh_utils.mdc_handler +@mdc_handler def _get_aai_request_headers(**kwargs): return {'accept': 'application/json', 'content-type': 'application/json', @@ -160,28 +159,22 @@ def get_aai_model_data(app_conf, model_invariant_id, model_version_id, nf_name): Returns: json (dict): the sdnc_model json object. - - Raises: - Exception: if AAI model data cannot be retrieved. """ - try: - session = requests.Session() - aai_model_ver_endpoint = \ - f'{_get_aai_service_url()}/service-design-and-creation/models/model/' \ - f'{model_invariant_id}/model-vers/model-ver/{model_version_id}' - - logger.info(f'Fetching sdnc-model info for xNF: {nf_name} from AAI.') - headers = _get_aai_request_headers() - response = session.get(aai_model_ver_endpoint, headers=headers, - auth=HTTPBasicAuth(app_conf.aaf_creds.get('aaf_id'), - app_conf.aaf_creds.get('aaf_pass')), - verify=(app_conf.ca_cert_path if app_conf.enable_tls else False), - cert=((app_conf.cert_path, - app_conf.key_path) if app_conf.enable_tls else None)) - response.raise_for_status() - if response.ok: - data = json.loads(response.text) - logger.debug(f'Successfully fetched sdnc-model info from AAI: {data}') - return data - except Exception: - raise + session = requests.Session() + aai_model_ver_endpoint = \ + f'{_get_aai_service_url()}/service-design-and-creation/models/model/' \ + f'{model_invariant_id}/model-vers/model-ver/{model_version_id}' + + logger.info(f'Fetching sdnc-model info for xNF: {nf_name} from AAI.') + headers = _get_aai_request_headers() + response = session.get(aai_model_ver_endpoint, headers=headers, + auth=HTTPBasicAuth(app_conf.aaf_id, + app_conf.aaf_pass), + verify=(app_conf.ca_cert_path if app_conf.enable_tls else False), + cert=((app_conf.cert_path, + app_conf.key_path) if app_conf.enable_tls else None)) + response.raise_for_status() + if response.ok: + data = json.loads(response.text) + logger.debug(f'Successfully fetched sdnc-model info from AAI: {data}') + return data |