From 1c4a4fb84bf470709541067665dbc232e2c12dd3 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Mon, 30 Mar 2020 10:08:06 +0200 Subject: flake8 cleanups --- libvirt-ifstat | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'libvirt-ifstat') diff --git a/libvirt-ifstat b/libvirt-ifstat index c9ff082..1561c6a 100644 --- a/libvirt-ifstat +++ b/libvirt-ifstat @@ -17,9 +17,11 @@ import re, sys, os import libvirt import libxml2 + def canon(name): return re.sub(r"[^a-zA-Z0-9_]", "_", name) + def print_config(uri): """print the plugin config, determine the domains""" @@ -50,12 +52,13 @@ graph_info This graph shows the network I/O of the virtual machines""") print("%s_tx.negative %s_rx" % (canon(name), canon(name))) print("%s_tx.draw LINE1" % canon(name)) + def get_ifaces(dom): xml = dom.XMLDesc(0) doc = None try: doc = libxml2.parseDoc(xml) - except: + except Exception: return [] ctx = doc.xpathNewContext() ifaces = [] @@ -66,16 +69,17 @@ def get_ifaces(dom): for child in node.children: if child.name == "target": devdst = child.prop("dev") - if devdst == None: + if devdst is None: continue ifaces.append(devdst) finally: - if ctx != None: + if ctx is not None: ctx.xpathFreeContext() - if doc != None: + if doc is not None: doc.freeDoc() return ifaces + def fetch_values(uri): conn = libvirt.openReadOnly(uri) ids = conn.listDomainsID() @@ -106,7 +110,7 @@ def main(sys): uri = os.getenv("uri", "qemu:///system") if len(sys) > 1: - if sys[1] in [ 'autoconf', 'detect' ]: + if sys[1] in ['autoconf', 'detect']: if libvirt.openReadOnly(uri): print("yes") return 0 @@ -119,6 +123,7 @@ def main(sys): fetch_values(uri) return 0 + if __name__ == "__main__": sys.exit(main(sys.argv)) -- cgit v1.2.3