[virt-tools-list] [v2 PATCH] Revert cpu 'copy' button & make 'host-model' checkbox invisible

Guannan Ren gren at redhat.com
Sat Apr 27 05:33:12 UTC 2013


This patch has 'Use host CPU model' checkbox invisible and keep
related codes for later use.
Restore 'Copy host CPU configuration' button and codes.
---
 ui/vmm-details.ui      | 103 +++++++++++++++++++++++++++++++++++++++++--------
 virtManager/details.py |  19 ++++++++-
 virtManager/domain.py  |  17 ++++----
 3 files changed, 112 insertions(+), 27 deletions(-)

diff --git a/ui/vmm-details.ui b/ui/vmm-details.ui
index 631d58f..8ba9b42 100644
--- a/ui/vmm-details.ui
+++ b/ui/vmm-details.ui
@@ -2317,7 +2317,7 @@ I/O:</property>
                                               <object class="GtkCheckButton" id="cpu-host-model-checkbutton">
                                                 <property name="label" translatable="yes">Use host CPU model</property>
                                                 <property name="use_action_appearance">False</property>
-                                                <property name="visible">True</property>
+                                                <property name="visible">False</property>
                                                 <property name="can_focus">True</property>
                                                 <property name="receives_default">False</property>
                                                 <property name="draw_indicator">True</property>
@@ -2330,43 +2330,114 @@ I/O:</property>
                                               </packing>
                                             </child>
                                             <child>
-                                              <object class="GtkHBox" id="hbox14">
+                                              <object class="GtkTable" id="table15">
                                                 <property name="visible">True</property>
                                                 <property name="can_focus">False</property>
+                                                <property name="n_rows">2</property>
+                                                <property name="n_columns">2</property>
+                                                <property name="column_spacing">12</property>
+                                                <property name="row_spacing">3</property>
                                                 <child>
                                                   <object class="GtkLabel" id="label52">
                                                     <property name="visible">True</property>
                                                     <property name="can_focus">False</property>
+                                                    <property name="xalign">0</property>
                                                     <property name="label" translatable="yes">Model:</property>
                                                   </object>
                                                   <packing>
-                                                    <property name="expand">False</property>
-                                                    <property name="fill">False</property>
-                                                    <property name="position">0</property>
+                                                    <property name="x_options">GTK_FILL</property>
+                                                    <property name="y_options">GTK_FILL</property>
                                                   </packing>
                                                 </child>
                                                 <child>
-                                                  <object class="GtkAlignment" id="alignment12">
+                                                  <object class="GtkHBox" id="hbox21">
                                                     <property name="visible">True</property>
                                                     <property name="can_focus">False</property>
                                                     <child>
-                                                      <object class="GtkComboBox" id="cpu-model">
+                                                      <object class="GtkAlignment" id="alignment33">
                                                         <property name="visible">True</property>
                                                         <property name="can_focus">False</property>
-                                                        <property name="has_entry">True</property>
-                                                        <signal name="changed" handler="on_cpu_model_changed" swapped="no"/>
-                                                        <child internal-child="entry">
-                                                        <object class="GtkEntry" id="combobox-entry">
+                                                        <child>
+                                                          <object class="GtkComboBox" id="cpu-model">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="has_entry">True</property>
+                                                            <signal name="changed" handler="on_cpu_model_changed" swapped="no"/>
+                                                            <child internal-child="entry">
+                                                            <object class="GtkEntry" id="combobox-entry">
+                                                            <property name="can_focus">True</property>
+                                                            </object>
+                                                            </child>
+                                                          </object>
+                                                        </child>
+                                                      </object>
+                                                      <packing>
+                                                        <property name="expand">False</property>
+                                                        <property name="fill">False</property>
+                                                        <property name="position">1</property>
+                                                      </packing>
+                                                    </child>
+                                                  </object>
+                                                  <packing>
+                                                    <property name="left_attach">1</property>
+                                                    <property name="right_attach">2</property>
+                                                    <property name="y_options">GTK_FILL</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
+                                                  <object class="GtkAlignment" id="alignment37">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <child>
+                                                      <placeholder/>
+                                                    </child>
+                                                  </object>
+                                                  <packing>
+                                                    <property name="top_attach">1</property>
+                                                    <property name="bottom_attach">2</property>
+                                                    <property name="x_options">GTK_FILL</property>
+                                                    <property name="y_options">GTK_FILL</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
+                                                  <object class="GtkHBox" id="hbox25">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <child>
+                                                      <object class="GtkButton" id="cpu-copy-host">
+                                                        <property name="label" translatable="yes">Copy host CPU configuration</property>
+                                                        <property name="visible">True</property>
                                                         <property name="can_focus">True</property>
-                                                        </object>
+                                                        <property name="receives_default">True</property>
+                                                        <signal name="clicked" handler="on_cpu_copy_host_clicked" swapped="no"/>
+                                                      </object>
+                                                      <packing>
+                                                        <property name="expand">False</property>
+                                                        <property name="fill">True</property>
+                                                        <property name="position">0</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <object class="GtkAlignment" id="alignment38">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <child>
+                                                          <placeholder/>
                                                         </child>
                                                       </object>
