README ¶
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.
Changes
- It's now possible to specify multiple disks for the instance, not just one.
- README.md updated to include instructions to compile it with recent versions of Go and packer.
Install
Build Packer from source as described here.
Packer started vendoring some packages and you cannot compile packer-builder-softlayer without some changes. The changes required are the following:
Install godep
tool:
go get github.com/tools/godep
Change to the packer source directory:
cd /home/user/Go/github.com/mitchellh/packer
Unvendor the packages:
godep restore
This will take some time to redownload all packages from various sources.
Next, clone this repository into $GOPATH/src/github.com/stunndard/packer-builder-softlayer
.
Then build the packer-softlayer-builder binary into the same folder as the packer binary.
For example, if you installed packer to /usr/local/bin
, do the following:
cd $GOPATH/src/github.com/stunndard/packer-builder-softlayer
go build -o /usr/local/bin/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_disks_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:
username
(string) - The user name to use to access your account. If unspecified, the value is taken from the SOFTLAYER_USER_NAME environment variable.api_key
(string) - The api key defined for the chosen user name. You can find what is your api key at the account->users tab of the SoftLayer web console. If unspecified, the value is taken from the SOFTLAYER_API_KEY environment variable.image_name
(string) - The name of the resulting image that will appear in your account. This must be unique. To help make this unique, use a function like timestamp.base_image_id
(string) - The ID of the base image to use (usually defined by theglobalIdentifier
or theuuid
fields in SoftLayer API). This is the image that will be used for laun ching a new instance. NOTE that if you choose to use this option, you must specify a private key usingssh_private_key_file
(described below). To view all of your currently available images, run:
curl https://<username>:<api_key>@api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualDiskImages.json
base_os_code
(string) - If you would like to start from a pre-installed SoftLayer OS image, you can specify it's reference code. NOTE that you can use only one ofbase_image_id
orbase_os_code
per builder configuration. To view all of the currently available pre-installed os images, run:
curl https://<username>:<api_key>@api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/getCreateObjectOptions.json | grep operatingSystemReferenceCode
Optional parameters:
datacenter_name
(string) - The code name of the region to launch the instance in. Consequently, this is the region where the image will be available. This defaults to "ams01"image_description
(string) - The description text which will be available for the resulting image. Defaults to "Instance snapshot. Generated by packer.io"image_type
(string) - The type of the image to create; either "flex" or "standard" (experimental). Defaults to "flex".instance_name
(string) - The name assigned to the instance. Default to "packer-softlayer-"instance_domain
(string) - The domain assigned to the instance. Defaults to "provisioning.com"instance_cpu
(string) - The amount of CPUs assigned to the instance. Defaults to 1instance_memory
(string) - The amount of Memory (in bytes) assigned to the instance. Defaults to 1024instance_network_speed
(string) - The network uplink speed, in megabits per second, which will be assigned to the instance. Defaults to 10instance_disks_capacity
(string array) - The amount of Disk capacity (in gigabytes) assigned to the instance. You can use multiple disk sizes here to configure multiple disks. For example, [25, 10, 15] will create 3 disks, with 25, 10 and 15GB respectively. Defaults to just one disk of 25GBssh_port
(string) - The port that SSH will be available on. Defaults to port 22ssh_timeout
(string) - The time to wait for SSH to become available before timing out. The format of this value is a duration such as "5s" or "5m". The default SSH timeout is "1m". Def aults to "15m"ssh_private_key_file
(string) - Use this ssh private key file instead of a generated ssh key pair for connecting to the instance.instance_state_timeout
(string) - The time to wait, as a duration string, for an instance or image snapshot to enter a desired state (such as "active") before timing out. The default s tate timeout is "25m"
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-builde r-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 m achine are propagated to the VM.
To run the unit tests, execute "go test ./..." from the root project directory.
TODO
- Add tests (especially for the client, however other parts of the code are important too)
- Configure travis CI or any alternative to automatically test and build the code
- Provide an easier way to install (with no need to compile from source)
Add an option to configure multiple disks for the instanceDone
Documentation ¶
There is no documentation for this package.