2013-03-18 01:06:52 +04:00
#
2013-10-28 00:59:46 +04:00
# Copyright 2009, 2013 Red Hat, Inc.
2013-03-18 01:06:52 +04:00
#
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-03-18 01:06:52 +04:00
"""
Classes for building and installing libvirt interface xml
"""
2014-09-12 23:59:22 +04:00
from . xmlbuilder import XMLBuilder , XMLChildProperty , XMLProperty
2013-09-10 01:14:16 +04:00
2018-03-21 17:49:29 +03:00
class _BondConfig ( XMLBuilder ) :
2018-03-21 17:53:34 +03:00
XML_NAME = " bond "
2018-03-21 17:49:29 +03:00
class _BridgeConfig ( XMLBuilder ) :
2018-03-21 17:53:34 +03:00
XML_NAME = " bridge "
2018-03-21 17:49:29 +03:00
class _VLANConfig ( XMLBuilder ) :
2018-03-21 17:53:34 +03:00
XML_NAME = " vlan "
2018-03-21 17:49:29 +03:00
2013-09-10 01:14:16 +04:00
class Interface ( XMLBuilder ) :
2013-03-18 01:06:52 +04:00
"""
2019-05-04 19:06:25 +03:00
Base class for parsing any libvirt virInterface object XML
2013-03-18 01:06:52 +04:00
"""
2018-03-21 17:53:34 +03:00
XML_NAME = " interface "
2019-05-04 19:06:25 +03:00
_XML_PROP_ORDER = [ " type " , " name " , " _bond " , " _bridge " , " _vlan " ]
2013-09-10 01:14:16 +04:00
2018-03-21 17:49:29 +03:00
######################
# Interface handling #
######################
# The recursive nature of nested interfaces complicates things here,
# which is why this is strange. See bottom of the file for more
# weirdness
_bond = XMLChildProperty ( _BondConfig , is_single = True )
_bridge = XMLChildProperty ( _BridgeConfig , is_single = True )
_vlan = XMLChildProperty ( _VLANConfig , is_single = True )
2013-09-10 01:14:16 +04:00
2018-03-21 17:49:29 +03:00
@property
def interfaces ( self ) :
if self . type != " ethernet " :
return getattr ( self , " _ " + self . type ) . interfaces
return [ ]
2013-09-10 01:14:16 +04:00
##################
# General params #
##################
type = XMLProperty ( " ./@type " )
2018-09-03 22:45:26 +03:00
name = XMLProperty ( " ./@name " )
2013-03-18 01:06:52 +04:00
2018-03-21 17:49:29 +03:00
# Interface can recursively have child interfaces which we can't define
# inline in the class config, hence this hackery
_BondConfig . interfaces = XMLChildProperty ( Interface )
_BridgeConfig . interfaces = XMLChildProperty ( Interface )
_VLANConfig . interfaces = XMLChildProperty ( Interface )