-
Notifications
You must be signed in to change notification settings - Fork 1
/
guest.py
42 lines (32 loc) · 1.08 KB
/
guest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from lxml import etree
import arp
import perf_wrapper
class Guest:
def __init__(self, domain, pid):
self.domain = domain
self.pid = pid
self.desc = None
self.perf = perf_wrapper.Perf(pid)
def get_domain(self):
return self.domain
def get_name(self):
return self.domain.name()
def get_pid(self):
return self.pid
def get_mac(self):
return self.get_xml_desc().find("devices/interface[@type='network']/mac").attrib["address"].lower().strip()
def get_ip(self):
return arp.mac_to_ip(self.get_mac())
def get_target_devices(self, device_name):
result = []
for target in self.get_xml_desc().findall("devices/" + device_name + "/target"):
device = target.get("dev")
if not device in result:
result.append(device)
return result
def get_xml_desc(self):
if self.desc is None:
self.refresh_xml_desc()
return self.desc
def refresh_xml_desc(self):
self.desc = etree.fromstring(self.domain.XMLDesc(0))