[master 7/8] livemedia-creator: Make --make-vagrant work with --no-virt

bcl installerbot-noreply at redhat.com
Wed Oct 21 00:59:22 UTC 2015


From: "Brian C. Lane" <bcl at redhat.com>

Also added a check to make sure the optional vagrant metadata.json file
actually exists, if passed.
---
 src/sbin/livemedia-creator | 36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/src/sbin/livemedia-creator b/src/sbin/livemedia-creator
index 08068e5..9f44c67 100755
--- a/src/sbin/livemedia-creator
+++ b/src/sbin/livemedia-creator
@@ -698,6 +698,7 @@ def novirt_install(opts, disk_img, disk_size, repo_url):
         if selinux_enforcing:
             selinux.security_setenforce(1)
 
+    # qcow2 is used by bare qcow2 images and by Vagrant
     if opts.qcow2:
         log.info("Converting %s to qcow2", disk_img)
         qcow2_args = []
@@ -709,13 +710,30 @@ def novirt_install(opts, disk_img, disk_size, repo_url):
             qcow2_args.extend(["-O", "qcow2"])
         qcow2_img = tempfile.mktemp(prefix="disk", suffix=".img")
         execWithRedirect("qemu-img", ["convert"] + qcow2_args + [disk_img, qcow2_img], raise_err=True)
-        execWithRedirect("mv", ["-f", qcow2_img, disk_img], raise_err=True)
-
-        if opts.make_vagrant:
-            pass
-
-            # tar the qcow2 file and optional json files
-
+        if not opts.make_vagrant:
+            execWithRedirect("mv", ["-f", qcow2_img, disk_img], raise_err=True)
+        else:
+            # Take the new qcow2 image and package it up for Vagrant
+            compress_args = []
+            for arg in opts.compress_args:
+                compress_args += arg.split(" ", 1)
+
+            vagrant_dir = tempfile.mkdtemp()
+            metadata_path = joinpaths(vagrant_dir, "metadata.json")
+            execWithRedirect("mv", ["-f", qcow2_img, joinpaths(vagrant_dir, "box.img")], raise_err=True)
+            if opts.vagrant_metadata:
+                shutil.copy2(opts.vagrant_metadata, metadata_path)
+            else:
+                create_vagrant_metadata(metadata_path)
+            update_vagrant_metadata(metadata_path, disk_size)
+            if opts.vagrantfile:
+                shutil.copy2(opts.vagrantfile, joinpaths(vagrant_dir, "vagrantfile"))
+
+            log.info("Creating Vagrant image")
+            rc = mktar(vagrant_dir, disk_img, opts.compression, compress_args, selinux=False)
+            if rc:
+                raise InstallError("novirt_install mktar failed: rc=%s" % rc)
+            shutil.rmtree(vagrant_dir)
     elif opts.make_tar:
         compress_args = []
         for arg in opts.compress_args:
@@ -850,6 +868,7 @@ def virt_install(opts, install_log, disk_img, disk_size):
         rc = mktar(vagrant_dir, disk_img, opts.compression, compress_args, selinux=False)
         if rc:
             raise InstallError("virt_install failed")
+        shutil.rmtree(vagrant_dir)
 
 
 def make_squashfs(disk_img, work_dir, compression="xz"):
@@ -1218,6 +1237,9 @@ def main():
     if opts.make_oci and not os.path.exists(opts.oci_runtime):
         errors.append("oci % file is missing" % opts.oci_runtime)
 
+    if opts.make_vagrant and opts.vagrant_metadata and not os.path.exists(opts.vagrant_metadata):
+        errors.append("Vagrant metadata file %s is missing" % opts.vagrant_metadata)
+
     if os.getuid() != 0:
         errors.append("You need to run this as root")
 


-- 
To view this commit on github, visit https://github.com/rhinstaller/lorax/commit/5a9ffebe7cae1034824407b1fb2da5015ded484d


More information about the anaconda-patches mailing list