network: Centralize pxe support check

This commit is contained in:
Cole Robinson 2013-09-22 17:04:22 -04:00
parent 6da801f944
commit e9b8a289b5
3 changed files with 17 additions and 14 deletions

View File

@ -33,7 +33,6 @@ import urlgrabber.progress as progress
import virtinst
import virtinst.cli as cli
import virtinst.util as util
from virtinst.cli import fail, print_stdout, print_stderr
@ -82,12 +81,9 @@ def supports_pxe(guest):
return True
try:
xml = nic.conn.networkLookupByName(nic.network).XMLDesc(0)
if util.xpath(xml, "/network/ip/dhcp/bootp/@file"):
return True
forward = util.xpath(xml, "/network/forward/@mode")
if forward and forward != "nat":
netobj = nic.conn.networkLookupByName(nic.network)
xmlobj = virtinst.Network(nic.conn, parsexml=netobj.XMLDesc(0))
if xmlobj.can_pxe():
return True
except:
logging.debug("Error checking if PXE supported", exc_info=True)

View File

@ -126,13 +126,7 @@ class vmmNetwork(vmmLibvirtObject):
return self._get_xmlobj().forward.pretty_desc()
def can_pxe(self):
forward = self.get_ipv4_forward_mode()
if forward and forward != "nat":
return True
for ip in self._get_xmlobj().ips:
if ip.bootp_file:
return True
return False
return self._get_xmlobj().can_pxe()
def _get_static_route(self, family):
xmlobj = self._get_xmlobj()

View File

@ -106,6 +106,19 @@ class Network(XMLBuilder):
self._random_uuid = None
###################
# Helper routines #
###################
def can_pxe(self):
forward = self.forward.mode
if forward and forward != "nat":
return True
for ip in self.ips:
if ip.bootp_file:
return True
return False
######################
# Validation helpers #
######################