Skip to content

Commit

Permalink
network_xml:Update outdated marshal functions to fix error
Browse files Browse the repository at this point in the history
Signed-off-by: Haijiao Zhao <[email protected]>
  • Loading branch information
chloerh committed Feb 21, 2023
1 parent 3a2402b commit 88d51bd
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions virttest/libvirt_xml/network_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

import logging
import six

from virttest import xml_utils
from virttest.libvirt_xml import base, xcepts, accessors
Expand Down Expand Up @@ -245,30 +244,35 @@ def __init__(self, virsh_instance=base.virsh):
tag_name='host', attribute='ip')
accessors.XMLElementList('hostnames', self, parent_xpath='/',
marshal_from=self.marshal_from_hostname,
marshal_to=self.marshal_to_hostname)
marshal_to=self.marshal_to_hostname,
has_subclass=True)
super(DNSXML.HostXML, self).__init__(virsh_instance=virsh_instance)
self.xml = '<host/>'

@staticmethod
def marshal_from_hostname(item, index, libvirtxml):
"""Convert a HostnameXML instance into a tag + attributes"""
del index # not used
del libvirtxml # not used
if isinstance(item, six.string_types):
return ("hostname", {}, item)
"""
Convert an HostnameXML object to hostname tag and xml element.
"""
if isinstance(item, DNSXML.HostnameXML):
return 'hostname', item
elif isinstance(item, str):
hostname = DNSXML.HostnameXML()
hostname.hostname = item
return 'hostname', hostname
else:
raise xcepts.LibvirtXMLError("Expected a str attributes,"
" not a %s" % str(item))
raise xcepts.LibvirtXMLError("Expected a list of HostnameXML "
"instances, not a %s" % str(item))

@staticmethod
def marshal_to_hostname(tag, attr, index, libvirtxml, text):
"""Convert a tag + attributes into a HostnameXML instance"""
del attr # not used
del index # not used
def marshal_to_hostname(tag, new_treefile, index, libvirtxml):
"""
Convert a hostname tag xml element to an object of hostnameXML.
"""
if tag != 'hostname':
return None # Don't convert this item
return None # Don't convert this item
newone = DNSXML.HostnameXML(virsh_instance=libvirtxml.virsh)
newone.hostname = text
newone.xmltreefile = new_treefile
return newone

def new_host(self, **dargs):
Expand Down

0 comments on commit 88d51bd

Please sign in to comment.