From d1ef363d806a2d67ab0ed0c99ee20e8028c11f75 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Wed, 18 Nov 2020 14:28:32 -0600 Subject: ncserver: Style improvements --- ncserver/module/interfaces.py | 12 +++++++----- ncserver/module/nms_ifupdownng.py | 9 ++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ncserver/module/interfaces.py b/ncserver/module/interfaces.py index 959436c..b8f9ad1 100644 --- a/ncserver/module/interfaces.py +++ b/ncserver/module/interfaces.py @@ -93,11 +93,12 @@ def _add_running_contents(ifaces): type_file.close() type_num = type_num.strip() if type_num in types.keys(): + iana_xmlns = "urn:ietf:params:xml:ns:yang:iana-if-type" iface.append(util.leaf_elm('if:type', 'ianaift:'+types[type_num], - nsmap={'ianaift': "urn:ietf:params:xml:ns:yang:iana-if-type"})) + nsmap={'ianaift': iana_xmlns})) else: LOGGER.warning(_('unknown Linux hwtype for %s: %s'), - ifname.name, type_num) + ifname.name, type_num) def running(node): @@ -119,14 +120,15 @@ def _add_stats_to(iface, name: str): stats = util.subelm(iface, 'if:statistics') # XXX BAD vvv - stats.append(util.leaf_elm('if:discontinuity-time', '2020-01-01T01:01:01.011Z')) + stats.append(util.leaf_elm('if:discontinuity-time', + '2020-01-01T01:01:01.011Z')) # XXX BAD ^^^ result = subprocess.run(['/sbin/ifupdown', 'ifctrstat', name], stdout=subprocess.PIPE, check=False) if result.returncode != 0: LOGGER.error(_('ifctrstat failed for %s: %s'), - name, result.returncode) + name, result.returncode) return counters = result.stdout.decode('utf-8').split('\n') @@ -134,7 +136,7 @@ def _add_stats_to(iface, name: str): for counter, value in [data.split(': ') for data in counters]: if counter not in counter_tags.keys(): LOGGER.warning(_('unhandled ifctrstat counter for %s: %s'), - name, counter) + name, counter) continue stats.append(util.leaf_elm(counter_tags[counter], value)) diff --git a/ncserver/module/nms_ifupdownng.py b/ncserver/module/nms_ifupdownng.py index d5d5da8..a05d7cc 100644 --- a/ncserver/module/nms_ifupdownng.py +++ b/ncserver/module/nms_ifupdownng.py @@ -12,6 +12,7 @@ SPDX-License-Identifier: NCSA import ipaddress import logging +import socket import subprocess import yaml @@ -83,7 +84,7 @@ def _save(): for item in _CONFIG[iface]: for key, val in item.items(): if key == 'auto' and \ - val == True or val.lower()[0] == 't': + (val is True or val.lower()[0] == 't'): buf = "auto " + iface + "\n" + buf continue if isinstance(val, bool): @@ -215,10 +216,12 @@ def list_addresses(iface: str) -> list: fallback_prefix = str(net.prefixlen) addrs = _find_many(iface, 'address') + def fixup(addr): if '/' not in addr: addr = addr + "/" + fallback_prefix return addr + return list(map(fixup, addrs)) @@ -232,6 +235,10 @@ def add_address(iface: str, _type, addr: str, prefix): ) return + if _type not in (socket.AF_INET, socket.AF_INET6): + LOGGER.error(_("unknown address type %r"), _type) + return + # implement this. raise NotImplementedError -- cgit v1.2.3-70-g09d2