Révision aa8f1a59
kvm_net: fix python code style issues
| plugins/libvirt/kvm_net | ||
|---|---|---|
| 32 | 32 |
=cut |
| 33 | 33 |
""" |
| 34 | 34 |
|
| 35 |
import re, os, sys |
|
| 35 |
import os |
|
| 36 |
import re |
|
| 36 | 37 |
from subprocess import Popen, PIPE |
| 38 |
import sys |
|
| 37 | 39 |
|
| 38 | 40 |
|
| 39 | 41 |
def config(vm_names): |
| ... | ... | |
| 78 | 80 |
|
| 79 | 81 |
@param dictionnary {kvm_pid: cleaned vm name}
|
| 80 | 82 |
""" |
| 81 |
res = {}
|
|
| 82 | 83 |
for pid in vms: |
| 83 | 84 |
tap = get_vm_mac(pid) |
| 84 | 85 |
try: |
| ... | ... | |
| 105 | 106 |
|
| 106 | 107 |
@return a dictionnary of {pids : cleaned vm name}
|
| 107 | 108 |
""" |
| 109 |
vm_name_regex = re.compile(r"^.*-name\x00([a-zA-Z0-9.-_-]*)\x00\-.*$") |
|
| 108 | 110 |
result = {}
|
| 109 | 111 |
for pid in pids: |
| 110 | 112 |
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
| 111 |
result[pid] = clean_vm_name(re.sub(r"^.*-name\x00([a-zA-Z0-9.-_-]*)\x00\-.*$",r"\1", cmdline.readline()))
|
|
| 113 |
result[pid] = clean_vm_name(vm_name_regex.sub(r"\1", cmdline.readline()))
|
|
| 112 | 114 |
return result |
| 113 | 115 |
|
| 114 | 116 |
|
| ... | ... | |
| 119 | 121 |
""" |
| 120 | 122 |
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
| 121 | 123 |
line = cmdline.readline() |
| 122 |
mac = re.sub(r"^.*ifname=(tap[^,]+),.*$",r"\1", line) |
|
| 124 |
mac = re.sub(r"^.*ifname=(tap[^,]+),.*$", r"\1", line)
|
|
| 123 | 125 |
return mac |
| 124 | 126 |
|
| 125 | 127 |
|
Formats disponibles : Unified diff