2013-09-20 20:40:07 -04:00
#
# Copyright 2013 Red Hat, Inc.
#
2018-04-04 14:35:41 +01:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 15:00:02 -04:00
# See the COPYING file in the top-level directory.
2013-09-20 20:40:07 -04:00
"""
Classes for building and installing libvirt < network > XML
"""
2014-09-12 15:59:22 -04:00
from . xmlbuilder import XMLBuilder , XMLChildProperty , XMLProperty
2013-09-20 20:40:07 -04:00
class _NetworkDHCPRange ( XMLBuilder ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " range "
2013-09-20 20:40:07 -04:00
start = XMLProperty ( " ./@start " )
end = XMLProperty ( " ./@end " )
class _NetworkDHCPHost ( XMLBuilder ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " host "
2013-09-20 20:40:07 -04:00
macaddr = XMLProperty ( " ./@mac " )
name = XMLProperty ( " ./@name " )
ip = XMLProperty ( " ./@ip " )
class _NetworkIP ( XMLBuilder ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " ip "
2013-09-20 20:40:07 -04:00
family = XMLProperty ( " ./@family " )
address = XMLProperty ( " ./@address " )
prefix = XMLProperty ( " ./@prefix " , is_int = True )
netmask = XMLProperty ( " ./@netmask " )
tftp = XMLProperty ( " ./tftp/@root " )
bootp_file = XMLProperty ( " ./dhcp/bootp/@file " )
bootp_server = XMLProperty ( " ./dhcp/bootp/@server " )
ranges = XMLChildProperty ( _NetworkDHCPRange , relative_xpath = " ./dhcp " )
hosts = XMLChildProperty ( _NetworkDHCPHost , relative_xpath = " ./dhcp " )
class _NetworkRoute ( XMLBuilder ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " route "
2013-09-20 20:40:07 -04:00
family = XMLProperty ( " ./@family " )
address = XMLProperty ( " ./@address " )
prefix = XMLProperty ( " ./@prefix " , is_int = True )
gateway = XMLProperty ( " ./@gateway " )
2013-09-23 09:10:43 -04:00
netmask = XMLProperty ( " ./@netmask " )
2013-09-20 20:40:07 -04:00
2017-03-31 20:12:00 +08:00
class _NetworkForwardPf ( XMLBuilder ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " pf "
2017-03-31 20:12:00 +08:00
dev = XMLProperty ( " ./@dev " )
2017-09-22 19:39:09 +08:00
class _NetworkForwardAddress ( XMLBuilder ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " address "
2017-09-22 19:39:09 +08:00
type = XMLProperty ( " ./@type " )
domain = XMLProperty ( " ./@domain " , is_int = True )
bus = XMLProperty ( " ./@bus " , is_int = True )
slot = XMLProperty ( " ./@slot " , is_int = True )
function = XMLProperty ( " ./@function " , is_int = True )
2013-09-20 20:40:07 -04:00
class _NetworkForward ( XMLBuilder ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " forward "
2013-09-20 20:40:07 -04:00
mode = XMLProperty ( " ./@mode " )
dev = XMLProperty ( " ./@dev " )
2017-03-31 20:12:00 +08:00
managed = XMLProperty ( " ./@managed " )
pf = XMLChildProperty ( _NetworkForwardPf )
2017-09-22 19:39:09 +08:00
vfs = XMLChildProperty ( _NetworkForwardAddress )
2017-03-31 20:12:00 +08:00
2013-09-20 20:40:07 -04:00
2014-06-25 12:27:00 +02:00
class _NetworkBandwidth ( XMLBuilder ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " bandwidth "
2014-06-25 12:27:00 +02:00
inbound_average = XMLProperty ( " ./inbound/@average " )
inbound_peak = XMLProperty ( " ./inbound/@peak " )
inbound_burst = XMLProperty ( " ./inbound/@burst " )
inbound_floor = XMLProperty ( " ./inbound/@floor " )
outbound_average = XMLProperty ( " ./outbound/@average " )
outbound_peak = XMLProperty ( " ./outbound/@peak " )
outbound_burst = XMLProperty ( " ./outbound/@burst " )
2014-05-31 14:20:56 -04:00
class _NetworkPortgroup ( XMLBuilder ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " portgroup "
2014-05-31 14:20:56 -04:00
name = XMLProperty ( " ./@name " )
default = XMLProperty ( " ./@default " , is_yesno = True )
2013-09-20 20:40:07 -04:00
class Network ( XMLBuilder ) :
"""
Top level class for < network > object XML
"""
2018-03-21 10:53:34 -04:00
XML_NAME = " network "
2017-03-23 16:06:56 +01:00
_XML_PROP_ORDER = [ " ipv6 " , " name " , " uuid " , " forward " , " virtualport_type " ,
2013-09-20 20:40:07 -04:00
" bridge " , " stp " , " delay " , " domain_name " ,
2014-06-25 12:27:00 +02:00
" macaddr " , " ips " , " routes " , " bandwidth " ]
2013-09-20 20:40:07 -04:00
ipv6 = XMLProperty ( " ./@ipv6 " , is_yesno = True )
2018-09-03 15:45:26 -04:00
name = XMLProperty ( " ./name " )
2017-12-14 12:10:28 -05:00
uuid = XMLProperty ( " ./uuid " )
2013-09-20 20:40:07 -04:00
2017-03-23 16:06:56 +01:00
virtualport_type = XMLProperty ( " ./virtualport/@type " )
2013-09-20 20:40:07 -04:00
# Not entirely correct, there can be multiple routes
forward = XMLChildProperty ( _NetworkForward , is_single = True )
domain_name = XMLProperty ( " ./domain/@name " )
bridge = XMLProperty ( " ./bridge/@name " )
stp = XMLProperty ( " ./bridge/@stp " , is_onoff = True )
delay = XMLProperty ( " ./bridge/@delay " , is_int = True )
macaddr = XMLProperty ( " ./mac/@address " )
2014-05-31 14:20:56 -04:00
portgroups = XMLChildProperty ( _NetworkPortgroup )
2013-09-20 20:40:07 -04:00
ips = XMLChildProperty ( _NetworkIP )
routes = XMLChildProperty ( _NetworkRoute )
2014-06-25 12:27:00 +02:00
bandwidth = XMLChildProperty ( _NetworkBandwidth , is_single = True )
2013-09-20 20:40:07 -04:00
2014-05-31 14:20:56 -04:00
2019-06-09 15:29:44 -04:00
###################
# Helper routines #
###################
2013-09-30 15:06:52 -04:00
2019-06-09 15:29:44 -04:00
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