From acfb988945dd62de36576b217dbc1013d1415765 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Fri, 4 Sep 2015 15:45:45 -0400 Subject: [PATCH] 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. --- virtinst/clock.py | 4 ++-- virtinst/cpu.py | 4 ++-- virtinst/devicegraphics.py | 2 +- virtinst/guest.py | 5 +++-- virtinst/interface.py | 12 ++++++------ virtinst/network.py | 6 +++--- virtinst/osxml.py | 8 ++++---- virtinst/storage.py | 6 +++--- virtinst/xmlbuilder.py | 9 +++++---- 9 files changed, 29 insertions(+), 27 deletions(-) diff --git a/virtinst/clock.py b/virtinst/clock.py index ccc640dd1..ea626b14d 100644 --- a/virtinst/clock.py +++ b/virtinst/clock.py @@ -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) diff --git a/virtinst/cpu.py b/virtinst/cpu.py index fb17bb733..9dfd0ce67 100644 --- a/virtinst/cpu.py +++ b/virtinst/cpu.py @@ -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): diff --git a/virtinst/devicegraphics.py b/virtinst/devicegraphics.py index fdd44f066..d8d54ddb8 100644 --- a/virtinst/devicegraphics.py +++ b/virtinst/devicegraphics.py @@ -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") diff --git a/virtinst/guest.py b/virtinst/guest.py index 24a1e6602..32c4e7c35 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -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], diff --git a/virtinst/interface.py b/virtinst/interface.py index d7b25e755..60faf355b 100644 --- a/virtinst/interface.py +++ b/virtinst/interface.py @@ -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) diff --git a/virtinst/network.py b/virtinst/network.py index 8518e57fb..a008f947b 100644 --- a/virtinst/network.py +++ b/virtinst/network.py @@ -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 diff --git a/virtinst/osxml.py b/virtinst/osxml.py index 9569f65a3..2bbd46661 100644 --- a/virtinst/osxml.py +++ b/virtinst/osxml.py @@ -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) diff --git a/virtinst/storage.py b/virtinst/storage.py index d3d867adc..377683ec7 100644 --- a/virtinst/storage.py +++ b/virtinst/storage.py @@ -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") diff --git a/virtinst/xmlbuilder.py b/virtinst/xmlbuilder.py index d4f03dbab..84bbc24ca 100644 --- a/virtinst/xmlbuilder.py +++ b/virtinst/xmlbuilder.py @@ -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)