[virt-tools-list] [virt-manager] [PATCH 3/9] create: Refactor OS container to enable bootstrap

Radostin Stoyanov rstoyanov1 at gmail.com
Thu Jun 22 14:54:00 UTC 2017


---
 ui/create.ui          |  2 ++
 virtManager/create.py | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/ui/create.ui b/ui/create.ui
index ae4227b..c9d2637 100644
--- a/ui/create.ui
+++ b/ui/create.ui
@@ -1736,6 +1736,7 @@ connections is not yet supported.</small></property>
                                             <property name="can_focus">True</property>
                                             <property name="receives_default">False</property>
                                             <property name="draw_indicator">True</property>
+                                            <signal name="toggled" handler="on_install_container_source_toggle" swapped="no"/>
                                           </object>
                                           <packing>
                                             <property name="expand">False</property>
@@ -1746,6 +1747,7 @@ connections is not yet supported.</small></property>
                                         <child>
                                           <object class="GtkBox" id="install-oscontainer-source">
                                             <property name="visible">True</property>
+                                            <property name="sensitive">False</property>
                                             <property name="can_focus">False</property>
                                             <property name="orientation">vertical</property>
                                             <child>
diff --git a/virtManager/create.py b/virtManager/create.py
index 275b6f3..658135c 100644
--- a/virtManager/create.py
+++ b/virtManager/create.py
@@ -21,6 +21,11 @@
 import logging
 import threading
 import time
+import subprocess
+try:
+    import commands  # Python2 only
+except Exception:
+    pass
 
 from gi.repository import GObject
 from gi.repository import Gtk
@@ -104,6 +109,17 @@ def _remove_vmm_device(guest, devkey):
         guest.remove_device(dev)
 
 
+def is_virt_bootstrap_installed():
+    ''' Returns True if virt-bootstrap is installed  '''
+    cmd = "virt-bootstrap --help"
+    # pylint: disable=E1101
+    try:
+        status, ignore = subprocess.getstatusoutput(cmd)  # Python3
+    except:
+        status, ignore = commands.getstatusoutput(cmd)  # Python2
+    return status == 0
+
+
 ##############
 # Main class #
 ##############
@@ -168,6 +184,7 @@ class vmmCreate(vmmGObjectUI):
             "on_install_import_browse_clicked": self._browse_import,
             "on_install_app_browse_clicked": self._browse_app,
             "on_install_oscontainer_browse_clicked": self._browse_oscontainer,
+            "on_install_container_source_toggle": self._container_source_toggle,
 
             "on_install_detect_os_toggled": self._toggle_detect_os,
             "on_install_os_type_changed": self._change_os_type,
@@ -427,6 +444,11 @@ class vmmCreate(vmmGObjectUI):
 
         # Install container OS
         self.widget("install-oscontainer-fs").set_text("")
+        self.widget("install-oscontainer-source-url-entry").set_text("")
+        self.widget("install-oscontainer-source-user").set_text("")
+        self.widget("install-oscontainer-source-passwd").set_text("")
+        self.widget("install-oscontainer-bootstrap").set_active(False)
+        self.widget("install-oscontainer-auth-options").set_expanded(False)
 
         # Install VZ container from template
         self.widget("install-container-template").set_text("centos-7-x86_64")
@@ -651,6 +673,20 @@ class vmmCreate(vmmGObjectUI):
 
         self._local_media_toggled(cdrom_option)
 
+        # Allow container bootstrap only for local connection and
+        # only if virt-bootstrap is installed. Otherwise, show message.
+        vb_installed = is_virt_bootstrap_installed()
+        vb_enabled = is_local and vb_installed
+
+        oscontainer_widget_conf = {
+            "install-oscontainer-notsupport-conn": not is_local,
+            "install-oscontainer-notsupport": not vb_installed,
+            "install-oscontainer-bootstrap": vb_enabled,
+            "install-oscontainer-source": vb_enabled
+            }
+        for w in oscontainer_widget_conf:
+            self.widget(w).set_visible(oscontainer_widget_conf[w])
+
         # Memory
         memory = int(self.conn.host_memory_size())
         mem_label = (_("Up to %(maxmem)s available on the host") %
@@ -1585,6 +1621,12 @@ class vmmCreate(vmmGObjectUI):
             _show_netdev_warn(_("Network selection does not support PXE"))
 
 
+    def _container_source_toggle(self, ignore):
+        ''' Enable/Disable container source URL entry on checkbox click'''
+        enable_src = self.widget("install-oscontainer-bootstrap").get_active()
+        self.widget("install-oscontainer-source").set_sensitive(enable_src)
+
+
     ########################
     # Misc helper routines #
     ########################
-- 
2.9.4




More information about the virt-tools-list mailing list