[virt-tools-list] [virt-manager PATCH] details: add UI interface for LXC user namespace

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Wed Feb 19 11:34:07 UTC 2014


We could config user namespace for LXC container
in details->overview page.

Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
 ui/details.ui          | 239 +++++++++++++++++++++++++++++++++++++++++++++++--
 virtManager/details.py |  58 +++++++++++-
 virtManager/domain.py  |  15 ++++
 3 files changed, 305 insertions(+), 7 deletions(-)

diff --git a/ui/details.ui b/ui/details.ui
index 6e330f9..9b8e862 100644
--- a/ui/details.ui
+++ b/ui/details.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.16.1 -->
+<!-- Generated with glade 3.16.0 on Wed Feb 19 02:51:40 2014 -->
 <interface>
-  <requires lib="gtk+" version="3.0"/>
+  <!-- interface-requires gtk+ 3.0 -->
   <object class="GtkAccelGroup" id="accelgroup1"/>
   <object class="GtkAdjustment" id="adjustment1">
     <property name="lower">1</property>
@@ -1004,6 +1004,233 @@
                                 <property name="position">1</property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkExpander" id="config-idmap-expander">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <child>
+                                  <object class="GtkGrid" id="config-idmap-grid">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="orientation">vertical</property>
+                                    <property name="column_spacing">1</property>
+                                    <child>
+                                      <object class="GtkCheckButton" id="config-idmap-check">
+                                        <property name="label" translatable="yes">Config User Namespace</property>
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">False</property>
+                                        <property name="xalign">0</property>
+                                        <property name="draw_indicator">True</property>
+                                        <signal name="toggled" handler="on_config_idmap_check_toggled" swapped="no"/>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">0</property>
+                                        <property name="top_attach">0</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkGrid" id="idmpa-entry-grid">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <child>
+                                          <object class="GtkLabel" id="label19">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="xalign">1</property>
+                                            <property name="label" translatable="yes">User ID: </property>
+                                            <property name="max_width_chars">15</property>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">0</property>
+                                            <property name="top_attach">1</property>
+                                            <property name="width">1</property>
+                                            <property name="height">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkLabel" id="label20">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="xalign">1</property>
+                                            <property name="label" translatable="yes">  Group ID: </property>
+                                            <property name="max_width_chars">15</property>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">0</property>
+                                            <property name="top_attach">2</property>
+                                            <property name="width">1</property>
+                                            <property name="height">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkLabel" id="label21">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="label" translatable="yes">start</property>
+                                            <property name="max_width_chars">10</property>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">1</property>
+                                            <property name="top_attach">0</property>
+                                            <property name="width">1</property>
+                                            <property name="height">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkLabel" id="label22">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="label" translatable="yes">target</property>
+                                            <property name="max_width_chars">10</property>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">2</property>
+                                            <property name="top_attach">0</property>
+                                            <property name="width">1</property>
+                                            <property name="height">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkLabel" id="label29">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="label" translatable="yes">count</property>
+                                            <property name="max_width_chars">10</property>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">3</property>
+                                            <property name="top_attach">0</property>
+                                            <property name="width">1</property>
+                                            <property name="height">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkLabel" id="label33">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="max_width_chars">15</property>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">0</property>
+                                            <property name="top_attach">0</property>
+                                            <property name="width">1</property>
+                                            <property name="height">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkEntry" id="uid-start">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="width_chars">10</property>
+                                            <signal name="changed" handler="on_idmap_uid_start_changed" swapped="no"/>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">1</property>
+                                            <property name="top_attach">1</property>
+                                            <property name="width">1</property>
+                                            <property name="height">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkEntry" id="gid-start">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="width_chars">10</property>
+                                            <signal name="changed" handler="on_idmap_gid_start_changed" swapped="no"/>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">1</property>
+                                            <property name="top_attach">2</property>
+                                            <property name="width">1</property>
+                                            <property name="height">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkEntry" id="uid-target">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="width_chars">10</property>
+                                            <signal name="changed" handler="on_idmap_uid_target_changed" swapped="no"/>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">2</property>
+                                            <property name="top_attach">1</property>
+                                            <property name="width">1</property>
+                                            <property name="height">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkEntry" id="gid-target">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="width_chars">10</property>
+                                            <signal name="changed" handler="on_idmap_gid_target_changed" swapped="no"/>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">2</property>
+                                            <property name="top_attach">2</property>
+                                            <property name="width">1</property>
+                                            <property name="height">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkEntry" id="uid-count">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="width_chars">10</property>
+                                            <signal name="changed" handler="on_idmap_uid_count_changed" swapped="no"/>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">3</property>
+                                            <property name="top_attach">1</property>
+                                            <property name="width">1</property>
+                                            <property name="height">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkEntry" id="gid-count">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="width_chars">10</property>
+                                            <signal name="changed" handler="on_idmap_gid_count_changed" swapped="no"/>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">3</property>
+                                            <property name="top_attach">2</property>
+                                            <property name="width">1</property>
+                                            <property name="height">1</property>
+                                          </packing>
+                                        </child>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">0</property>
+                                        <property name="top_attach">1</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                </child>
+                                <child type="label">
+                                  <object class="GtkLabel" id="label8">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label" translatable="yes">User Namespace setting</property>
+                                  </object>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">True</property>
+                                <property name="fill">True</property>
+                                <property name="position">2</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
                           </object>
                         </child>
                         <child type="tab">
