Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Philippe Vanhaesendonck <philippe.vanhaesendonck@oracle.com>
- Loading branch information
1 parent
1298637
commit dfc9c00
Showing
6 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
oracle-linux-image-tools/cloud/vagrant-libvirt/env.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Default parameters for the vagrant-libvirt cloud. | ||
# Do NOT change anything in this file, customisation must be done in separate | ||
# env file. | ||
|
||
# Location of the vagrant libvirt create_box.sh script. | ||
# Install the vagrant-libvirt plugin on your build machine or download the | ||
# script from: | ||
# https://github.com/vagrant-libvirt/vagrant-libvirt/blob/master/tools/create_box.sh | ||
# VAGRANT_LIBVIRT_BOX_SCRIPT="${HOME}/.vagrant.d/gems/<vagrant version>/gems/vagrant-libvirt-<version>/tools/create_box.sh" | ||
|
||
# Memory and CPU to allocate to the box by default at runtime (default: use | ||
# build VM parameters) | ||
# VAGRANT_LIBVIRT_MEM_SIZE= | ||
# VAGRANT_LIBVIRT_CPU_NUM= | ||
|
||
# Install developer release packages (common to all providers) | ||
VAGRANT_DEVELOPER_REPOS="no" |
1 change: 1 addition & 0 deletions
1
oracle-linux-image-tools/cloud/vagrant-libvirt/files/vagrant-common.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../vagrant-virtualbox/files/vagrant-common.sh |
74 changes: 74 additions & 0 deletions
74
oracle-linux-image-tools/cloud/vagrant-libvirt/image-scripts.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Cleanup and package image for the "vagrant-libvirt" image | ||
# | ||
# Copyright (c) 2020 Oracle and/or its affiliates. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at | ||
# https://oss.oracle.com/licenses/upl. | ||
# | ||
# Description: this module provides 2 functions: | ||
# cloud::image_cleanup: cloud specific actions to cleanup the image | ||
# This function is optional | ||
# cloud::image_package: Package the raw image for the target cloud. | ||
# This function must be defined either at cloud or cloud/distribution level | ||
# | ||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | ||
# | ||
|
||
####################################### | ||
# Parameter validation | ||
# Globals: | ||
# VAGRANT_LIBVIRT_BOX_SCRIPT | ||
# Arguments: | ||
# None | ||
# Returns: | ||
# None | ||
####################################### | ||
cloud::validate() { | ||
[[ -n ${VAGRANT_LIBVIRT_BOX_SCRIPT} && -x ${VAGRANT_LIBVIRT_BOX_SCRIPT} ]] || error "missing vagrant box_create script" | ||
[[ ${VAGRANT_LIBVIRT_CPU_NUM} =~ ^[0-9]*$ ]] || error "vagrant cpu count is not numeric" | ||
[[ ${VAGRANT_LIBVIRT_MEM_SIZE} =~ ^[0-9]*$ ]] || error "vagrant memory is not numeric" | ||
[[ ${VAGRANT_DEVELOPER_REPOS,,} =~ ^(yes)|(no)$ ]] || error "VAGRANT_DEVELOPER_REPOS must be Yes or No" | ||
} | ||
|
||
####################################### | ||
# Cleanup actions run directly on the image | ||
# Globals: | ||
# None | ||
# Arguments: | ||
# root filesystem directory | ||
# boot filesystem directory | ||
# Returns: | ||
# None | ||
####################################### | ||
cloud::image_cleanup() { | ||
: | ||
} | ||
|
||
####################################### | ||
# Image packaging: generate box using vagrant tool | ||
# Globals: | ||
# VM_NAME | ||
# Arguments: | ||
# None | ||
# Returns: | ||
# None | ||
####################################### | ||
cloud::image_package() { | ||
local cpus="${VAGRANT_LIBVIRT_CPU_NUM:-$CPU_NUM}" | ||
local memory="${VAGRANT_LIBVIRT_MEM_SIZE:-$MEM_SIZE}" | ||
|
||
# Convert to qcow2 | ||
qemu-img convert -c -O qcow2 System.img "${VM_NAME}.qcow" | ||
rm System.img | ||
|
||
# Defaults for the box | ||
cat > Vagrantfile <<-EOF | ||
config.vm.provider :libvirt do |libvirt| | ||
libvirt.memory = ${memory} | ||
libvirt.cpus = ${cpus} | ||
end | ||
EOF | ||
${VAGRANT_LIBVIRT_BOX_SCRIPT} "${VM_NAME}.qcow" "${VM_NAME}.box" Vagrantfile | ||
rm "${VM_NAME}.qcow" Vagrantfile | ||
} |
76 changes: 76 additions & 0 deletions
76
oracle-linux-image-tools/cloud/vagrant-libvirt/provision.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Packer provisioning script for Vagrant-libvirt | ||
# | ||
# Copyright (c) 2020 Oracle and/or its affiliates. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at | ||
# https://oss.oracle.com/licenses/upl. | ||
# | ||
# Description: Vagrant specific provisioning. This module provides 2 functions, | ||
# both are optional. | ||
# cloud::provision: provision the instance | ||
# cloud::cleanup: instance cleanup before shutdown | ||
# | ||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | ||
# | ||
|
||
# Load vagrant common scripts | ||
source /tmp/packer_files/cloud/vagrant-common.sh | ||
|
||
####################################### | ||
# Configure Vagrant instance | ||
# Globals: | ||
# None | ||
# Arguments: | ||
# None | ||
# Returns: | ||
# None | ||
####################################### | ||
cloud::config() | ||
{ | ||
vagrant::config | ||
} | ||
|
||
####################################### | ||
# Install NFS client (needed for shared /vagrant folder) | ||
# Globals: | ||
# YUM_VERBOSE | ||
# Arguments: | ||
# None | ||
# Returns: | ||
# None | ||
####################################### | ||
cloud::install_agent() | ||
{ | ||
echo_message "Install NFS client" | ||
yum install -y ${YUM_VERBOSE} nfs-utils | ||
} | ||
|
||
####################################### | ||
# Provisioning module | ||
# Globals: | ||
# None | ||
# Arguments: | ||
# None | ||
# Returns: | ||
# None | ||
####################################### | ||
cloud::provision() | ||
{ | ||
cloud::install_agent | ||
cloud::config | ||
} | ||
|
||
####################################### | ||
# Cleanup module | ||
# Globals: | ||
# None | ||
# Arguments: | ||
# None | ||
# Returns: | ||
# None | ||
####################################### | ||
cloud::cleanup() | ||
{ | ||
vagrant::cleanup | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters