xenserverarmy / packer

A builder plugin for Packer to support building XenServer images.
Mozilla Public License 2.0
18 stars 8 forks source link

XenServer Packer builder and post-processors

The builder plugin extends packer to support building images for XenServer. The post-processor plug extends packer to support registration of XenServer images within various providers (Apache CloudStack for the moment)

You can check out packer here.

Dependencies

Install Go

Follow these instructions and install golang on your system:

Install Packer

Follow the directions and install packer on your system:

Note that if you're upgrading from a version of packer prior to 0.9.0, you must remove the packer-* files lest things get confused.

Important: CentOS 7 and RHEL 7 both have a symlink for packer. The symlink points to cracklib-packer, and you're probably going to want to keep that as is.

To keep things simple, in the examples below, the packer binary has been fully qualified with $GOPATH/bin since I installed packer to that location. Please adjust as your requirements dictate.

Compile the plugin

Once you have installed Packer, you must compile this plugin and install the resulting binary.

cd $GOPATH
mkdir -p src/github.com/xenserverarmy/
cd src/github.com/xenserverarmy
git clone https://github.com/xenserverarmy/packer.git
cd packer
./build.sh

If the build is successful, you should now have packer-builder-xenserver-iso and packer-builder-xenserver-xva binaries in your $GOPATH/bin directory and you are ready to get going with packer; skip to the CentOS 7 example below.

In order to do a cross-compile, run instead:

XC_OS="windows linux" XC_ARCH="386 amd64" ./build.sh

This builds 32 and 64 bit binaries for both Windows and Linux. Native binaries will be installed in $GOPATH/bin as above, and cross-compiled ones in the pkg/ directory.

Don't forget to also cross compile Packer, by running

XC_OS="windows linux" XC_ARCH="386 amd64" make bin

(instead of make dev) in the directory where you checked out Packer.

CentOS 7 Builder Example

Once you've setup the above, you are good to go with an example.

To get you started, there is an example config file which you can use: examples/centos-7.json

The example is functional, once suitable remote_host, remote_username and remote_password configurations have been substituted.

A brief explanation of what the config parameters mean:

Once you've updated the config file with your own parameters, you can use packer to build this VM with the following command:

$GOPATH/bin/packer build ./examples/centos-7.json

CentOS 7 Builder from running VM Example

The idea behind using a running VM as a starting point is to test patching/conversion of existing infrastructure; without incurring downtime. Using this builder, you can clone, perform the tests on the clone until satisfied, and then apply them. Source VM experiences no downtime, and there is no machine collision (if you pay attention).

To facilitate this process, the clone is launched on an internal network and then basic commands (contained in boot_command) are executed to provide a clean network which is then used to copy in packer_clean.sh from the script location. You modify that script to do what you need to make your VM unique, and then have it perform a shutdown. The remaining work you'd want to do to make the patch/update/convert/process/whatever the Vm is done using Packer Provisioners.

To get you started, there is an example config file which you can use: examples/centos-7vm.json

The example is functional, once suitable remote_host, remote_username and remote_password configurations have been substituted.

A brief explanation of what the config parameters mean:

Once you've updated the config file with your own parameters, you can use packer to build this VM with the following command:

$GOPATH/bin/packer build ./examples/centos-7vm.json

Apache CloudStack Post-processor Example with CentOS 7

Once you've setup the above, you are good to go with an example.

To get you started, there is an example config file which you can use: examples/centos-7acs.json

The builder parameters are described in the CentOS 7 builder example.

This example is functional, once suitable apiurl, apikey and secret configurations have been substituted.

A brief explanation of what the config parameters mean:

Once you've updated the config file with your own parameters, you can use packer to build this VM, and upload it to your CloudStack instance with the following command:

$GOPATH/bin/packer build ./examples/centos-7acs.json

Testing

This code was built on CentOS 7 and has been tested with a stock XenServer 6.5 and Apache CloudStack 4.3. There is no known limitation which would prevent its use with XenServer 6.2, or other Linux variants. The post-processor uses stable CloudStack APIs which should allow for its use on most CloudStack versions.