def vm_network(name):
"""
Return IP, Mac, Netmask, Broadcast and Status about every interfaces
of a running VM
:param name: str
:return: list[dict[str,str]]
"""
try:
networks = []
count = int(str(VBoxManage('guestproperty', 'get',
name, '/VirtualBox/GuestInfo/Net/Count'))[7:])
mappings = {
'ip': '/VirtualBox/GuestInfo/Net/%d/V4/IP',
'mac': '/VirtualBox/GuestInfo/Net/%d/MAC',
'netmask': '/VirtualBox/GuestInfo/Net/%d/V4/Netmask',
'status': '/VirtualBox/GuestInfo/Net/%d/Status',
'broadcast': '/VirtualBox/GuestInfo/Net/%d/V4/Broadcast'
}
for i in range(count):
network = {}
for map, property in mappings.iteritems():
prop = VBoxManage('guestproperty', 'get', name, property % i)
network[map] = str(prop)[7:].strip()
networks.append(network)
return networks
except ErrorReturnCode_1 as e:
# if the VM was not found
if 'VBOX_E_OBJECT_NOT_FOUND' in e.stderr:
raise VMNotFound(name)
# something else happened, just let it go
raise
评论列表
文章目录