+                                                      <packing>
+                                                        <property name="expand">True</property>
+                                                        <property name="fill">True</property>
+                                                        <property name="position">1</property>
+                                                      </packing>
                                                     </child>
                                                   </object>
                                                   <packing>
-                                                    <property name="expand">False</property>
-                                                    <property name="fill">False</property>
-                                                    <property name="position">1</property>
+                                                    <property name="left_attach">1</property>
+                                                    <property name="right_attach">2</property>
+                                                    <property name="top_attach">1</property>
+                                                    <property name="bottom_attach">2</property>
+                                                    <property name="y_options">GTK_FILL</property>
                                                   </packing>
                                                 </child>
                                               </object>
@@ -2423,7 +2494,7 @@ I/O:</property>
                                                             </child>
                                                           </object>
                                                           <packing>
-                                                            <property name="expand">False</property>
+                                                            <property name="expand">True</property>
                                                             <property name="fill">True</property>
                                                             <property name="position">1</property>
                                                           </packing>
diff --git a/virtManager/details.py b/virtManager/details.py
index cd18aa8..e323716 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -360,6 +360,7 @@ class vmmDetails(vmmGObjectUI):
 
         self.ignorePause = False
         self.ignoreDetails = False
+        self._cpu_copy_host = False
 
         self.console = vmmConsolePages(self.vm, self.builder, self.topwin)
 
@@ -431,6 +432,7 @@ class vmmDetails(vmmGObjectUI):
             "on_cpu_sockets_changed": lambda *x: self.enable_apply(x, EDIT_TOPOLOGY),
             "on_cpu_threads_changed": lambda *x: self.enable_apply(x, EDIT_TOPOLOGY),
             "on_cpu_host_model_enable_toggled": self.config_cpu_host_model_enable,
+            "on_cpu_copy_host_clicked": self.config_cpu_copy_host,
             "on_cpu_topology_enable_toggled": self.config_cpu_topology_enable,
 
             "on_config_memory_changed": self.config_memory_changed,
@@ -1819,6 +1821,18 @@ class vmmDetails(vmmGObjectUI):
         self.widget("cpu-features").set_sensitive(not bool(do_enable))
         self.enable_apply(EDIT_CPU)
 
+    def config_cpu_copy_host(self, src_ignore):
+        # Update UI with output copied from host
+        try:
+            CPU = virtinst.CPU(self.vm.conn.vmm)
+            CPU.copy_host_cpu()
+
+            self._refresh_cpu_config(CPU)
+            self._cpu_copy_host = True
+        except Exception, e:
+            self.err.show_err(_("Error copying host CPU: %s") % str(e))
+            return
+
     def config_cpu_topology_enable(self, src):
         do_enable = src.get_active()
         self.widget("cpu-topology-table").set_sensitive(do_enable)
@@ -2119,7 +2133,7 @@ class vmmDetails(vmmGObjectUI):
             model, vendor = self.get_config_cpu_model()
             features = self.get_config_cpu_features()
             add_define(self.vm.define_cpu,
-                       model, vendor, from_host, features)
+                       model, vendor, self._cpu_copy_host, features)
 
         if self.editted(EDIT_TOPOLOGY):
             do_top = self.widget("cpu-topology-enable").get_active()
@@ -2134,6 +2148,8 @@ class vmmDetails(vmmGObjectUI):
             add_define(self.vm.define_cpu_topology, sockets, cores, threads)
 
         ret = self._change_config_helper(df, da, hf, ha)
+        if ret:
+            self._cpu_copy_host = False
         return ret
 
     def config_vcpu_pin(self, src_ignore, path, new_text):
@@ -2860,6 +2876,7 @@ class vmmDetails(vmmGObjectUI):
             row[1] = get_feature_policy(row[0])
 
     def refresh_config_cpu(self):
+        self._cpu_copy_host = False
         cpu = self.vm.get_cpu_config()
 
         self._refresh_cpu_count()
diff --git a/virtManager/domain.py b/virtManager/domain.py
index 823e17b..f958c4b 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -468,19 +468,16 @@ class vmmDomain(vmmLibvirtObject):
     def define_cpu(self, model, vendor, from_host, featurelist):
         def change(guest):
             if from_host:
-                if virtinst.support.check_domain_support(self._backend,
-                    virtinst.support.SUPPORT_DOMAIN_CPU_HOST_MODEL):
-                    guest.cpu.clear_attrs()
-                    guest.cpu.mode = "host-model"
-                else:
-                    guest.cpu.copy_host_cpu()
-                return
+                guest.cpu.copy_host_cpu()
+            elif guest.cpu.model != model:
+                # Since we don't expose this in the UI, have host value trump
+                # caps value
+                guest.cpu.vendor = vendor
 
             guest.cpu.model = model or None
-            guest.cpu.vendor = vendor or None
-
             if guest.cpu.model is None:
-                guest.cpu.clear_attrs()
+                for f in guest.cpu.features:
+                    guest.cpu.remove_feature(f)
                 return
 
             origfeatures = guest.cpu.features
-- 
1.8.1.4




More information about the virt-tools-list mailing list