Merge pull request #2224 from mitchellh/f-os-userdata

builder/openstack: support user data [GH-1867]
This commit is contained in:
Mitchell Hashimoto 2015-06-15 09:35:49 -07:00
commit a95408aa21
3 changed files with 18 additions and 0 deletions

View File

@ -83,6 +83,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
SecurityGroups: b.config.SecurityGroups,
Networks: b.config.Networks,
AvailabilityZone: b.config.AvailabilityZone,
UserData: b.config.UserData,
UserDataFile: b.config.UserDataFile,
},
&StepWaitForRackConnect{
Wait: b.config.RackconnectWait,

View File

@ -21,6 +21,8 @@ type RunConfig struct {
FloatingIp string `mapstructure:"floating_ip"`
SecurityGroups []string `mapstructure:"security_groups"`
Networks []string `mapstructure:"networks"`
UserData string `mapstructure:"user_data"`
UserDataFile string `mapstructure:"user_data_file"`
// Not really used, but here for BC
OpenstackProvider string `mapstructure:"openstack_provider"`

View File

@ -2,6 +2,7 @@ package openstack
import (
"fmt"
"io/ioutil"
"log"
"github.com/mitchellh/multistep"
@ -16,6 +17,8 @@ type StepRunSourceServer struct {
SecurityGroups []string
Networks []string
AvailabilityZone string
UserData string
UserDataFile string
server *servers.Server
}
@ -39,6 +42,16 @@ func (s *StepRunSourceServer) Run(state multistep.StateBag) multistep.StepAction
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...")
s.server, err = servers.Create(computeClient, keypairs.CreateOptsExt{
CreateOptsBuilder: servers.CreateOpts{
@ -48,6 +61,7 @@ func (s *StepRunSourceServer) Run(state multistep.StateBag) multistep.StepAction
SecurityGroups: s.SecurityGroups,
Networks: networks,
AvailabilityZone: s.AvailabilityZone,
UserData: userData,
},
KeyName: keyName,