[virt-tools-list] [PATCH virt-manager] virtManager, host: warn user for unapplied changes

Cole Robinson crobinso at redhat.com
Fri Jul 25 19:46:05 UTC 2014


On 07/23/2014 09:56 AM, Giuseppe Scrivano wrote:
> Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1047875
> 
> Signed-off-by: Giuseppe Scrivano <gscrivan at redhat.com>
> ---
>  virtManager/host.py | 94 +++++++++++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 80 insertions(+), 14 deletions(-)
> 
> diff --git a/virtManager/host.py b/virtManager/host.py
> index 3c53a20..efcabd1 100644
> --- a/virtManager/host.py
> +++ b/virtManager/host.py
> @@ -1,5 +1,5 @@
>  #
> -# Copyright (C) 2007, 2013 Red Hat, Inc.
> +# Copyright (C) 2007, 2013-2014 Red Hat, Inc.
>  # Copyright (C) 2007 Daniel P. Berrange <berrange at redhat.com>
>  #
>  # This program is free software; you can redistribute it and/or modify
> @@ -47,7 +47,9 @@ EDIT_NET_QOS,
>  
>  EDIT_POOL_NAME,
>  EDIT_POOL_AUTOSTART,
> -) = range(5)
> +
> +EDIT_INTERFACE_STARTMODE,
> +) = range(6)
>  
>  
>  class vmmHost(vmmGObjectUI):
> @@ -99,7 +101,7 @@ class vmmHost(vmmGObjectUI):
>              "on_net_delete_clicked": self.delete_network,
>              "on_net_stop_clicked": self.stop_network,
>              "on_net_start_clicked": self.start_network,
> -            "on_net_apply_clicked": self.net_apply,
> +            "on_net_apply_clicked": (lambda *x: self.net_apply()),
>              "on_net_list_changed": self.net_selected,
>              "on_net_autostart_toggled": self.net_autostart_changed,
>              "on_net_name_changed": (lambda *x:
> @@ -114,7 +116,7 @@ class vmmHost(vmmGObjectUI):
>              "on_pool_autostart_toggled": self.pool_autostart_changed,
>              "on_vol_delete_clicked": self.delete_vol,
>              "on_vol_list_button_press_event": self.popup_vol_menu,
> -            "on_pool_apply_clicked": self.pool_apply,
> +            "on_pool_apply_clicked": (lambda *x: self.pool_apply()),
>              "on_vol_list_changed": self.vol_selected,
>              "on_pool_name_changed": (lambda *x:
>                  self.enable_pool_apply(x, EDIT_POOL_NAME)),
> @@ -124,7 +126,7 @@ class vmmHost(vmmGObjectUI):
>              "on_interface_stop_clicked" : self.stop_interface,
>              "on_interface_delete_clicked" : self.delete_interface,
>              "on_interface_startmode_changed": self.interface_startmode_changed,
> -            "on_interface_apply_clicked" : self.interface_apply,
> +            "on_interface_apply_clicked" : (lambda *x: self.interface_apply()),
>              "on_interface_list_changed": self.interface_selected,
>  
>              "on_config_autoconnect_toggled": self.toggle_autoconnect,
> @@ -177,6 +179,9 @@ class vmmHost(vmmGObjectUI):
>          netListModel = Gtk.ListStore(str, str, str, int, bool)
>          self.widget("net-list").set_model(netListModel)
>  
> +        sel = self.widget("net-list").get_selection()
> +        sel.set_select_function((lambda *x: self.confirm_changes()), None)
> +
>          netCol = Gtk.TreeViewColumn("Networks")
>          netCol.set_spacing(6)
>          net_txt = Gtk.CellRendererText()
> @@ -235,7 +240,7 @@ class vmmHost(vmmGObjectUI):
>  
>          volListModel.set_sort_column_id(1, Gtk.SortType.ASCENDING)
>  
> -        init_pool_list(self.widget("pool-list"), self.pool_selected)
> +        self.init_pool_list()
>  
>      def init_interface_state(self):
>          self.widget("interface-pages").set_show_tabs(False)
> @@ -244,6 +249,9 @@ class vmmHost(vmmGObjectUI):
>          interfaceListModel = Gtk.ListStore(str, str, str, int, bool)
>          self.widget("interface-list").set_model(interfaceListModel)
>  
> +        sel = self.widget("interface-list").get_selection()
> +        sel.set_select_function((lambda *x: self.confirm_changes()), None)
> +
>          interfaceCol = Gtk.TreeViewColumn("Interfaces")
>          interfaceCol.set_spacing(6)
>          interface_txt = Gtk.CellRendererText()
> @@ -324,6 +332,8 @@ class vmmHost(vmmGObjectUI):
>          if not self.is_visible():
>              return
>  
> +        self.confirm_changes()
> +
>          self.topwin.hide()
>          self.emit("host-closed")
>  
> @@ -377,11 +387,15 @@ class vmmHost(vmmGObjectUI):
>      def page_changed(self, src, child, pagenum):
>          ignore = src
>          ignore = child
> +        self.confirm_changes()
>          if pagenum == 1:
> +            self.repopulate_networks()
>              self.conn.schedule_priority_tick(pollnet=True)
>          elif pagenum == 2:
> +            self.repopulate_storage_volumes()
>              self.conn.schedule_priority_tick(pollpool=True)
>          elif pagenum == 3:
> +            self.repopulate_interfaces()
>              self.conn.schedule_priority_tick(polliface=True)
> 

What's this for?

>      def refresh_resources(self, ignore=None):
> @@ -485,7 +499,7 @@ class vmmHost(vmmGObjectUI):
>          except Exception, e:
>              self.err.show_err(_("Error launching network wizard: %s") % str(e))
>  
> -    def net_apply(self, src_ignore):
> +    def net_apply(self):
>          net = self.current_network()
>          if net is None:
>              return
> @@ -532,15 +546,28 @@ class vmmHost(vmmGObjectUI):
>              self.disable_net_apply()
>  
>      def disable_net_apply(self):
> -        self.active_edits = []
> +        for i in [EDIT_NET_NAME, EDIT_NET_AUTOSTART, EDIT_NET_QOS]:
> +            if i in self.active_edits:
> +                self.active_edits.remove(i)
>          self.widget("net-apply").set_sensitive(False)

This is going to get out of date fast. I'd say do something like:

EDIT_NET_IDS = (
EDIT_NET_FOO,
...) = range(5)

EDIT_STORAGE_IDS = (
...) = range(100, 101)

And then use those named tuples to implement just one disable_apply handler
that doesn't list the EDIT_* bits explicitly.

- Cole




More information about the virt-tools-list mailing list