diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-08-29 14:11:21 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-08-29 14:11:21 +0200 |
commit | 4234a2882f0812be37721b6b7a58156260d52379 (patch) | |
tree | 9394eba47021a7050c7764b7fed0689d5a15b6fa /grid5000/steps/export | |
download | grid5k-4234a2882f0812be37721b6b7a58156260d52379.tar.gz grid5k-4234a2882f0812be37721b6b7a58156260d52379.tar.bz2 grid5k-4234a2882f0812be37721b6b7a58156260d52379.zip |
initial import
Diffstat (limited to 'grid5000/steps/export')
-rw-r--r-- | grid5000/steps/export/debian/clean_dhcp_leases.yaml | 2 | ||||
-rw-r--r-- | grid5000/steps/export/do_qcow2_finish_works.yaml | 44 | ||||
-rw-r--r-- | grid5000/steps/export/export_g5k.yaml | 84 | ||||
-rw-r--r-- | grid5000/steps/export/export_vagrant_box.yaml | 42 | ||||
-rw-r--r-- | grid5000/steps/export/save_appliance_VM.yaml | 23 |
5 files changed, 195 insertions, 0 deletions
diff --git a/grid5000/steps/export/debian/clean_dhcp_leases.yaml b/grid5000/steps/export/debian/clean_dhcp_leases.yaml new file mode 100644 index 0000000..85ee860 --- /dev/null +++ b/grid5000/steps/export/debian/clean_dhcp_leases.yaml @@ -0,0 +1,2 @@ +- clean_dhcp_leases: + - exec_local: virt-customize -a $${image_disk}.$${image_format} --run-command "rm -rf /var/lib/dhcp/*" diff --git a/grid5000/steps/export/do_qcow2_finish_works.yaml b/grid5000/steps/export/do_qcow2_finish_works.yaml new file mode 100644 index 0000000..be80e25 --- /dev/null +++ b/grid5000/steps/export/do_qcow2_finish_works.yaml @@ -0,0 +1,44 @@ +# Install cloud_init in qcow2 output file (tarball must be exported beforehand, in order to not include cloud_init) +- install_cloud_init: + - exec_local: | + if [[ "$${appliance_formats}" =~ "qcow2" ]]; then + echo "Install cloud_init in qcow2" + # First unset any proxy variable (set to http://127.0.0.1:8000 if kameleon's cache is enabled) so that virt-customise works ok + (for e in $(env | grep -i _proxy); do unset ${e%%=*}; done; virt-customize -a $${output}.qcow2 --install cloud-init) + echo "Configure datasource and timeout for cloud_init" + virt-customize -a $${output}.qcow2 --run-command 'printf "datasource_list: [ NoCloud, Ec2, None ]\n" > /etc/cloud/cloud.cfg.d/91-set-datasources.cfg' + virt-customize -a $${output}.qcow2 --run-command 'printf "datasource:\n Ec2:\n timeout: 3\n max_wait: -1\n" > /etc/cloud/cloud.cfg.d/92-set-ec2-timeout.cfg' + # Remove DHCP hook to let cloud-init handle hostname + virt-customize -a $${output}.qcow2 --run-command 'rm -f /etc/dhcp/dhclient-exit-hooks.d/g5k-update-host-name' + else + echo "No qcow2 export, nothing to do." + fi + +- fix_interface_name: + - exec_local: | + if [[ "$${appliance_formats}" =~ "qcow2" && "$${distrib}" == "debian" ]]; then + virt-customize -a $${output}.qcow2 --run-command 'sed -i s/ens3/enp0s2/ /etc/network/interfaces' + else + echo "Nothing to do." + fi + +- setup_uefi_boot: + - exec_local: | + if [[ "$${qemu_uefi}" == "true" ]] && [[ "$${arch}" == "aarch64" ]] && [[ "$${appliance_formats}" =~ "qcow2" ]]; then + echo "Setting up ARM64 UEFI boot for qcow2 image" + virt-customize \ + -a $${output}.qcow2 \ + --run-command 'if ! [ -e /boot/efi/EFI/BOOT/BOOTAA64.EFI ]; then mkdir -p /boot/efi/EFI/BOOT ; cp /boot/efi/EFI/$${distrib}/grubaa64.efi /boot/efi/EFI/BOOT/BOOTAA64.EFI; fi' + else + echo "Nothing to do." + fi + +- sparsify_qcow2_image: + - exec_local: | + if [[ "$${appliance_formats}" =~ "qcow2" ]]; then + echo "Compress and reduce qcow2 size" + virt-sparsify --compress $${output}.qcow2 $${output}.qcow2.sparsed + mv -f $${output}.qcow2.sparsed $${output}.qcow2 + else + echo "No qcow2 export, nothing to do." + fi diff --git a/grid5000/steps/export/export_g5k.yaml b/grid5000/steps/export/export_g5k.yaml new file mode 100644 index 0000000..04b1358 --- /dev/null +++ b/grid5000/steps/export/export_g5k.yaml @@ -0,0 +1,84 @@ +# Generate a dsc file as used on grid'5000 by kaenv + +- dashes: "---" # kameleon eats my dash if I don't use this dirty hack :-( +- g5k_version: "unknown" +- g5k_kernel_path: "/vmlinuz" +- g5k_initrd_path: "/initrd.img" +- g5k_filesystem: "ext4" +- g5k_author: "support-staff@lists.grid5000.fr" +- g5k_visibility: "public" +- g5k_destructive: "false" +- g5k_tar_compression: "gzip" +- g5k_postinst_compression: "gzip" + +# - save_as_tgz: +# - check_cmd_local: guestfish +# - check_cmd_local: gzip +# - exec_local: echo "Exporting appliance to $${output}.tgz" +# - exec_local: mkdir -p $${kameleon_cwd}/.mnt +# - exec_local: LIBGUESTFS_CACHEDIR=$${kameleon_cwd} guestmount --ro -i -a $${input} $${kameleon_cwd}/.mnt +# - exec_local: LIBGUESTFS_CACHEDIR=$${kameleon_cwd} tar -cf $${output}.tgz --gzip --numeric-owner --selinux --acls --xattrs -C $${kameleon_cwd}/.mnt . +# - exec_local: LIBGUESTFS_CACHEDIR=$${kameleon_cwd} guestunmount $${kameleon_cwd}/.mnt +# - exec_local: rmdir $${kameleon_cwd}/.mnt + +- generate_dsc: + - exec_local: echo "Creating description file for kaenv in $${output}.dsc" + - exec_local: | + if [[ "x$${g5k_variant}" != "xxen" ]]; then + cat << EOF > $${output}.dsc + $${dashes} + name: $${kameleon_recipe_name} + version: $${g5k_version} + description: $${distrib} $${release_number} ($${release}) for $${g5k_image_arch} - $${g5k_variant} + author: $${g5k_author} + visibility: $${g5k_visibility} + destructive: $${g5k_destructive} + os: linux + image: + file: $${g5k_tar_path} + kind: tar + compression: $${g5k_tar_compression} + postinstalls: + - archive: $${g5k_postinst_path} + compression: $${g5k_postinst_compression} + script: $${g5k_postinst_script} + boot: + kernel_params: "$${g5k_kernel_params}" + kernel: $${g5k_kernel_path} + initrd: $${g5k_initrd_path} + filesystem: $${g5k_filesystem} + partition_type: 131 + multipart: false + EOF + else + cat << EOF > $${output}.dsc + $${dashes} + name: $${kameleon_recipe_name} + version: $${g5k_version} + description: $${distrib} $${release_number} ($${release}) for $${g5k_image_arch} - $${g5k_variant} + author: $${g5k_author} + visibility: $${g5k_visibility} + destructive: $${g5k_destructive} + os: xen + image: + file: $${g5k_tar_path} + kind: tar + compression: $${g5k_tar_compression} + postinstalls: + - archive: $${g5k_postinst_path} + compression: $${g5k_postinst_compression} + script: $${g5k_postinst_script} + boot: + kernel_params: "$${g5k_kernel_params}" + kernel: $${g5k_kernel_path} + initrd: $${g5k_initrd_path} + hypervisor: /hypervisor + hypervisor_params: "dom0_mem=4096M no-bootscrub" + filesystem: $${g5k_filesystem} + partition_type: 131 + multipart: false + EOF + fi + +- generate_md5: + - exec_local: md5sum $${kameleon_recipe_name}.* > $${kameleon_recipe_name}.md5 diff --git a/grid5000/steps/export/export_vagrant_box.yaml b/grid5000/steps/export/export_vagrant_box.yaml new file mode 100644 index 0000000..6c048ef --- /dev/null +++ b/grid5000/steps/export/export_vagrant_box.yaml @@ -0,0 +1,42 @@ +- virtualbox_vmid: $${kameleon_recipe_name}_$${kameleon_short_uuid} +- virtualbox_disk_filename: $${appliance_filename}.$${appliance_formats} +- virtualbox_os_type: "Debian_64" +- vagrant_box_filename: $${kameleon_cwd}/$${kameleon_recipe_name}.box + +- create_vbox_machine: + - on_export_clean: + - exec_local: | + if VBoxManage list vms | grep -q $${virtualbox_vmid}; then + echo "Deleting VBox machine $${virtualbox_vmid}" + VBoxManage unregistervm $${virtualbox_vmid} --delete + fi + - exec_local: | + if [ -e $${virtualbox_disk_filename} ]; then + echo "Deleting disk file $${virtualbox_disk_filename}" + rm $${virtualbox_disk_filename} + fi + - exec_local: echo "Creating VBox machine $${virtualbox_vmid}" + - exec_local: VBoxManage createvm --name $${virtualbox_vmid} --register + - exec_local: VBoxManage modifyvm $${virtualbox_vmid} --ostype $${virtualbox_os_type} + - exec_local: VBoxManage modifyvm $${virtualbox_vmid} --boot1 disk + - exec_local: VBoxManage modifyvm $${virtualbox_vmid} --memory 256 + - exec_local: VBoxManage modifyvm $${virtualbox_vmid} --acpi on + - exec_local: VBoxManage modifyvm $${virtualbox_vmid} --nictype1 82540EM + - exec_local: VBoxManage modifyvm $${virtualbox_vmid} --nictype2 82540EM + - exec_local: VBoxManage modifyvm $${virtualbox_vmid} --nictype3 82540EM + - exec_local: VBoxManage modifyvm $${virtualbox_vmid} --nictype4 82540EM + - exec_local: VBoxManage modifyvm $${virtualbox_vmid} --nic1 nat --cableconnected1 on + - exec_local: VBoxManage storagectl $${virtualbox_vmid} --name "SATA Controller" --add sata --controller IntelAHCI --hostiocache on + - exec_local: | + VBoxManage storageattach $${virtualbox_vmid} \ + --storagectl "SATA Controller" \ + --port 0 \ + --device 0 \ + --type hdd \ + --medium $${virtualbox_disk_filename} + +- save_box: + - check_cmd_local: vagrant + - exec_local: echo "Create vagrant box $${vagrant_box_filename}..." + - exec_local: rm -f $${vagrant_box_filename} + - exec_local: vagrant package --base $${virtualbox_vmid} --output $${vagrant_box_filename} diff --git a/grid5000/steps/export/save_appliance_VM.yaml b/grid5000/steps/export/save_appliance_VM.yaml new file mode 100644 index 0000000..b064d02 --- /dev/null +++ b/grid5000/steps/export/save_appliance_VM.yaml @@ -0,0 +1,23 @@ +# +# Save Appliance from virtual machine +# +- export_appliance_script: $${kameleon_data_dir}/helpers/export_appliance.py + +# Zero free unallocated blocks from ext2/3 file-systems before export to +# reduce image size +- zerofree: true + +- save_appliance: + - check_cmd_local: python2 + - exec_local: | + if [ "$${zerofree}" = "true" ]; then + EXPORT_OPTS="--zerofree" + else + EXPORT_OPTS="" + fi + - exec_local: | + python2 $${export_appliance_script} $${image_disk}.$${image_format} \ + -o $${appliance_filename} \ + --formats $${appliance_formats} \ + --tar-compression-level $${appliance_tar_compression_level} \ + --tar-excludes $${appliance_tar_excludes} $EXPORT_OPTS |