[virt-tools-list] [virt-manager] [PATCH v3 1/4] create: Call virt-bootstrap asynchronously
Radostin Stoyanov
rstoyanov1 at gmail.com
Tue Jul 11 00:07:20 UTC 2017
The bootstrap method is called at the end of the "create dialog" (when
"Finish" button is clicked).
We handle two cases:
1. When virt-bootstrap fails. User re-clicks the 'Finish' button and we
reattempt the container bootstrap.
2. When virt-bootstrap succeeds, but something later in the install
fails, like XML define. If user re-clicks 'Finish' we don't attempt
virt-bootstrap again, just use the directory path.
This is achieved by unchecking the 'install-oscontainer-bootstrap'
checkbox is unchecked if virt-bootstrap succeeds.
Log messages from the virtBootstrap's logger are stored in string
buffer and shown in case of failure.
---
virtManager/create.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/virtManager/create.py b/virtManager/create.py
index 662c200..75fd553 100644
--- a/virtManager/create.py
+++ b/virtManager/create.py
@@ -21,6 +21,7 @@
import logging
import pkgutil
import os
+import cStringIO
import threading
import time
@@ -2494,6 +2495,19 @@ class vmmCreate(vmmGObjectUI):
"""
meter = asyncjob.get_meter()
+ container_bootstrap = self._get_config_oscontainer_bootstrap()
+ # If creating new container and "container bootstrap" is enabled
+ if self._guest.os.is_container() and container_bootstrap:
+ # Start container bootstrap
+ src_url = self._get_config_oscontainer_source_url()
+ dest = self.widget("install-oscontainer-fs").get_text()
+ user = self._get_config_oscontainer_source_username()
+ passwd = self._get_config_oscontainer_source_password()
+ insecure = self._get_config_oscontainer_isecure()
+
+ self._create_directory_tree(asyncjob, src_url, dest, user, passwd,
+ insecure)
+
# Build a list of pools we should refresh, if we are creating storage
refresh_pools = []
for disk in guest.get_devices("disk"):
@@ -2578,3 +2592,35 @@ class vmmCreate(vmmGObjectUI):
self.err.show_err(_("Error continue install: %s") % str(e))
return True
+
+
+ def _create_directory_tree(self, asyncjob, src, dest, user, passwd, insecure):
+ """
+ Call bootstrap method from virtBootstrap.
+ """
+ import virtBootstrap
+
+ # Use string buffer to store log messages
+ log_stream = cStringIO.StringIO()
+
+ # Get virt-bootstrap logger
+ vbLogger = logging.getLogger('virtBootstrap')
+ vbLogger.setLevel(logging.DEBUG)
+ vbLogger.addHandler(logging.StreamHandler(log_stream))
+
+ # Key word arguments to be passed
+ kwargs = {'uri': src, 'dest': dest, 'not_secure': insecure}
+ if user and passwd:
+ kwargs['username'] = user
+ kwargs['password'] = passwd
+
+ logging.debug('Start container bootstrap')
+ try:
+ virtBootstrap.bootstrap(**kwargs)
+ # Success - uncheck the 'install-oscontainer-bootstrap' checkbox
+ self.widget("install-oscontainer-bootstrap").set_active(False)
+ except Exception as err:
+ asyncjob.set_error(err, log_stream.getvalue())
+ except:
+ asyncjob.set_error("Container bootstrap has failed",
+ log_stream.getvalue())
--
2.9.4
More information about the virt-tools-list
mailing list