fleshing out step_create_instance

This commit is contained in:
Megan Marsh 2018-01-12 16:48:35 -08:00 committed by Matthew Hooker
parent 4fe89be32a
commit a66dfe1972
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
1 changed files with 39 additions and 18 deletions

View File

@ -2,34 +2,55 @@ package classic
import ( import (
"fmt" "fmt"
"text/template"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
) )
type stepCreateInstance struct{} type instanceOptions struct {
Username string
IdentityDomain string
SshKey string
Shape string
ImageList string
InstanceIP string
}
func (s *stepCreateIPReservation) Run(state multistep.StateBag) multistep.StepAction { var instanceTemplate = template.Must(template.New("instanceRequestBody").Parse(`
ui := state.Get("ui").(packer.Ui)
ui.Say("Creating Instance...")
const endpoint_path = "/launchplan/" // POST
// master-instance.json
`
{ {
"instances": [{ "instances": [{
"shape": "oc3", "shape": "{{.Shape}}",
"sshkeys": ["/Compute-mydomain/user@example.com/my_sshkey"], "sshkeys": ["/Compute-{{.IdentityDomain}}/{{Username}}/{{.SshKey}}"],
"name": "Compute-mydomain/user@example.com/master-instance", "name": "Compute-{{.IdentityDomain}}/{{Username}}/packer-instance",
"label": "master-instance", "label": "packer-instance",
"imagelist": "/Compute-mydomain/user@example.com/Ubuntu.16.04-LTS.amd64.20170330", "imagelist": "/Compute-{{.IdentityDomain}}/{{Username}}/{{.ImageList}}",
"networking": { "networking": {
"eth0": { "eth0": {
"nat": "ipreservation:/Compute-mydomain/user@example.com/master-instance-ip" "nat": "ipreservation:/Compute-{{.IdentityDomain}}/{{Username}}/{{.InstanceIP}}"
} }
} }
}] }]
} }
` `))
type stepCreateInstance struct{}
func (s *stepCreateIPReservation) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
config := state.Get("config").(Config)
const endpoint_path = "/launchplan/" // POST
ui.Say("Creating Instance...")
// generate launch plan definition for this instance
err = instanceTemplate.Execute(&buffer, instanceOptions{
Username: config.Username,
IdentityDomain: config.IdentityDomain,
SshKey: config.SshKey,
Shape: config.Shape,
ImageList: config.ImageList,
})
// command line call // command line call
// $ opc compute launch-plans add --request-body=./master-instance.json // $ opc compute launch-plans add --request-body=./master-instance.json
// ... // ...