diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-11-19 13:32:59 -0600 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2020-11-19 13:32:59 -0600 |
commit | 7feaea9553a81ef24931b804226881774f7d61cf (patch) | |
tree | 6c5b2cce5dbee2fd3b35f200fbf59a1309036f90 /ncserver | |
parent | a8c7c3fbf37a9eedc96e63d3a946c3a795006f30 (diff) | |
download | netconfapk-7feaea9553a81ef24931b804226881774f7d61cf.tar.gz netconfapk-7feaea9553a81ef24931b804226881774f7d61cf.tar.bz2 netconfapk-7feaea9553a81ef24931b804226881774f7d61cf.tar.xz netconfapk-7feaea9553a81ef24931b804226881774f7d61cf.zip |
ifupdown-ng NMSA: Make all keys case-insensitive
Diffstat (limited to 'ncserver')
-rw-r--r-- | ncserver/module/nms_ifupdownng.py | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/ncserver/module/nms_ifupdownng.py b/ncserver/module/nms_ifupdownng.py index b4e1c1f..70fadd9 100644 --- a/ncserver/module/nms_ifupdownng.py +++ b/ncserver/module/nms_ifupdownng.py @@ -88,7 +88,7 @@ def _save_unlocked(): buf = "iface " + iface + "\n" for item in _CONFIG[iface]: for key, val in item.items(): - if key == 'auto' and \ + if key.casefold() == 'auto'.casefold() and \ (val is True or val.lower()[0] == 't'): buf = "auto " + iface + "\n" + buf continue @@ -118,8 +118,9 @@ def _find_one(iface: str, key: str): return None for item in _CONFIG[iface]: - if key in item.keys(): - return item[key] + for candidate in item.keys(): + if key.casefold() == candidate.casefold(): + return item[candidate] return None @@ -132,12 +133,39 @@ def _find_many(iface: str, key: str) -> list: return None for item in _CONFIG[iface]: - if key in item.keys(): - ret.append(item[key]) + for candidate in item.keys(): + if key.casefold() == candidate.casefold(): + ret.append(item[candidate]) return ret +def _replace_one(iface: str, key: str, value: str): + """Replace a single instance of +key+ for +iface+ with +value+.""" + iface_cfg = _CONFIG[iface] + for item in iface_cfg: + for candidate in item.keys(): + if key.casefold() == candidate.casefold(): + item[candidate] = value + _save() + return + + iface_cfg.append({key: value}) + _save() + return + + +def _remove_one(iface: str, key: str): + """Remove a single instance of +key+ from +iface+.""" + iface_cfg = _CONFIG[iface] + for item in iface_cfg: + for candidate in item.keys(): + if key.casefold() == candidate.casefold(): + iface_cfg.remove(item) + _save() + return + + ############################# # P A R A M E T E R S # ############################# @@ -145,31 +173,17 @@ def _find_many(iface: str, key: str) -> list: def get_desc(iface: str): """Retrieve the description for the specified interface.""" - return _find_one(iface, "netconf-description") + return _find_one(iface, 'netconf-description') def set_desc(iface: str, value: str): """Set the description for the specified interface.""" - iface_cfg = _CONFIG[iface] - for item in iface_cfg: - if 'netconf-description' in item.keys(): - item['netconf-description'] = value - _save() - return - - iface_cfg.append({'netconf-description': value}) - _save() - return + _replace_one(iface, 'netconf-description', value) def unset_desc(iface: str): """Unset the description for the specified interface.""" - iface_cfg = _CONFIG[iface] - for item in iface_cfg: - if 'netconf-description' in item.keys(): - iface_cfg.remove(item) - _save() - return + _remove_one(iface, 'netconf-description') _PARAMETERS = { |