Commit a95408aa authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

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

builder/openstack: support user data [GH-1867]
parents 3edff006 b3a97124
......@@ -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,
......
......@@ -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"`
......
......@@ -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,
......
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