Commit e6a11302 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Device component - NCE:

- Properly implemented set/delete
- Code polishing
parent d7826918
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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, [
        {
+12 −24
Original line number Diff line number Diff line
@@ -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'
@@ -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
@@ -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

@@ -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