@@ -1646,12 +1873,12 @@
                                                 <property name="climb_rate">1</property>
                                                 <property name="numeric">True</property>
                                                 <property name="update_policy">if-valid</property>
-                                                <signal name="changed" handler="on_config_vcpus_changed" swapped="no"/>
                                                 <child internal-child="accessible">
                                                   <object class="AtkObject" id="config-vcpus-atkobject">
                                                     <property name="AtkObject::accessible-name" translatable="yes">Virtual CPU Select</property>
                                                   </object>
                                                 </child>
+                                                <signal name="changed" handler="on_config_vcpus_changed" swapped="no"/>
                                               </object>
                                               <packing>
                                                 <property name="left_attach">1</property>
@@ -2046,12 +2273,12 @@
                                                     <property name="visible">True</property>
                                                     <property name="can_focus">True</property>
                                                     <property name="invisible_char">●</property>
-                                                    <signal name="changed" handler="on_config_vcpupin_changed" swapped="no"/>
                                                     <child internal-child="accessible">
                                                       <object class="AtkObject" id="config-vcpupin-atkobject">
                                                         <property name="AtkObject::accessible-name" translatable="yes">Virtual CPU Affinity Select</property>
                                                       </object>
                                                     </child>
+                                                    <signal name="changed" handler="on_config_vcpupin_changed" swapped="no"/>
                                                   </object>
                                                   <packing>
                                                     <property name="expand">False</property>
@@ -2280,12 +2507,12 @@
                                                 <property name="climb_rate">2</property>
                                                 <property name="numeric">True</property>
                                                 <property name="update_policy">if-valid</property>
-                                                <signal name="changed" handler="on_config_memory_changed" swapped="no"/>
                                                 <child internal-child="accessible">
                                                   <object class="AtkObject" id="config-memory-atkobject">
                                                     <property name="AtkObject::accessible-name" translatable="yes">Memory Select</property>
                                                   </object>
                                                 </child>
+                                                <signal name="changed" handler="on_config_memory_changed" swapped="no"/>
                                               </object>
                                               <packing>
                                                 <property name="expand">False</property>
@@ -2329,12 +2556,12 @@
                                                 <property name="climb_rate">2</property>
                                                 <property name="numeric">True</property>
                                                 <property name="update_policy">if-valid</property>
-                                                <signal name="changed" handler="on_config_maxmem_changed" swapped="no"/>
                                                 <child internal-child="accessible">
                                                   <object class="AtkObject" id="config-maxmem-atkobject">
                                                     <property name="AtkObject::accessible-name" translatable="yes">Max Memory Select</property>
                                                   </object>
                                                 </child>
+                                                <signal name="changed" handler="on_config_maxmem_changed" swapped="no"/>
                                               </object>
                                               <packing>
                                                 <property name="expand">False</property>
diff --git a/virtManager/details.py b/virtManager/details.py
index 72e79da..f4b1339 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -103,7 +103,9 @@ EDIT_FS,
 
 EDIT_HOSTDEV_ROMBAR,
 
-) = range(1, 42)
+EDIT_IDMAP,
+
+) = range(1, 43)
 
 
 # Columns in hw list model
@@ -579,6 +581,13 @@ class vmmDetails(vmmGObjectUI):
             "on_overview_name_changed": lambda *x: self.enable_apply(x, EDIT_NAME),
             "on_overview_title_changed": lambda *x: self.enable_apply(x, EDIT_TITLE),
             "on_machine_type_changed": lambda *x: self.enable_apply(x, EDIT_MACHTYPE),
+            "on_idmap_uid_start_changed": lambda *x: self.enable_apply(x, EDIT_IDMAP),
+            "on_idmap_uid_target_changed": lambda *x: self.enable_apply(x, EDIT_IDMAP),
+            "on_idmap_uid_count_changed": lambda *x: self.enable_apply(x, EDIT_IDMAP),
+            "on_idmap_gid_start_changed": lambda *x: self.enable_apply(x, EDIT_IDMAP),
+            "on_idmap_gid_target_changed": lambda *x: self.enable_apply(x, EDIT_IDMAP),
+            "on_idmap_gid_count_changed": lambda *x: self.enable_apply(x, EDIT_IDMAP),
+            "on_config_idmap_check_toggled": self.toggle_idmap_check,
 
             "on_config_vcpus_changed": self.config_vcpus_changed,
             "on_config_maxvcpus_changed": self.config_maxvcpus_changed,
