summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-11-20 11:47:35 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-11-20 11:47:35 -0600
commit79444d36e07d2e43697fe6b35d8870a371062690 (patch)
tree0ee2cb7ab90b6564e8f8633ec52b344ad511b579
parent0fb6a466f8fd7a292bb840245da1c13ea1cbe836 (diff)
downloadnetconfapk-79444d36e07d2e43697fe6b35d8870a371062690.tar.gz
netconfapk-79444d36e07d2e43697fe6b35d8870a371062690.tar.bz2
netconfapk-79444d36e07d2e43697fe6b35d8870a371062690.tar.xz
netconfapk-79444d36e07d2e43697fe6b35d8870a371062690.zip
ifupdown-ng NMSA: Factor common methods into one
-rw-r--r--ncserver/module/nms_ifupdownng.py36
1 files 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."""