xmlbuilder: Make _add_child and _remove_child public

We have a lot of functions that are just wrappers around these, so
make it public for future use.
This commit is contained in:
Cole Robinson 2015-09-04 15:45:45 -04:00
parent 5e68b0fc3d
commit acfb988945
9 changed files with 29 additions and 27 deletions

View File

@ -39,7 +39,7 @@ class Clock(XMLBuilder):
def add_timer(self):
obj = _ClockTimer(self.conn)
self._add_child(obj)
self.add_child(obj)
return obj
def remove_timer(self, obj):
self._remove_child(obj)
self.remove_child(obj)

View File

@ -83,9 +83,9 @@ class CPU(XMLBuilder):
feature.name = name
feature.policy = policy
self._add_child(feature)
self.add_child(feature)
def remove_feature(self, feature):
self._remove_child(feature)
self.remove_child(feature)
features = XMLChildProperty(CPUFeature)
def copy_host_cpu(self):

View File

@ -216,7 +216,7 @@ class VirtualGraphics(VirtualDevice):
listens = XMLChildProperty(_GraphicsListen)
def remove_listen(self, obj):
self._remove_child(obj)
self.remove_child(obj)
# Spice bits
image_compression = XMLProperty("./image/@compression")

View File

@ -250,7 +250,7 @@ class Guest(XMLBuilder):
@param dev: VirtualDevice instance to attach to guest
"""
self._add_child(dev)
self.add_child(dev)
def remove_device(self, dev):
"""
@ -258,7 +258,7 @@ class Guest(XMLBuilder):
@param dev: VirtualDevice instance
"""
self._remove_child(dev)
self.remove_child(dev)
def get_devices(self, devtype):
"""
@ -273,6 +273,7 @@ class Guest(XMLBuilder):
if devtype == "all" or i.virtual_device_type == devtype:
newlist.append(i)
return newlist
_devices = XMLChildProperty(
[VirtualDevice.virtual_device_classes[_n]
for _n in VirtualDevice.virtual_device_types],

View File

@ -70,9 +70,9 @@ class InterfaceProtocol(XMLBuilder):
ip = _IPAddress(self.conn)
ip.address = addr
ip.prefix = prefix
self._add_child(ip)
self.add_child(ip)
def remove_ip(self, ip):
self._remove_child(ip)
self.remove_child(ip)
ip.clear()
ips = XMLChildProperty(_IPAddress)
@ -136,16 +136,16 @@ class Interface(XMLBuilder):
##################
def add_interface(self, obj):
self._add_child(obj)
self.add_child(obj)
def remove_interface(self, obj):
self._remove_child(obj)
self.remove_child(obj)
# 'interfaces' property is added outside this class, since it needs
# to reference the completed Interface class
def add_protocol(self, obj):
self._add_child(obj)
self.add_child(obj)
def remove_protocol(self, obj):
self._remove_child(obj)
self.remove_child(obj)
protocols = XMLChildProperty(InterfaceProtocol)

View File

@ -58,7 +58,7 @@ class _NetworkIP(XMLBuilder):
def add_range(self):
r = _NetworkDHCPRange(self.conn)
self._add_child(r)
self.add_child(r)
return r
@ -238,11 +238,11 @@ class Network(XMLBuilder):
def add_ip(self):
ip = _NetworkIP(self.conn)
self._add_child(ip)
self.add_child(ip)
return ip
def add_route(self):
route = _NetworkRoute(self.conn)
self._add_child(route)
self.add_child(route)
return route

View File

@ -83,12 +83,12 @@ class OSXML(XMLBuilder):
return [dev.dev for dev in self._bootdevs]
def _set_bootorder(self, newdevs):
for dev in self._bootdevs:
self._remove_child(dev)
self.remove_child(dev)
for d in newdevs:
dev = _BootDevice(self.conn)
dev.dev = d
self._add_child(dev)
self.add_child(dev)
_bootdevs = XMLChildProperty(_BootDevice)
bootorder = property(_get_bootorder, _set_bootorder)
@ -96,11 +96,11 @@ class OSXML(XMLBuilder):
def add_initarg(self, val):
obj = _InitArg(self.conn)
obj.val = val
self._add_child(obj)
self.add_child(obj)
def set_initargs_string(self, argstring):
import shlex
for obj in self.initargs:
self._remove_child(obj)
self.remove_child(obj)
for val in shlex.split(argstring):
self.add_initarg(val)

View File

@ -411,14 +411,14 @@ class StoragePool(_StorageObject):
default_cb=_get_default_target_path)
def add_host_obj(self, obj):
self._add_child(obj)
self.add_child(obj)
def add_host(self, name, port=None):
obj = _Host(self.conn)
obj.name = name
obj.port = port
self._add_child(obj)
self.add_child(obj)
def remove_host(self, obj):
self._remove_child(obj)
self.remove_child(obj)
hosts = XMLChildProperty(_Host, relative_xpath="./source")

View File

@ -292,7 +292,7 @@ class XMLChildProperty(property):
self._get(xmlbuilder).clear()
else:
for obj in self._get(xmlbuilder)[:]:
xmlbuilder._remove_child(obj)
xmlbuilder.remove_child(obj)
def append(self, xmlbuilder, newobj):
# Keep the list ordered by the order of passed in child classes
@ -950,10 +950,11 @@ class XMLBuilder(object):
for p in util.listify(getattr(self, propname, [])):
p._xmlstate._parse(None, self._xmlstate.xml_node)
def _add_child(self, obj):
def add_child(self, obj):
"""
Insert the passed XMLBuilder object into our XML document. The
object needs to have an associated mapping via XMLChildProperty
or an error is thrown.
"""
xmlprop = self._find_child_prop(obj.__class__)
xml = obj.get_xml_config()
@ -967,10 +968,10 @@ class XMLBuilder(object):
_build_xpath_node(self._xmlstate.xml_ctx, use_xpath, newnode)
obj._parse_with_children(None, self._xmlstate.xml_node)
def _remove_child(self, obj):
def remove_child(self, obj):
"""
Remove the passed XMLBuilder object from our XML document, but
ensure it's data isn't altered.
ensure its data isn't altered.
"""
xmlprop = self._find_child_prop(obj.__class__)
xmlprop.remove(self, obj)