diff --git a/plugins/libvirt/kvm_net b/plugins/libvirt/kvm_net index 6bf14553..40c78468 100755 --- a/plugins/libvirt/kvm_net +++ b/plugins/libvirt/kvm_net @@ -18,6 +18,7 @@ import re, os, sys from subprocess import Popen, PIPE + def config(vm_names): """ Print the plugin's config @@ -41,6 +42,7 @@ graph_args --base 1024 print "%s_out.min 0" % vm print "%s_out.draw LINE2" % vm + def clean_vm_name(vm_name): """ Replace all special chars @@ -51,9 +53,9 @@ def clean_vm_name(vm_name): suffix = os.getenv("vmsuffix") if suffix: vm_name = re.sub(suffix, "", vm_name) - return re.sub(r"[^a-zA-Z0-9_]", "_", vm_name) - + + def fetch(vms): """ Fetch values for a list of pids @@ -73,12 +75,14 @@ def fetch(vms): print inst continue + def detect_kvm(): """ Check if kvm is installed """ kvm = Popen("which kvm", shell=True, stdout=PIPE) kvm.communicate() return not bool(kvm.returncode) + def find_vm_names(pids): """Find and clean vm names from pids @@ -87,9 +91,10 @@ def find_vm_names(pids): 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(re.sub(r"^.*-name\x00([a-zA-Z0-9.-_-]*)\x00\-.*$",r"\1", cmdline.readline())) return result - + + def get_vm_mac(pid): """Find and clean vm names from pids @@ -100,6 +105,7 @@ def get_vm_mac(pid): mac = re.sub(r"^.*ifname=(tap[^,]+),.*$",r"\1", line) return mac + def list_pids(): """ Find the pid of kvm processes @@ -122,5 +128,3 @@ if __name__ == "__main__": fetch(find_vm_names(list_pids())) else: fetch(find_vm_names(list_pids())) - -