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 instanceOptions struct {
Username string
IdentityDomain string
SshKey string
Shape string
ImageList string
InstanceIP string
}
var instanceTemplate = template.Must(template.New("instanceRequestBody").Parse(`
{
"instances": [{
"shape": "{{.Shape}}",
"sshkeys": ["/Compute-{{.IdentityDomain}}/{{Username}}/{{.SshKey}}"],
"name": "Compute-{{.IdentityDomain}}/{{Username}}/packer-instance",
"label": "packer-instance",
"imagelist": "/Compute-{{.IdentityDomain}}/{{Username}}/{{.ImageList}}",
"networking": {
"eth0": {
"nat": "ipreservation:/Compute-{{.IdentityDomain}}/{{Username}}/{{.InstanceIP}}"
}
}
}]
}
`))
type stepCreateInstance struct{} type stepCreateInstance struct{}
func (s *stepCreateIPReservation) Run(state multistep.StateBag) multistep.StepAction { func (s *stepCreateIPReservation) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
ui.Say("Creating Instance...") config := state.Get("config").(Config)
const endpoint_path = "/launchplan/" // POST const endpoint_path = "/launchplan/" // POST
// master-instance.json
` ui.Say("Creating Instance...")
{
"instances": [{ // generate launch plan definition for this instance
"shape": "oc3", err = instanceTemplate.Execute(&buffer, instanceOptions{
"sshkeys": ["/Compute-mydomain/user@example.com/my_sshkey"], Username: config.Username,
"name": "Compute-mydomain/user@example.com/master-instance", IdentityDomain: config.IdentityDomain,
"label": "master-instance", SshKey: config.SshKey,
"imagelist": "/Compute-mydomain/user@example.com/Ubuntu.16.04-LTS.amd64.20170330", Shape: config.Shape,
"networking": { ImageList: config.ImageList,
"eth0": { })
"nat": "ipreservation:/Compute-mydomain/user@example.com/master-instance-ip"
}
}
}]
}
`
// 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
// ... // ...