From b3a97124023b48a36d05d2aa8fc1fa0def0ad0c9 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 12 Jun 2015 22:55:39 -0400 Subject: [PATCH] builder/openstack: support user data [GH-1867] --- builder/openstack/builder.go | 2 ++ builder/openstack/run_config.go | 2 ++ builder/openstack/step_run_source_server.go | 14 ++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/builder/openstack/builder.go b/builder/openstack/builder.go index ab60afc0e..cf1cfc8c5 100644 --- a/builder/openstack/builder.go +++ b/builder/openstack/builder.go @@ -80,6 +80,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, diff --git a/builder/openstack/run_config.go b/builder/openstack/run_config.go index 4a6a1b81f..ca0360a10 100644 --- a/builder/openstack/run_config.go +++ b/builder/openstack/run_config.go @@ -23,6 +23,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"` diff --git a/builder/openstack/step_run_source_server.go b/builder/openstack/step_run_source_server.go index 4014f1d95..9e55dea0e 100644 --- a/builder/openstack/step_run_source_server.go +++ b/builder/openstack/step_run_source_server.go @@ -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,