Loading src/device/service/drivers/__init__.py +1 −1 Original line number Diff line number Diff line Loading @@ -109,7 +109,7 @@ DRIVERS.append( } ])) from .nce.driver import NCEDriver # pylint: disable=wrong-import-position from .nce.NCEDriver import NCEDriver # pylint: disable=wrong-import-position DRIVERS.append( (NCEDriver, [ { Loading src/device/service/drivers/nce/driver.py→src/device/service/drivers/nce/NCEDriver.py +12 −24 Original line number Diff line number Diff line Loading @@ -40,8 +40,7 @@ ALL_RESOURCE_KEYS = [ LOGGER = logging.getLogger(__name__) RE_NCE_APP_FLOW_DATA = re.compile(r'^\/service\[[^\]]+\]\/AppFlow$') RE_NCE_APP_FLOW_OPERATION = re.compile(r'^\/service\[[^\]]+\]\/AppFlow\/operation$') RE_NCE_APP_FLOW_DATA = re.compile(r'^\/service\[([^\]]+)\]\/AppFlow$') DRIVER_NAME = 'nce' Loading Loading @@ -172,15 +171,6 @@ class NCEDriver(_Driver): results = [] if len(resources) == 0: return results 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)) break else: raise Exception('operation type not found in resources') for resource in resources: LOGGER.info('resource = {:s}'.format(str(resource))) resource_key, resource_value = resource Loading @@ -188,18 +178,11 @@ class NCEDriver(_Driver): continue try: resource_value = json.loads(resource_value) if operation_type == 'create': self.nce.create_app_flow(resource_value) elif operation_type == 'delete': app_flow_name = resource_value['huawei-nce-app-flow:app-flows']['app-flow'][ 0 ]['app-name'] self.nce.delete_app_flow(app_flow_name) results.append((resource_key, True)) except Exception as e: # pylint: disable=broad-except LOGGER.exception( 'Unhandled error processing resource_key({:s})'.format(str(resource_key)) ) MSG = 'Unhandled error processing SET resource_key({:s})' LOGGER.exception(MSG.format(str(resource_key))) results.append((resource_key, e)) return results Loading @@ -211,12 +194,17 @@ class NCEDriver(_Driver): for resource in resources: LOGGER.info('resource = {:s}'.format(str(resource))) resource_key, resource_value = resource if not RE_NCE_APP_FLOW_DATA.match(resource_key): continue try: resource_value = json.loads(resource_value) app_flows = resource_value['huawei-nce-app-flow:app-flows'] app_flow_name = app_flows['app-flow'][0]['app-name'] self.nce.delete_app_flow(app_flow_name) results.append((resource_key, True)) except Exception as e: # pylint: disable=broad-except LOGGER.exception( 'Unhandled error processing resource_key({:s})'.format(str(resource_key)) ) except Exception as e: MSG = 'Unhandled error processing DELETE resource_key({:s})' LOGGER.exception(MSG.format(str(resource_key))) results.append((resource_key, e)) return results Loading Loading
src/device/service/drivers/__init__.py +1 −1 Original line number Diff line number Diff line Loading @@ -109,7 +109,7 @@ DRIVERS.append( } ])) from .nce.driver import NCEDriver # pylint: disable=wrong-import-position from .nce.NCEDriver import NCEDriver # pylint: disable=wrong-import-position DRIVERS.append( (NCEDriver, [ { Loading
src/device/service/drivers/nce/driver.py→src/device/service/drivers/nce/NCEDriver.py +12 −24 Original line number Diff line number Diff line Loading @@ -40,8 +40,7 @@ ALL_RESOURCE_KEYS = [ LOGGER = logging.getLogger(__name__) RE_NCE_APP_FLOW_DATA = re.compile(r'^\/service\[[^\]]+\]\/AppFlow$') RE_NCE_APP_FLOW_OPERATION = re.compile(r'^\/service\[[^\]]+\]\/AppFlow\/operation$') RE_NCE_APP_FLOW_DATA = re.compile(r'^\/service\[([^\]]+)\]\/AppFlow$') DRIVER_NAME = 'nce' Loading Loading @@ -172,15 +171,6 @@ class NCEDriver(_Driver): results = [] if len(resources) == 0: return results 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)) break else: raise Exception('operation type not found in resources') for resource in resources: LOGGER.info('resource = {:s}'.format(str(resource))) resource_key, resource_value = resource Loading @@ -188,18 +178,11 @@ class NCEDriver(_Driver): continue try: resource_value = json.loads(resource_value) if operation_type == 'create': self.nce.create_app_flow(resource_value) elif operation_type == 'delete': app_flow_name = resource_value['huawei-nce-app-flow:app-flows']['app-flow'][ 0 ]['app-name'] self.nce.delete_app_flow(app_flow_name) results.append((resource_key, True)) except Exception as e: # pylint: disable=broad-except LOGGER.exception( 'Unhandled error processing resource_key({:s})'.format(str(resource_key)) ) MSG = 'Unhandled error processing SET resource_key({:s})' LOGGER.exception(MSG.format(str(resource_key))) results.append((resource_key, e)) return results Loading @@ -211,12 +194,17 @@ class NCEDriver(_Driver): for resource in resources: LOGGER.info('resource = {:s}'.format(str(resource))) resource_key, resource_value = resource if not RE_NCE_APP_FLOW_DATA.match(resource_key): continue try: resource_value = json.loads(resource_value) app_flows = resource_value['huawei-nce-app-flow:app-flows'] app_flow_name = app_flows['app-flow'][0]['app-name'] self.nce.delete_app_flow(app_flow_name) results.append((resource_key, True)) except Exception as e: # pylint: disable=broad-except LOGGER.exception( 'Unhandled error processing resource_key({:s})'.format(str(resource_key)) ) except Exception as e: MSG = 'Unhandled error processing DELETE resource_key({:s})' LOGGER.exception(MSG.format(str(resource_key))) results.append((resource_key, e)) return results Loading