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