[PATCH] Add "real" Vagrant format options to image building.

Ian McLeod imcleod at redhat.com
Thu Apr 9 03:37:16 UTC 2015


We originally added Vagrant support by tweaking options sent
to the existing RHEV-M and vSphere OVA generation code.  This was
a bit of a hack and resulted in confusing filenames.

This adds "vagrant-libvirt" and "vagrant-virtualbox" image types,
passes in the correct options to Image Factory and produces output
files with the conventional ".box" extension and more descriptive
and less confusing vagrant name suffixes.
---
 builder/kojid   | 20 +++++++++++++++++++-
 cli/koji        |  2 +-
 docs/schema.sql |  1 +
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/builder/kojid b/builder/kojid
index 3df0588..e460ccc 100755
--- a/builder/kojid
+++ b/builder/kojid
@@ -3051,7 +3051,7 @@ class BaseImageTask(OzImageTask):
         Some image formats require others to be processed first, which is why
         we have to do this. raw files in particular may not be kept.
         """
-        supported = ('raw', 'raw-xz', 'vmdk', 'qcow', 'qcow2', 'vdi', 'rhevm-ova', 'vsphere-ova', 'docker')
+        supported = ('raw', 'raw-xz', 'vmdk', 'qcow', 'qcow2', 'vdi', 'rhevm-ova', 'vsphere-ova', 'docker', 'vagrant-virtualbox', 'vagrant-libvirt')
         for f in formats:
             if f not in supported:
                 raise koji.ApplianceError('Invalid format: %s' % f)
@@ -3083,6 +3083,8 @@ class BaseImageTask(OzImageTask):
                   'qcow2': self._buildConvert,
                   'rhevm-ova':   self._buildOVA,
                   'vsphere-ova': self._buildOVA,
+                  'vagrant-virtualbox': self._buildOVA,
+                  'vagrant-libvirt':    self._buildOVA,
                   'docker':      self._buildDocker
         }
         # add a handler to the logger so that we capture ImageFactory's logging
@@ -3221,6 +3223,17 @@ class BaseImageTask(OzImageTask):
         img_opts = {}
         if self.opts.get('ova_option'):
             img_opts = dict([o.split('=') for o in self.opts.get('ova_option')])
+        # As far as Image Factory is concerned, vagrant boxes are just another type of OVA
+        # We communicate the desire for vagrant-specific formatting by adding the *_ova_format
+        # options and turning the underlying format option back into one of the two target
+        # image types ('vsphere-ova' or 'rhevm-ova') that are used to generate the intermediate
+        # disk image
+        if format == 'vagrant-virtualbox':
+            format = 'vsphere-ova'
+            img_opts['vsphere_ova_format'] = 'vagrant-virtualbox'
+        if format == 'vagrant-libvirt':
+            format = 'rhevm-ova'
+            img_opts['rhevm_ova_format'] = 'vagrant-libvirt'
         targ = self._do_target_image(self.base_img.base_image.identifier,
             format.replace('-ova', ''))
         targ2 = self._do_target_image(targ.target_image.identifier, 'OVA',
@@ -3381,6 +3394,11 @@ class BaseImageTask(OzImageTask):
             newimg = images[format]['image']
             if 'ova' in format or format == 'raw-xz':
                 newname = self.imgname + '.' + format.replace('-', '.')
+            elif 'vagrant' in format:
+                # This embeds the vagrant target and the ".box" format in the name
+                # Previously, based on filename, these looked like OVAs
+                # This was confusing to many people
+                newname = self.imgname + '.' + format + '.box'
             elif format == 'docker':
                 newname = self.imgname + '.' + 'tar.xz'
             else:
diff --git a/cli/koji b/cli/koji
index bfb0955..473bcb8 100755
--- a/cli/koji
+++ b/cli/koji
@@ -5243,7 +5243,7 @@ def _build_image_indirection(options, task_opts, session, args):
 def handle_image_build(options, session, args):
     """Create a disk image given an install tree"""
     formats = ('vmdk', 'qcow', 'qcow2', 'vdi', 'rhevm-ova', 'vsphere-ova',
-               'docker', 'raw-xz')
+               'vagrant-virtualbox', 'vagrant-libvirt', 'docker', 'raw-xz')
     usage = _("usage: %prog image-build [options] <name> <version> " +
               "<target> <install-tree-url> <arch> [<arch>...]")
     usage += _("\n       %prog image-build --config FILE")
diff --git a/docs/schema.sql b/docs/schema.sql
index c087d56..ffe9b22 100644
--- a/docs/schema.sql
+++ b/docs/schema.sql
@@ -736,6 +736,7 @@ insert into archivetypes (name, description, extensions) values ('so', 'Shared l
 insert into archivetypes (name, description, extensions) values ('txt', 'Text file', 'txt');
 insert into archivetypes (name, description, extensions) values ('vhd', 'Hyper-V image', 'vhd');
 insert into archivetypes (name, description, extensions) values ('wsf', 'Windows script file', 'wsf');
+insert into archivetypes (name, description, extensions) values ('box', 'Vagrant Box Image', 'box');
 
 
 -- Do we want to enforce a constraint that a build can only generate one
-- 
2.1.0



More information about the buildsys mailing list