summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-11-18 14:28:32 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-11-18 14:28:32 -0600
commitd1ef363d806a2d67ab0ed0c99ee20e8028c11f75 (patch)
tree7f7ba0560e75e7b1103cea38c5b053bb468997d6
parent557adae9056c81247e713ad4fb133c24db6e8b7f (diff)
downloadnetconfapk-d1ef363d806a2d67ab0ed0c99ee20e8028c11f75.tar.gz
netconfapk-d1ef363d806a2d67ab0ed0c99ee20e8028c11f75.tar.bz2
netconfapk-d1ef363d806a2d67ab0ed0c99ee20e8028c11f75.tar.xz
netconfapk-d1ef363d806a2d67ab0ed0c99ee20e8028c11f75.zip
ncserver: Style improvements
-rw-r--r--ncserver/module/interfaces.py12
-rw-r--r--ncserver/module/nms_ifupdownng.py9
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