cloudstack: moved instanceSource to statebag

This commit is contained in:
Rickard von Essen 2017-07-16 18:23:59 +02:00
parent ba3d4c8cd2
commit 07fffd7cd5
3 changed files with 10 additions and 8 deletions

View File

@ -55,9 +55,8 @@ type Config struct {
TemplateScalable bool `mapstructure:"template_scalable"`
TemplateTag string `mapstructure:"template_tag"`
ctx interpolate.Context
hostAddress string // The host address used by the communicators.
instanceSource string // This can be either a template ID or an ISO ID.
ctx interpolate.Context
hostAddress string // The host address used by the communicators.
}
// NewConfig parses and validates the given config.

View File

@ -30,13 +30,14 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
client := state.Get("client").(*cloudstack.CloudStackClient)
config := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui)
source := state.Get("source").(string)
ui.Say("Creating instance...")
// Create a new parameter struct.
p := client.VirtualMachine.NewDeployVirtualMachineParams(
config.ServiceOffering,
config.instanceSource,
source,
config.Zone,
)

View File

@ -101,23 +101,25 @@ func (s *stepPrepareConfig) Run(state multistep.StateBag) multistep.StepAction {
if config.SourceISO != "" {
if isUUID(config.SourceISO) {
config.instanceSource = config.SourceISO
state.Put("source", config.SourceISO)
} else {
config.instanceSource, _, err = client.ISO.GetIsoID(config.SourceISO, "executable", config.Zone)
isoID, _, err := client.ISO.GetIsoID(config.SourceISO, "executable", config.Zone)
if err != nil {
errs = packer.MultiErrorAppend(errs, &retrieveErr{"ISO", config.SourceISO, err})
}
state.Put("source", isoID)
}
}
if config.SourceTemplate != "" {
if isUUID(config.SourceTemplate) {
config.instanceSource = config.SourceTemplate
state.Put("source", config.SourceTemplate)
} else {
config.instanceSource, _, err = client.Template.GetTemplateID(config.SourceTemplate, "executable", config.Zone)
templateID, _, err := client.Template.GetTemplateID(config.SourceTemplate, "executable", config.Zone)
if err != nil {
errs = packer.MultiErrorAppend(errs, &retrieveErr{"template", config.SourceTemplate, err})
}
state.Put("source", templateID)
}
}