Wizard in virtual mode uses libvirt's DHCPLeases() method to check if the lease table contains guest libvirt domain name. Unfortunately the hostname key is not the libvirt guest's name but really a hostname. So unless a user has a mapping in /etc/hosts the current approach won't work and the hostname contains 'None'. The solution is to get guest's XML and based on the interface data there search the entry in the lease table provided by DHCPLeases().
Fixes issue #156
Signed-off-by: Jan Tluka jtluka@redhat.com --- lnst/Controller/Wizard.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/lnst/Controller/Wizard.py b/lnst/Controller/Wizard.py index ddd461a..562efe1 100644 --- a/lnst/Controller/Wizard.py +++ b/lnst/Controller/Wizard.py @@ -22,6 +22,7 @@ from lnst.Common.Utils import mkdir_p, check_process_running from lnst.Common.Config import DefaultRPCPort from lnst.Common.ConnectionHandler import send_data, recv_data from xml.dom.minidom import getDOMImplementation +from lxml import etree
DefaultPoolDir = os.path.expanduser("~/.lnst/pool/") PATH_IS_DIR_ACCESSIBLE = 0 @@ -416,20 +417,31 @@ class Wizard: sys.stderr.write("No domain entered\n") continue try: - conn.lookupByName(libvirt_domain) + guest = conn.lookupByName(libvirt_domain) except: continue
- # when libvirtd is old + guestxml = etree.fromstring(guest.XMLDesc()) + + macs = list() + for mac in guestxml.findall(".//interface/source[@network='default']/../mac"): + macs.append(mac.get('address')) + + guest_ip = None try: for lease in conn.networkLookupByName("default").DHCPLeases(): - if lease["hostname"] == libvirt_domain: - return (libvirt_domain, lease["ipaddr"]) + if lease['mac'] in macs: + guest_ip = lease['ipaddr'] + break except: sys.stderr.write("Failed getting DHCPLeases from hypervisor\n")
- sys.stderr.write("Couldn't find any IP associated with " - "libvirt_domain '%s'\n" % libvirt_domain) + if guest_ip == None: + sys.stderr.write("Couldn't find any IP associated with " + "libvirt_domain '%s'\n" % libvirt_domain) + else: + return libvirt_domain, lease['ipaddr'] + hostname = self._query_hostname() return libvirt_domain, hostname
2015-12-08 11:38 GMT+01:00 Jan Tluka jtluka@redhat.com:
Wizard in virtual mode uses libvirt's DHCPLeases() method to check if the lease table contains guest libvirt domain name. Unfortunately the hostname key is not the libvirt guest's name but really a hostname. So unless a user has a mapping in /etc/hosts the current approach won't work and the hostname contains 'None'. The solution is to get guest's XML and based on the interface data there search the entry in the lease table provided by DHCPLeases().
Fixes issue #156
Signed-off-by: Jan Tluka jtluka@redhat.com
lnst/Controller/Wizard.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/lnst/Controller/Wizard.py b/lnst/Controller/Wizard.py index ddd461a..562efe1 100644 --- a/lnst/Controller/Wizard.py +++ b/lnst/Controller/Wizard.py @@ -22,6 +22,7 @@ from lnst.Common.Utils import mkdir_p, check_process_running from lnst.Common.Config import DefaultRPCPort from lnst.Common.ConnectionHandler import send_data, recv_data from xml.dom.minidom import getDOMImplementation +from lxml import etree
DefaultPoolDir = os.path.expanduser("~/.lnst/pool/") PATH_IS_DIR_ACCESSIBLE = 0 @@ -416,20 +417,31 @@ class Wizard: sys.stderr.write("No domain entered\n") continue try:
conn.lookupByName(libvirt_domain)
guest = conn.lookupByName(libvirt_domain) except: continue
# when libvirtd is old
guestxml = etree.fromstring(guest.XMLDesc())
macs = list()
for mac in
guestxml.findall(".//interface/source[@network='default']/../mac"):
macs.append(mac.get('address'))
guest_ip = None try: for lease in
conn.networkLookupByName("default").DHCPLeases():
if lease["hostname"] == libvirt_domain:
return (libvirt_domain, lease["ipaddr"])
if lease['mac'] in macs:
guest_ip = lease['ipaddr']
break except: sys.stderr.write("Failed getting DHCPLeases from
hypervisor\n")
sys.stderr.write("Couldn't find any IP associated with "
"libvirt_domain '%s'\n" % libvirt_domain)
if guest_ip == None:
sys.stderr.write("Couldn't find any IP associated with "
"libvirt_domain '%s'\n" % libvirt_domain)
else:
return libvirt_domain, lease['ipaddr']
hostname = self._query_hostname() return libvirt_domain, hostname
-- 2.4.3 _______________________________________________ LNST-developers mailing list lnst-developers@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/lnst-developers@lists.fedorahoste...
Acked-by: Jiri Prochazka jprochaz@redhat.com
On Tue, Dec 08, 2015 at 11:38:59AM +0100, Jan Tluka wrote:
Wizard in virtual mode uses libvirt's DHCPLeases() method to check if the lease table contains guest libvirt domain name. Unfortunately the hostname key is not the libvirt guest's name but really a hostname. So unless a user has a mapping in /etc/hosts the current approach won't work and the hostname contains 'None'. The solution is to get guest's XML and based on the interface data there search the entry in the lease table provided by DHCPLeases().
Fixes issue #156
Signed-off-by: Jan Tluka jtluka@redhat.com
Acked-by: Ondrej Lichtner olichtne@redhat.com
lnst-developers@lists.fedorahosted.org