mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
vmmDomain: cleanup xml handling functions.
Separate the public interfaces (get_xml and get_xml_to_define) from the private interfaces. Clean up usage where we violated this.
This commit is contained in:
parent
49938ebbd7
commit
b4b5a2b138
@ -577,7 +577,6 @@ class vmmDetails(gobject.GObject):
|
|||||||
|
|
||||||
self.engine.increment_window_counter()
|
self.engine.increment_window_counter()
|
||||||
self.update_widget_states(self.vm, self.vm.status())
|
self.update_widget_states(self.vm, self.vm.status())
|
||||||
self.vm.update_xml()
|
|
||||||
|
|
||||||
def show_help(self, src):
|
def show_help(self, src):
|
||||||
# From the Details window, show the help document from the Details page
|
# From the Details window, show the help document from the Details page
|
||||||
@ -862,10 +861,6 @@ class vmmDetails(gobject.GObject):
|
|||||||
details = self.window.get_widget("details-pages")
|
details = self.window.get_widget("details-pages")
|
||||||
page = details.get_current_page()
|
page = details.get_current_page()
|
||||||
|
|
||||||
if self.is_visible():
|
|
||||||
# Force an xml update, so we check for changed xml on every tick
|
|
||||||
self.vm.update_xml()
|
|
||||||
|
|
||||||
if (page == PAGE_DETAILS and
|
if (page == PAGE_DETAILS and
|
||||||
self.get_hw_selection(HW_LIST_COL_TYPE) == HW_LIST_TYPE_STATS):
|
self.get_hw_selection(HW_LIST_COL_TYPE) == HW_LIST_TYPE_STATS):
|
||||||
self.refresh_stats_page()
|
self.refresh_stats_page()
|
||||||
@ -1700,7 +1695,6 @@ class vmmDetails(gobject.GObject):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.remove_device(info[0], info[1])
|
self.remove_device(info[0], info[1])
|
||||||
self.vm.update_xml()
|
|
||||||
|
|
||||||
def prepare_hw_list(self):
|
def prepare_hw_list(self):
|
||||||
hw_list_model = gtk.ListStore(str, str, int, gtk.gdk.Pixbuf, int, gobject.TYPE_PYOBJECT)
|
hw_list_model = gtk.ListStore(str, str, int, gtk.gdk.Pixbuf, int, gobject.TYPE_PYOBJECT)
|
||||||
@ -1945,13 +1939,9 @@ class vmmDetails(gobject.GObject):
|
|||||||
def add_hardware(self, src):
|
def add_hardware(self, src):
|
||||||
if self.addhw is None:
|
if self.addhw is None:
|
||||||
self.addhw = vmmAddHardware(self.config, self.vm)
|
self.addhw = vmmAddHardware(self.config, self.vm)
|
||||||
self.addhw.topwin.connect("hide", self.add_hardware_done)
|
|
||||||
|
|
||||||
self.addhw.show()
|
self.addhw.show()
|
||||||
|
|
||||||
def add_hardware_done(self, ignore=None):
|
|
||||||
self.vm.update_xml()
|
|
||||||
|
|
||||||
def toggle_cdrom(self, src):
|
def toggle_cdrom(self, src):
|
||||||
info = self.get_hw_selection(HW_LIST_COL_DEVICE)
|
info = self.get_hw_selection(HW_LIST_COL_DEVICE)
|
||||||
if not info:
|
if not info:
|
||||||
|
@ -90,10 +90,20 @@ class vmmDomain(gobject.GObject):
|
|||||||
def get_xml(self):
|
def get_xml(self):
|
||||||
# Get domain xml. If cached xml is invalid, update.
|
# Get domain xml. If cached xml is invalid, update.
|
||||||
if self._xml is None or not self._valid_xml:
|
if self._xml is None or not self._valid_xml:
|
||||||
self.update_xml()
|
self._update_xml()
|
||||||
return self._xml
|
return self._xml
|
||||||
|
|
||||||
def update_xml(self):
|
def get_xml_to_define(self):
|
||||||
|
# FIXME: This isn't sufficient, since we pull stuff like disk targets
|
||||||
|
# from the active XML. This all needs proper fixing in the long
|
||||||
|
# term.
|
||||||
|
if self.is_active():
|
||||||
|
return self._get_inactive_xml()
|
||||||
|
else:
|
||||||
|
self._invalidate_xml()
|
||||||
|
return self.get_xml()
|
||||||
|
|
||||||
|
def _update_xml(self):
|
||||||
# Force an xml update. Signal 'config-changed' if domain xml has
|
# Force an xml update. Signal 'config-changed' if domain xml has
|
||||||
# changed since last refresh
|
# changed since last refresh
|
||||||
|
|
||||||
@ -110,30 +120,20 @@ class vmmDomain(gobject.GObject):
|
|||||||
self.tick(time.time())
|
self.tick(time.time())
|
||||||
self.emit("config-changed")
|
self.emit("config-changed")
|
||||||
|
|
||||||
def invalidate_xml(self):
|
def _invalidate_xml(self):
|
||||||
# Mark cached xml as invalid
|
# Mark cached xml as invalid
|
||||||
self._valid_xml = False
|
self._valid_xml = False
|
||||||
|
|
||||||
def get_inactive_xml(self):
|
def _get_inactive_xml(self):
|
||||||
# FIXME: We only allow the user to change the inactive xml once.
|
# FIXME: We only allow the user to change the inactive xml once.
|
||||||
# We should eventually allow them to continually change it,
|
# We should eventually allow them to continually change it,
|
||||||
# possibly see the inactive config? and not choke if they try
|
# possibly see the inactive config? and not choke if they try
|
||||||
# to remove a device twice.
|
# to remove a device twice.
|
||||||
if self._orig_inactive_xml is None:
|
if self._orig_inactive_xml is None:
|
||||||
self.refresh_inactive_xml()
|
self._refresh_inactive_xml()
|
||||||
return self._orig_inactive_xml
|
return self._orig_inactive_xml
|
||||||
|
|
||||||
def get_xml_to_define(self):
|
def _refresh_inactive_xml(self):
|
||||||
# FIXME: This isn't sufficient, since we pull stuff like disk targets
|
|
||||||
# from the active XML. This all needs proper fixing in the long
|
|
||||||
# term.
|
|
||||||
if self.is_active():
|
|
||||||
return self.get_inactive_xml()
|
|
||||||
else:
|
|
||||||
self.update_xml()
|
|
||||||
return self.get_xml()
|
|
||||||
|
|
||||||
def refresh_inactive_xml(self):
|
|
||||||
flags = (libvirt.VIR_DOMAIN_XML_INACTIVE |
|
flags = (libvirt.VIR_DOMAIN_XML_INACTIVE |
|
||||||
libvirt.VIR_DOMAIN_XML_SECURE)
|
libvirt.VIR_DOMAIN_XML_SECURE)
|
||||||
if not self.connection.has_dom_flags(flags):
|
if not self.connection.has_dom_flags(flags):
|
||||||
@ -172,7 +172,7 @@ class vmmDomain(gobject.GObject):
|
|||||||
self.get_connection().define_domain(newxml)
|
self.get_connection().define_domain(newxml)
|
||||||
|
|
||||||
# Invalidate cached XML
|
# Invalidate cached XML
|
||||||
self.invalidate_xml()
|
self._invalidate_xml()
|
||||||
|
|
||||||
def release_handle(self):
|
def release_handle(self):
|
||||||
del(self.vm)
|
del(self.vm)
|
||||||
@ -370,7 +370,7 @@ class vmmDomain(gobject.GObject):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Invalidate cached xml
|
# Invalidate cached xml
|
||||||
self.invalidate_xml()
|
self._invalidate_xml()
|
||||||
|
|
||||||
info = self.vm.info()
|
info = self.vm.info()
|
||||||
expected = self.config.get_stats_history_length()
|
expected = self.config.get_stats_history_length()
|
||||||
@ -718,8 +718,6 @@ class vmmDomain(gobject.GObject):
|
|||||||
return self._parse_device_xml(_parse_serial_consoles)
|
return self._parse_device_xml(_parse_serial_consoles)
|
||||||
|
|
||||||
def get_graphics_console(self):
|
def get_graphics_console(self):
|
||||||
self.update_xml()
|
|
||||||
|
|
||||||
typ = vutil.get_xml_path(self.get_xml(),
|
typ = vutil.get_xml_path(self.get_xml(),
|
||||||
"/domain/devices/graphics/@type")
|
"/domain/devices/graphics/@type")
|
||||||
port = None
|
port = None
|
||||||
@ -1067,7 +1065,6 @@ class vmmDomain(gobject.GObject):
|
|||||||
return xml[0:index] + devxml + xml[index:]
|
return xml[0:index] + devxml + xml[index:]
|
||||||
|
|
||||||
def get_device_xml(self, dev_type, dev_id_info):
|
def get_device_xml(self, dev_type, dev_id_info):
|
||||||
self.update_xml()
|
|
||||||
vmxml = self.get_xml()
|
vmxml = self.get_xml()
|
||||||
|
|
||||||
def dev_xml_serialize(doc, ctx):
|
def dev_xml_serialize(doc, ctx):
|
||||||
@ -1300,11 +1297,6 @@ class vmmDomain(gobject.GObject):
|
|||||||
self.hotplug_maxmem(maxmem)
|
self.hotplug_maxmem(maxmem)
|
||||||
|
|
||||||
def define_both_mem(self, memory, maxmem):
|
def define_both_mem(self, memory, maxmem):
|
||||||
# Make sure we correctly define the XML with new values, since
|
|
||||||
# setMem and setMaxMem don't (or, aren't supposed to) affect
|
|
||||||
# the persistent config
|
|
||||||
self.invalidate_xml()
|
|
||||||
|
|
||||||
def set_mem_node(doc, ctx, memval, xpath):
|
def set_mem_node(doc, ctx, memval, xpath):
|
||||||
node = ctx.xpathEval(xpath)
|
node = ctx.xpathEval(xpath)
|
||||||
node = (node and node[0] or None)
|
node = (node and node[0] or None)
|
||||||
|
Loading…
Reference in New Issue
Block a user