diff --git a/iso/empanadas/empanadas/scripts/build_image.py b/iso/empanadas/empanadas/scripts/build_image.py index c889c21..3ee5427 100644 --- a/iso/empanadas/empanadas/scripts/build_image.py +++ b/iso/empanadas/empanadas/scripts/build_image.py @@ -147,25 +147,25 @@ class ImageBuild: if self.image_type in ["Vagrant"]: _map = { "Vbox": {"format": "vmdk", "provider": "virtualbox"}, - "Libvirt": {"format": "qcow2", "provider": "libvirt"}, - "VMware": {"format": "vmdk", "convertOptions": ["-o", "subformat=streamOptimized"], "provider": "vmware_desktop"} + "Libvirt": {"format": "qcow2", "provider": "libvirt", "virtual_size": 10}, + "VMware": {"format": "vmdk", "provider": "vmware_desktop"} } output = f"{_map[self.variant]['format']}" #type: ignore options = _map[self.variant]['convertOptions'] if 'convertOptions' in _map[self.variant].keys() else '' #type: ignore provider = f"{_map[self.variant]['provider']}" # type: ignore - self.prepare_vagrant(provider) self.stage_commands = [ ["qemu-img", "convert", "-c", "-f", "raw", "-O", output, *options, lambda: f"{STORAGE_DIR}/{self.target_uuid}.body", f"{self.outdir}/{self.outname}.{output}"], ["tar", "-C", self.outdir, "-czf", f"/tmp/{self.outname}.box", '.'], ["mv", f"/tmp/{self.outname}.box", self.outdir] ] + self.prepare_vagrant(_map[self.variant]) if self.stage_commands: self.stage_commands.append(["cp", "-v", lambda: f"{STORAGE_DIR}/{self.target_uuid}.meta", f"{self.outdir}/build.meta"]) - def prepare_vagrant(self, provider): + def prepare_vagrant(self, options): """Setup the output directory for the Vagrant type variant, dropping templates as required""" file_loader = FileSystemLoader(f"{_rootdir}/templates") tmplenv = Environment(loader=file_loader) @@ -179,11 +179,17 @@ class ImageBuild: provider = "vmware_desktop" templates[f"{self.outname}.vmx"] = tmplenv.get_template('vagrant/vmx.tmpl') + + if self.variant == "Libvirt": + # Libvirt vagrant driver expects the qcow2 file to be called box.img. + qemu_command_index = [i for i, d in enumerate(self.stage_commands) if d[0] == "qemu-img"][0] + self.stage_commands.insert(qemu_command_index+1, ["mv", f"{self.outdir}/{self.outname}.qcow2", f"{self.outdir}/box.img"]) + for name, template in templates.items(): - print(name, template) self.render_template(f"{self.outdir}/{name}", template, name=self.outname, - provider=provider + arch=self.architecture.name, + options=options ) def checkout_kickstarts(self) -> int: diff --git a/iso/empanadas/empanadas/templates/vagrant/Vagrantfile.Libvirt b/iso/empanadas/empanadas/templates/vagrant/Vagrantfile.Libvirt index e69de29..4f08f79 100644 --- a/iso/empanadas/empanadas/templates/vagrant/Vagrantfile.Libvirt +++ b/iso/empanadas/empanadas/templates/vagrant/Vagrantfile.Libvirt @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + + # Example configuration of new VM.. + # + #config.vm.define :test_vm do |test_vm| + # Box name + # + #test_vm.vm.box = "rockylinux" + + # Domain Specific Options + # + # See README for more info. + + # Interfaces for VM + # + # Networking features in the form of `config.vm.network` + # + #test_vm.vm.network :private_network, :ip => '10.20.30.40' + #test_vm.vm.network :public_network, :ip => '10.20.30.41' + #end + + # Options for Libvirt Vagrant provider. + config.vm.provider :libvirt do |libvirt| + + # A hypervisor name to access. Different drivers can be specified, but + # this version of provider creates KVM machines only. Some examples of + # drivers are KVM (QEMU hardware accelerated), QEMU (QEMU emulated), + # Xen (Xen hypervisor), lxc (Linux Containers), + # esx (VMware ESX), vmwarews (VMware Workstation) and more. Refer to + # documentation for available drivers (http://libvirt.org/drivers.html). + libvirt.driver = "kvm" + + # The name of the server, where Libvirtd is running. + # libvirt.host = "localhost" + + # If use ssh tunnel to connect to Libvirt. + libvirt.connect_via_ssh = false + + # The username and password to access Libvirt. Password is not used when + # connecting via ssh. + libvirt.username = "root" + #libvirt.password = "secret" + + # Libvirt storage pool name, where box image and instance snapshots will + # be stored. + libvirt.storage_pool_name = "default" + + # Set a prefix for the machines that's different than the project dir name. + #libvirt.default_prefix = '' + end +end diff --git a/iso/empanadas/empanadas/templates/vagrant/box.tmpl.ovf b/iso/empanadas/empanadas/templates/vagrant/box.tmpl.ovf new file mode 100644 index 0000000..b0e76e3 --- /dev/null +++ b/iso/empanadas/empanadas/templates/vagrant/box.tmpl.ovf @@ -0,0 +1,109 @@ + + + + + + + List of the virtual disks used in the package + + + + A virtual machine + + The kind of installed guest operating system + RedHat_64 + RedHat_64 + + + Virtual hardware requirements for a virtual machine + + Virtual Hardware Family + 0 + rockylinux-{{ arch }} + virtualbox-2.2 + + + 2 virtual CPU + Number of virtual CPUs + 2 virtual CPU + 1 + 3 + 2 + + + MegaBytes + 8192 MB of memory + Memory Size + 8192 MB of memory + 2 + 4 + 8192 + + + 0 + ideController0 + IDE Controller + ideController0 + 3 + PIIX4 + 5 + + + 1 + ideController1 + IDE Controller + ideController1 + 4 + PIIX4 + 5 + + + 0 + disk1 + Disk Image + disk1 + /disk/vmdisk1 + 5 + 3 + 17 + + + + Complete VirtualBox machine configuration in VirtualBox format + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iso/empanadas/empanadas/templates/vagrant/metadata.tmpl.json b/iso/empanadas/empanadas/templates/vagrant/metadata.tmpl.json index 7674c26..254cad1 100644 --- a/iso/empanadas/empanadas/templates/vagrant/metadata.tmpl.json +++ b/iso/empanadas/empanadas/templates/vagrant/metadata.tmpl.json @@ -1,3 +1 @@ -{ - "provider": "{{ provider }}" -} +{{ options | tojson(indent=2 )}}