@@ -1600,6 +1609,24 @@ class vmmDetails(vmmGObjectUI):
         if edittype not in self.active_edits:
             self.active_edits.append(edittype)
 
+    def toggle_idmap_check(self, src):
+        Name = ["uid-start", "uid-target", "uid-count",
+                "gid-start", "gid-target", "gid-count"]
+        for name in Name:
+            self.widget(name).set_sensitive(src.get_active())
+        IdMap = self.vm.get_idmap()
+        if IdMap.uid_start is not None:
+            for name in Name:
+                IdMap_proper = getattr(IdMap, name.replace("-", "_"))
+                self.widget(name).set_text(str(IdMap_proper))
+        elif src.get_active():
+            self.widget("uid-start").set_text('0')
+            self.widget("uid-target").set_text('1000')
+            self.widget("uid-count").set_text('10')
+            self.widget("gid-start").set_text('0')
+            self.widget("gid-target").set_text('1000')
+            self.widget("gid-count").set_text('10')
+
     # Memory
     def config_get_maxmem(self):
         return uiutil.spin_get_helper(self.widget("config-maxmem"))
@@ -1955,6 +1982,19 @@ class vmmDetails(vmmGObjectUI):
             add_define(self.vm.define_description, desc)
             add_hotplug(self.vm.hotplug_description, desc)
 
+        if self.edited(EDIT_IDMAP):
+            uid_start = self.widget("uid-start").get_text().strip()
+            uid_target = self.widget("uid-target").get_text().strip()
+            uid_count = self.widget("uid-count").get_text().strip()
+            gid_start = self.widget("gid-start").get_text().strip()
+            gid_target = self.widget("gid-target").get_text().strip()
+            gid_count = self.widget("gid-count").get_text().strip()
+
+            idmap_list = [uid_start, uid_target, uid_count, gid_start,
+                    gid_target, gid_count]
+            if self.widget("config-idmap-check").get_active():
+                add_define(self.vm.define_idmap, idmap_list)
+
         return self._change_config_helper(df, da, hf, ha)
 
     # CPUs
@@ -2439,6 +2479,22 @@ class vmmDetails(vmmGObjectUI):
             if machtype is not None:
                 uiutil.set_combo_entry(self.widget("machine-type"), machtype)
 
+        # User namespace idmap setting
+        is_container = self.vm.is_container()
+        self.widget("config-idmap-expander").set_visible(is_container)
+        IdMap = self.vm.get_idmap()
+        Name = ["uid-start", "uid-target", "uid-count",
+                "gid-start", "gid-target", "gid-count"]
+        if IdMap.uid_start is not None:
+            self.widget("config-idmap-check").set_active(True)
+            for name in Name:
+                IdMap_proper = getattr(IdMap, name.replace("-", "_"))
+                self.widget(name).set_text(str(IdMap_proper))
+        else:
+            self.widget("config-idmap-check").set_active(False)
+            for name in Name:
+                self.widget(name).set_text("")
+
     def refresh_inspection_page(self):
         inspection_supported = self.config.support_inspection
         uiutil.set_grid_row_visible(self.widget("details-overview-error"),
diff --git a/virtManager/domain.py b/virtManager/domain.py
index 8d0c95f..3ede5d0 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -573,6 +573,19 @@ class vmmDomain(vmmLibvirtObject):
             guest.title = newvalue or None
         return self._redefine(change)
 
+    # Idmap config define methods
+    def define_idmap(self, idmap_list):
+        (uid_start, uid_target, uid_count, gid_start,
+                gid_target, gid_count) = idmap_list
+        def change(guest):
+            guest.idmap.uid_start = uid_start
+            guest.idmap.uid_target = uid_target
+            guest.idmap.uid_count = uid_count
+            guest.idmap.gid_start = gid_start
+            guest.idmap.gid_target = gid_target
+            guest.idmap.gid_count = gid_count
+        return self._redefine(change)
+
     # Boot define methods
     def can_use_device_boot_order(self):
         # Return 'True' if guest can use new style boot device ordering
@@ -1058,6 +1071,8 @@ class vmmDomain(vmmLibvirtObject):
         return self.get_xmlobj().emulator
     def get_machtype(self):
         return self.get_xmlobj().os.machine
+    def get_idmap(self):
+        return self.get_xmlobj().idmap
 
     def get_name_or_title(self):
         title = self.get_title()
-- 
1.8.5.3





More information about the virt-tools-list mailing list