From 79444d36e07d2e43697fe6b35d8870a371062690 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Fri, 20 Nov 2020 11:47:35 -0600 Subject: ifupdown-ng NMSA: Factor common methods into one --- ncserver/module/nms_ifupdownng.py | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/ncserver/module/nms_ifupdownng.py b/ncserver/module/nms_ifupdownng.py index 5a06f47..f844d32 100644 --- a/ncserver/module/nms_ifupdownng.py +++ b/ncserver/module/nms_ifupdownng.py @@ -172,25 +172,24 @@ def _iface_path(iface: str) -> pathlib.Path: # P A R A M E T E R S # ############################# +_ENI_MAPPING = {'description': 'netconf-description', + 'enabled': 'auto'} +"""Mapping of NMSA keys to /e/n/i keys.""" -def get_desc(iface: str, _): - """Retrieve the description for the specified interface.""" - return _find_one(iface, 'netconf-description') +def get_one_eni(iface: str, parameter: str): + """Retrieve the specified parameter from /e/n/i.""" + return _find_one(iface, _ENI_MAPPING[parameter]) -def set_desc(iface: str, _, value: str): - """Set the description for the specified interface.""" - _replace_one(iface, 'netconf-description', value) +def unset_one_eni(iface: str, parameter: str): + """Unset a parameter in /e/n/i.""" + _remove_one(iface, _ENI_MAPPING[parameter]) -def unset_desc(iface: str, _): - """Unset the description for the specified interface.""" - _remove_one(iface, 'netconf-description') - -def get_auto(iface: str, _): - """Retrieve whether the interface is auto or not.""" - return _find_one(iface, 'auto') +def set_desc(iface: str, _, value: str): + """Set the description for the specified interface.""" + _replace_one(iface, 'netconf-description', value) def live_enabled(iface: str, _): @@ -205,18 +204,13 @@ def live_enabled(iface: str, _): def set_auto(iface: str, _, value: bool): """Set the auto flag for the specified interface.""" - _replace_one(iface, 'auto', value) - - -def unset_auto(iface: str, _): - """Unset the auto flag for the specified interface.""" - _remove_one(iface, 'auto') + _replace_one(iface, 'auto', str(value).lower()) _PARAMETERS = { # "name": (getter, live getter, setter, unsetter) - "description": (get_desc, get_desc, set_desc, unset_desc), - "enabled": (get_auto, live_enabled, set_auto, unset_auto) + "description": (get_one_eni, get_one_eni, set_desc, unset_one_eni), + "enabled": (get_one_eni, live_enabled, set_auto, unset_one_eni) } """Describes all supported parameters and their methods.""" -- cgit v1.2.3-70-g09d2