Loading src/device/service/drivers/nce/driver.py +2 −7 Original line number Diff line number Diff line Loading @@ -128,20 +128,14 @@ class NCEDriver(_Driver): return results def Connect(self) -> bool: url = ( self.__tfs_nbi_root + "/restconf/data/ietf-l3vpn-svc:l3vpn-svc/vpn-services" ) with self.__lock: if self.__started.is_set(): return True try: # requests.get(url, timeout=self.__timeout) ... except requests.exceptions.Timeout: LOGGER.exception("Timeout connecting {:s}".format(url)) return False except Exception: # pylint: disable=broad-except LOGGER.exception("Exception connecting {:s}".format(url)) return False else: self.__started.set() Loading Loading @@ -206,6 +200,7 @@ class NCEDriver(_Driver): with self.__lock: for resource in resources: resource_key, resource_value = resource LOGGER.debug("resource = {:s}".format(str(resource))) if RE_NCE_APP_FLOW_OPERATION.match(resource_key): operation_type = json.loads(resource_value)["type"] results.append((resource_key, True)) Loading @@ -224,7 +219,7 @@ class NCEDriver(_Driver): elif operation_type == "delete": app_flow_name = resource_value["huawei-nce-app-flow:app-flows"][ "app-flow" ][0]["name"] ][0]["app-name"] self.nce.delete_app_flow(app_flow_name) LOGGER.debug(f"app_flow_datamodel {resource_value}") results.append((resource_key, True)) Loading src/device/service/drivers/nce/nce_fan_client.py +12 −4 Original line number Diff line number Diff line Loading @@ -12,11 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import logging from typing import Optional import requests from requests.auth import HTTPBasicAuth LOGGER = logging.getLogger(__name__) NCE_FAN_URL = "{:s}://{:s}:{:d}/restconf/v1/data" TIMEOUT = 30 Loading Loading @@ -48,6 +51,7 @@ MAPPING_DRIVER = { "DEVICEDRIVER_OC": 11, } HEADERS = {'Content-Type': 'application/json'} class NCEClient: def __init__( Loading @@ -65,20 +69,24 @@ class NCEClient: try: app_data = app_flow_data["huawei-nce-app-flow:app-flows"]["applications"] app_url = self._nce_fan_url + "/app-flows/apps" requests.post(app_url, json=app_data) LOGGER.info(f'Creating app: {app_data} URL: {app_url}') # requests.post(app_url, json=app_data, headers=HEADERS) app_flow_data = { "app-flow": app_flow_data["huawei-nce-app-flow:app-flows"]["app-flow"] } app_flow_url = self._nce_fan_url + "/app-flows" requests.post(app_flow_url, json=app_flow_data) LOGGER.info(f'Creating app flow: {app_flow_data} URL: {app_flow_url}') # requests.post(app_flow_url, json=app_flow_data, headers=HEADERS) except requests.exceptions.ConnectionError: raise Exception("faild to send post requests to NCE FAN") def delete_app_flow(self, app_flow_name: str) -> None: try: app_url = self._nce_fan_url + f"/app-flows/apps/application={app_flow_name}" requests.delete(app_url) LOGGER.info(f'Deleting app: {app_flow_name} URL: {app_url}') # requests.delete(app_url) app_flow_url = self._nce_fan_url + f"/app-flows/app-flow={app_flow_name}" requests.delete(app_flow_url) LOGGER.info(f'Deleting app flow: {app_flow_name} URL: {app_flow_url}') # requests.delete(app_flow_url) except requests.exceptions.ConnectionError: raise Exception("faild to send delete request to NCE FAN") Loading
src/device/service/drivers/nce/driver.py +2 −7 Original line number Diff line number Diff line Loading @@ -128,20 +128,14 @@ class NCEDriver(_Driver): return results def Connect(self) -> bool: url = ( self.__tfs_nbi_root + "/restconf/data/ietf-l3vpn-svc:l3vpn-svc/vpn-services" ) with self.__lock: if self.__started.is_set(): return True try: # requests.get(url, timeout=self.__timeout) ... except requests.exceptions.Timeout: LOGGER.exception("Timeout connecting {:s}".format(url)) return False except Exception: # pylint: disable=broad-except LOGGER.exception("Exception connecting {:s}".format(url)) return False else: self.__started.set() Loading Loading @@ -206,6 +200,7 @@ class NCEDriver(_Driver): with self.__lock: for resource in resources: resource_key, resource_value = resource LOGGER.debug("resource = {:s}".format(str(resource))) if RE_NCE_APP_FLOW_OPERATION.match(resource_key): operation_type = json.loads(resource_value)["type"] results.append((resource_key, True)) Loading @@ -224,7 +219,7 @@ class NCEDriver(_Driver): elif operation_type == "delete": app_flow_name = resource_value["huawei-nce-app-flow:app-flows"][ "app-flow" ][0]["name"] ][0]["app-name"] self.nce.delete_app_flow(app_flow_name) LOGGER.debug(f"app_flow_datamodel {resource_value}") results.append((resource_key, True)) Loading
src/device/service/drivers/nce/nce_fan_client.py +12 −4 Original line number Diff line number Diff line Loading @@ -12,11 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import logging from typing import Optional import requests from requests.auth import HTTPBasicAuth LOGGER = logging.getLogger(__name__) NCE_FAN_URL = "{:s}://{:s}:{:d}/restconf/v1/data" TIMEOUT = 30 Loading Loading @@ -48,6 +51,7 @@ MAPPING_DRIVER = { "DEVICEDRIVER_OC": 11, } HEADERS = {'Content-Type': 'application/json'} class NCEClient: def __init__( Loading @@ -65,20 +69,24 @@ class NCEClient: try: app_data = app_flow_data["huawei-nce-app-flow:app-flows"]["applications"] app_url = self._nce_fan_url + "/app-flows/apps" requests.post(app_url, json=app_data) LOGGER.info(f'Creating app: {app_data} URL: {app_url}') # requests.post(app_url, json=app_data, headers=HEADERS) app_flow_data = { "app-flow": app_flow_data["huawei-nce-app-flow:app-flows"]["app-flow"] } app_flow_url = self._nce_fan_url + "/app-flows" requests.post(app_flow_url, json=app_flow_data) LOGGER.info(f'Creating app flow: {app_flow_data} URL: {app_flow_url}') # requests.post(app_flow_url, json=app_flow_data, headers=HEADERS) except requests.exceptions.ConnectionError: raise Exception("faild to send post requests to NCE FAN") def delete_app_flow(self, app_flow_name: str) -> None: try: app_url = self._nce_fan_url + f"/app-flows/apps/application={app_flow_name}" requests.delete(app_url) LOGGER.info(f'Deleting app: {app_flow_name} URL: {app_url}') # requests.delete(app_url) app_flow_url = self._nce_fan_url + f"/app-flows/app-flow={app_flow_name}" requests.delete(app_flow_url) LOGGER.info(f'Deleting app flow: {app_flow_name} URL: {app_flow_url}') # requests.delete(app_flow_url) except requests.exceptions.ConnectionError: raise Exception("faild to send delete request to NCE FAN")