mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
kvm_net: fix python code style issues
This commit is contained in:
parent
a9059703a6
commit
aa8f1a59c4
@ -32,8 +32,10 @@ GPLv3
|
|||||||
=cut
|
=cut
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re, os, sys
|
import os
|
||||||
|
import re
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def config(vm_names):
|
def config(vm_names):
|
||||||
@ -78,7 +80,6 @@ def fetch(vms):
|
|||||||
|
|
||||||
@param dictionnary {kvm_pid: cleaned vm name}
|
@param dictionnary {kvm_pid: cleaned vm name}
|
||||||
"""
|
"""
|
||||||
res = {}
|
|
||||||
for pid in vms:
|
for pid in vms:
|
||||||
tap = get_vm_mac(pid)
|
tap = get_vm_mac(pid)
|
||||||
try:
|
try:
|
||||||
@ -105,10 +106,11 @@ def find_vm_names(pids):
|
|||||||
|
|
||||||
@return a dictionnary of {pids : cleaned vm name}
|
@return a dictionnary of {pids : cleaned vm name}
|
||||||
"""
|
"""
|
||||||
|
vm_name_regex = re.compile(r"^.*-name\x00([a-zA-Z0-9.-_-]*)\x00\-.*$")
|
||||||
result = {}
|
result = {}
|
||||||
for pid in pids:
|
for pid in pids:
|
||||||
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
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
|
return result
|
||||||
|
|
||||||
|
|
||||||
@ -119,7 +121,7 @@ def get_vm_mac(pid):
|
|||||||
"""
|
"""
|
||||||
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
||||||
line = cmdline.readline()
|
line = cmdline.readline()
|
||||||
mac = re.sub(r"^.*ifname=(tap[^,]+),.*$",r"\1", line)
|
mac = re.sub(r"^.*ifname=(tap[^,]+),.*$", r"\1", line)
|
||||||
return mac
|
return mac
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user