From aa8f1a59c4dbbed02f470718aafcae11d0c66f19 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Sun, 10 Jun 2018 17:44:22 +0200 Subject: [PATCH] kvm_net: fix python code style issues --- plugins/libvirt/kvm_net | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/libvirt/kvm_net b/plugins/libvirt/kvm_net index e464b6ed..e03794ba 100755 --- a/plugins/libvirt/kvm_net +++ b/plugins/libvirt/kvm_net @@ -32,8 +32,10 @@ GPLv3 =cut """ -import re, os, sys +import os +import re from subprocess import Popen, PIPE +import sys def config(vm_names): @@ -78,7 +80,6 @@ def fetch(vms): @param dictionnary {kvm_pid: cleaned vm name} """ - res = {} for pid in vms: tap = get_vm_mac(pid) try: @@ -105,10 +106,11 @@ def find_vm_names(pids): @return a dictionnary of {pids : cleaned vm name} """ + vm_name_regex = re.compile(r"^.*-name\x00([a-zA-Z0-9.-_-]*)\x00\-.*$") result = {} for pid in pids: cmdline = open("/proc/%s/cmdline" % pid, "r") - result[pid] = clean_vm_name(re.sub(r"^.*-name\x00([a-zA-Z0-9.-_-]*)\x00\-.*$",r"\1", cmdline.readline())) + result[pid] = clean_vm_name(vm_name_regex.sub(r"\1", cmdline.readline())) return result @@ -119,7 +121,7 @@ def get_vm_mac(pid): """ cmdline = open("/proc/%s/cmdline" % pid, "r") line = cmdline.readline() - mac = re.sub(r"^.*ifname=(tap[^,]+),.*$",r"\1", line) + mac = re.sub(r"^.*ifname=(tap[^,]+),.*$", r"\1", line) return mac