2013-09-21 04:40:07 +04:00
#
# Copyright 2013 Red Hat, Inc.
#
2018-04-04 16:35:41 +03:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 22:00:02 +03:00
# See the COPYING file in the top-level directory.
2013-09-21 04:40:07 +04:00
"""
Classes for building and installing libvirt < network > XML
"""
2014-09-12 23:59:22 +04:00
from . xmlbuilder import XMLBuilder , XMLChildProperty , XMLProperty
2013-09-21 04:40:07 +04:00
class _NetworkDHCPRange ( XMLBuilder ) :
2018-03-21 17:53:34 +03:00
XML_NAME = " range "
2013-09-21 04:40:07 +04:00
start = XMLProperty ( " ./@start " )
end = XMLProperty ( " ./@end " )
class _NetworkDHCPHost ( XMLBuilder ) :
2018-03-21 17:53:34 +03:00
XML_NAME = " host "
2013-09-21 04:40:07 +04:00
macaddr = XMLProperty ( " ./@mac " )
name = XMLProperty ( " ./@name " )
ip = XMLProperty ( " ./@ip " )
class _NetworkIP ( XMLBuilder ) :
2018-03-21 17:53:34 +03:00
XML_NAME = " ip "
2013-09-21 04: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 17:53:34 +03:00
XML_NAME = " route "
2013-09-21 04:40:07 +04:00
family = XMLProperty ( " ./@family " )
address = XMLProperty ( " ./@address " )
prefix = XMLProperty ( " ./@prefix " , is_int = True )
gateway = XMLProperty ( " ./@gateway " )
2013-09-23 17:10:43 +04:00
netmask = XMLProperty ( " ./@netmask " )
2013-09-21 04:40:07 +04:00
2017-03-31 15:12:00 +03:00
class _NetworkForwardPf ( XMLBuilder ) :
2018-03-21 17:53:34 +03:00
XML_NAME = " pf "
2017-03-31 15:12:00 +03:00
dev = XMLProperty ( " ./@dev " )
2013-09-21 04:40:07 +04:00
class _NetworkForward ( XMLBuilder ) :
2018-03-21 17:53:34 +03:00
XML_NAME = " forward "
2013-09-21 04:40:07 +04:00
mode = XMLProperty ( " ./@mode " )
dev = XMLProperty ( " ./@dev " )
2017-03-31 15:12:00 +03:00
managed = XMLProperty ( " ./@managed " )
pf = XMLChildProperty ( _NetworkForwardPf )
2013-09-21 04:40:07 +04:00
2014-05-31 22:20:56 +04:00
class _NetworkPortgroup ( XMLBuilder ) :
2018-03-21 17:53:34 +03:00
XML_NAME = " portgroup "
2014-05-31 22:20:56 +04:00
name = XMLProperty ( " ./@name " )
default = XMLProperty ( " ./@default " , is_yesno = True )
2013-09-21 04:40:07 +04:00
class Network ( XMLBuilder ) :
"""
Top level class for < network > object XML
"""
2018-03-21 17:53:34 +03:00
XML_NAME = " network "
2017-03-23 18:06:56 +03:00
_XML_PROP_ORDER = [ " ipv6 " , " name " , " uuid " , " forward " , " virtualport_type " ,
2013-09-21 04:40:07 +04:00
" bridge " , " stp " , " delay " , " domain_name " ,
2019-06-17 03:25:42 +03:00
" macaddr " , " ips " , " routes " ]
2013-09-21 04:40:07 +04:00
ipv6 = XMLProperty ( " ./@ipv6 " , is_yesno = True )
2018-09-03 22:45:26 +03:00
name = XMLProperty ( " ./name " )
2017-12-14 20:10:28 +03:00
uuid = XMLProperty ( " ./uuid " )
2013-09-21 04:40:07 +04:00
2017-03-23 18:06:56 +03:00
virtualport_type = XMLProperty ( " ./virtualport/@type " )
2013-09-21 04: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 22:20:56 +04:00
portgroups = XMLChildProperty ( _NetworkPortgroup )
2013-09-21 04:40:07 +04:00
ips = XMLChildProperty ( _NetworkIP )
routes = XMLChildProperty ( _NetworkRoute )
2014-05-31 22:20:56 +04:00
2019-06-09 22:29:44 +03:00
###################
# Helper routines #
###################
2013-09-30 23:06:52 +04:00
2019-06-09 22:29:44 +03: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