leonidlm / packer-builder-softlayer

A builder plugin for packer.io for a SoftLayer cloud
MIT License
38 stars 32 forks source link

SoftLayer Builder (for packer.io)

The softlayer builder is able to create new images for use with SoftLayer. The builder takes a source image (identified by it's global ID or reference name), runs any provisioning necessary on the image after launching it, then snapshots it into a reusable image. This reusable image can then be used as the foundation of new servers that are launched within SoftLayer.

The builder does not manage images. Once it creates an image, it is up to you to use it or delete it.

Install

Download the Packer binaries here or build Packer from source as described here.

Next, clone this repository into $GOPATH/src/github.com/leonidlm/packer-builder-softlayer. Then build the packer-softlayer-builder binary into the same folder as the packer binaries:

cd $GOPATH/src/github.com/leonidlm/packer-builder-softlayer
go build -o /usr/local/packer/packer-builder-softlayer main.go

Packer should automatically detect the plugin.

Basic Example

The example below is fully functional and will create a basic centos 6 image with dnsmasq installed (only the __api_key and username__ are missing):

{
  "provisioners": [
    {
      "type": "shell",
      "inline": [
        "sudo yum install -y dnsmasq"
      ]
    }
  ],
  "builders": [{
    "type": "softlayer",
    "api_key": "",
    "username": "",
    "datacenter_name": "ams01",
    "base_os_code": "CENTOS_6_64",
    "image_name": "packer-centos-{{isotime}}",
    "image_description": "centos image created by packer at {{isotime}}",
    "image_type": "flex",
    "instance_name": "packer-centos-{{isotime}}",
    "instance_domain": "provisioning.com",
    "instance_cpu": 1,
    "instance_memory": 1024,
    "instance_network_speed": 10,
    "instance_disk_capacity": 25,
    "ssh_port": 22,
    "ssh_timeout": "15m",
    "instance_state_timeout": "25m"
  }]
}

If you are willing to use your own image as your starting point, you can specify base_image_id instead of base_os_code.

Configuration Reference

The reference of available configuration options is listed below.

Required parameters:

 curl https://<username>:<api_key>@api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualDiskImages.json
 curl https://<username>:<api_key>@api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/getCreateObjectOptions.json | grep operatingSystemReferenceCode

Optional parameters:

As already stated above, a good way of reviewing the available options is by inspecting the output of the following API call:

 curl https://<username>:<api_key>@api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/getCreateObjectOptions.json

Contribute

New contributors are always welcome! When in doubt please feel free to ask questions, just Create an issue with your enquiries.

Development Environment

The Vagrantfile creates a development environment with Go and packer checked out and built. Type "vagrant up" to bring up the environment and then "vagrant ssh" to log in. The packer-builder-softlayer directory on the host is shared to the guest VM, and packer-builder-softalyer is built during "vagrant up". The SL_USERNAME and SL_API_KEY environment variables from your host machine are propagated to the VM.

To run the unit tests, execute "go test ./..." from the root project directory.

TODO