diff options
author | Radostin Stoyanov <rstoyanov1@gmail.com> | 2017-08-26 21:42:05 +0100 |
---|---|---|
committer | Radostin Stoyanov <rstoyanov1@gmail.com> | 2017-08-28 16:03:59 +0100 |
commit | 2bb76d45f14ae1bce4240bd3c1eeabcb44f663ac (patch) | |
tree | 6d73ffc3effffc67e3ae67f9908a08f3ca5ff436 /src/virtBootstrap/sources/file_source.py | |
parent | 7baf904cffdc4074ba5529b095f98a8c1ed6707a (diff) | |
download | virt-bootstrap.git-2bb76d45f14ae1bce4240bd3c1eeabcb44f663ac.tar.gz virt-bootstrap.git-2bb76d45f14ae1bce4240bd3c1eeabcb44f663ac.tar.xz virt-bootstrap.git-2bb76d45f14ae1bce4240bd3c1eeabcb44f663ac.zip |
Set root password with guestfs-python
Use the python bindings of libguestfs to create additional qcow2 image
which has as backing file the last layer (layer-0.qcow2 for FileSource)
and insert hashed value of given root password in the /etc/shadow file.
Note: This additional qcow2 image is also used to apply UID/GID map.
Diffstat (limited to 'src/virtBootstrap/sources/file_source.py')
-rw-r--r-- | src/virtBootstrap/sources/file_source.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/virtBootstrap/sources/file_source.py b/src/virtBootstrap/sources/file_source.py index b4b29ce..63dd4d2 100644 --- a/src/virtBootstrap/sources/file_source.py +++ b/src/virtBootstrap/sources/file_source.py @@ -43,12 +43,14 @@ class FileSource(object): @param fmt: Format used to store image [dir, qcow2] @param uid_map: Mappings for UID of files in rootfs @param gid_map: Mappings for GID of files in rootfs + @param root_password: Root password to set in rootfs @param progress: Instance of the progress module """ self.path = kwargs['uri'].path self.output_format = kwargs.get('fmt', utils.DEFAULT_OUTPUT_FORMAT) self.uid_map = kwargs.get('uid_map', []) self.gid_map = kwargs.get('gid_map', []) + self.root_password = kwargs.get('root_password', None) self.progress = kwargs['progress'].update_progress def unpack(self, dest): @@ -77,9 +79,16 @@ class FileSource(object): progress=self.progress ) img.create_base_layer() + img.set_root_password(self.root_password) if self.uid_map or self.gid_map: logger.info("Mapping UID/GID") - utils.map_id_in_image(1, dest, self.uid_map, self.gid_map) + utils.map_id_in_image( + 1, # Number of layers + dest, + self.uid_map, + self.gid_map, + (self.root_password is None) # Create new disk? + ) else: raise Exception("Unknown format:" + self.output_format) |