aboutsummaryrefslogtreecommitdiff
path: root/libvirt-ifstat
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2020-03-30 10:08:06 +0200
committerGuido Günther <agx@sigxcpu.org>2020-03-30 10:11:47 +0200
commit1c4a4fb84bf470709541067665dbc232e2c12dd3 (patch)
tree32f9832b73be1f06b48af515d853b259dd28e075 /libvirt-ifstat
parent35be326f61d8cedbd506ed78463fb182a245bc25 (diff)
flake8 cleanups
Diffstat (limited to 'libvirt-ifstat')
-rw-r--r--libvirt-ifstat15
1 files changed, 10 insertions, 5 deletions
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))