[virt-bootstrap] [PATCH 8/9] root-password: Handle different sources

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This changes aim to:
- VirtBuilderSource: pass the root password to virt-builder.
- FileSource: Call set_root_password_in_rootfs() or
  set_root_password_in_image() for format 'dir' or 'qcow2' respectivly.
- DockerSource: should have the same behaviour as before.
---
 src/virtBootstrap/sources.py        | 19 +++++++++++++++++++
 src/virtBootstrap/virt_bootstrap.py |  5 +----
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/virtBootstrap/sources.py b/src/virtBootstrap/sources.py
index 3f06f96..8ed8406 100644
--- a/src/virtBootstrap/sources.py
+++ b/src/virtBootstrap/sources.py
@@ -51,6 +51,7 @@ class FileSource(object):
         self.path = kwargs['uri'].path
         self.output_format = kwargs.get('fmt', utils.DEFAULT_OUTPUT_FORMAT)
         self.use_sandbox = kwargs.get('use_sandbox', False)
+        self.root_password = kwargs.get('root_password', None)
         self.progress = kwargs['progress'].update_progress
 
     def unpack(self, dest):
@@ -68,6 +69,10 @@ class FileSource(object):
                           value=0, logger=logger)
             utils.untar(self.path, dest, self.use_sandbox)
 
+            if self.root_password is not None:
+                logger.info("Setting password of the root account")
+                utils.set_root_password_in_rootfs(dest, self.root_password)
+
         elif self.output_format == 'qcow2':
             # Remove the old path
             file_name = os.path.basename(self.path)
@@ -77,6 +82,11 @@ class FileSource(object):
             self.progress("Extracting files into qcow2 image", value=0,
                           logger=logger)
             utils.create_qcow2(self.path, qcow2_file)
+
+            if self.root_password is not None:
+                logger.info("Setting password of the root account")
+                utils.set_root_password_in_image(qcow2_file,
+                                                 self.root_password)
         else:
             raise Exception("Unknown format:" + self.output_format)
 
@@ -112,6 +122,7 @@ class DockerSource(object):
         self.insecure = kwargs.get('not_secure', False)
         self.no_cache = kwargs.get('no_cache', False)
         self.use_sandbox = kwargs.get('use_sandbox', False)
+        self.root_password = kwargs.get('root_password', None)
         self.progress = kwargs['progress'].update_progress
         self.images_dir = utils.get_image_dir(self.no_cache)
         self.manifest = None
@@ -320,6 +331,13 @@ class DockerSource(object):
             raise
 
         else:
+
+            if self.root_password is not None:
+                logger.info("Setting password of the root account")
+                utils.set_root_password(self.output_format,
+                                        dest,
+                                        self.root_password)
+
             self.progress("Download and extract completed!", value=100,
                           logger=logger)
             logger.info("Files are stored in: " + dest)
@@ -349,6 +367,7 @@ class VirtBuilderSource(object):
         # - "virt-builder:/<template>"
         self.template = kwargs['uri'].netloc or kwargs['uri'].path[1:]
         self.output_format = kwargs.get('fmt', utils.DEFAULT_OUTPUT_FORMAT)
+        self.root_password = kwargs.get('root_password', None)
         self.progress = kwargs['progress'].update_progress
 
     def build_image(self, output_file):
diff --git a/src/virtBootstrap/virt_bootstrap.py b/src/virtBootstrap/virt_bootstrap.py
index b8c3e29..2081880 100755
--- a/src/virtBootstrap/virt_bootstrap.py
+++ b/src/virtBootstrap/virt_bootstrap.py
@@ -200,12 +200,9 @@ def bootstrap(uri, dest,
            not_secure=not_secure,
            no_cache=no_cache,
            progress=prog,
+           root_password=root_password,
            use_sandbox=use_sandbox).unpack(dest)
 
-    if root_password is not None:
-        logger.info("Setting password of the root account")
-        utils.set_root_password(fmt, dest, root_password)
-
     if fmt == "dir" and uid_map or gid_map:
         logger.info("Mapping UID/GID")
         mapping_uid_gid(dest, uid_map, gid_map)
-- 
2.9.4

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list



[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux