def vm_ip(name, id):
"""
Return a running VMs IP for the given VM name and interface id,
returns None if not running or the id does not exists
:param name: str
:param id: int
:return: None|str
"""
try:
prop = '/VirtualBox/GuestInfo/Net/%d/V4/IP' % (id)
value = str(VBoxManage('guestproperty', 'get',
name, prop))
if value == 'No value set!':
return None
return value[7:].strip()
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
评论列表
文章目录