Commit b3a97124 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/openstack: support user data [GH-1867]

parent a3863c34
...@@ -80,6 +80,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -80,6 +80,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
SecurityGroups: b.config.SecurityGroups, SecurityGroups: b.config.SecurityGroups,
Networks: b.config.Networks, Networks: b.config.Networks,
AvailabilityZone: b.config.AvailabilityZone, AvailabilityZone: b.config.AvailabilityZone,
UserData: b.config.UserData,
UserDataFile: b.config.UserDataFile,
}, },
&StepWaitForRackConnect{ &StepWaitForRackConnect{
Wait: b.config.RackconnectWait, Wait: b.config.RackconnectWait,
......
...@@ -23,6 +23,8 @@ type RunConfig struct { ...@@ -23,6 +23,8 @@ type RunConfig struct {
FloatingIp string `mapstructure:"floating_ip"` FloatingIp string `mapstructure:"floating_ip"`
SecurityGroups []string `mapstructure:"security_groups"` SecurityGroups []string `mapstructure:"security_groups"`
Networks []string `mapstructure:"networks"` Networks []string `mapstructure:"networks"`
UserData string `mapstructure:"user_data"`
UserDataFile string `mapstructure:"user_data_file"`
// Not really used, but here for BC // Not really used, but here for BC
OpenstackProvider string `mapstructure:"openstack_provider"` OpenstackProvider string `mapstructure:"openstack_provider"`
......
...@@ -2,6 +2,7 @@ package openstack ...@@ -2,6 +2,7 @@ package openstack
import ( import (
"fmt" "fmt"
"io/ioutil"
"log" "log"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
...@@ -16,6 +17,8 @@ type StepRunSourceServer struct { ...@@ -16,6 +17,8 @@ type StepRunSourceServer struct {
SecurityGroups []string SecurityGroups []string
Networks []string Networks []string
AvailabilityZone string AvailabilityZone string
UserData string
UserDataFile string
server *servers.Server server *servers.Server
} }
...@@ -39,6 +42,16 @@ func (s *StepRunSourceServer) Run(state multistep.StateBag) multistep.StepAction ...@@ -39,6 +42,16 @@ func (s *StepRunSourceServer) Run(state multistep.StateBag) multistep.StepAction
networks[i].UUID = networkUuid networks[i].UUID = networkUuid
} }
userData := []byte(s.UserData)
if s.UserDataFile != "" {
userData, err = ioutil.ReadFile(s.UserDataFile)
if err != nil {
err = fmt.Errorf("Error reading user data file: %s", err)
state.Put("error", err)
return multistep.ActionHalt
}
}
ui.Say("Launching server...") ui.Say("Launching server...")
s.server, err = servers.Create(computeClient, keypairs.CreateOptsExt{ s.server, err = servers.Create(computeClient, keypairs.CreateOptsExt{
CreateOptsBuilder: servers.CreateOpts{ CreateOptsBuilder: servers.CreateOpts{
...@@ -48,6 +61,7 @@ func (s *StepRunSourceServer) Run(state multistep.StateBag) multistep.StepAction ...@@ -48,6 +61,7 @@ func (s *StepRunSourceServer) Run(state multistep.StateBag) multistep.StepAction
SecurityGroups: s.SecurityGroups, SecurityGroups: s.SecurityGroups,
Networks: networks, Networks: networks,
AvailabilityZone: s.AvailabilityZone, AvailabilityZone: s.AvailabilityZone,
UserData: userData,
}, },
KeyName: keyName, KeyName: keyName,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment