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