Merge remote-tracking branch 'origin/master' into scrape_doc_to_builder_struct_config

This commit is contained in:
Adrien Delorme
2019-09-20 10:54:38 +02:00
272 changed files with 36114 additions and 9533 deletions
+1
View File
@@ -75,6 +75,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
Debug: b.config.PackerDebug,
},
&stepSetupNetworking{},
&stepDetachIso{},
&communicator.StepConnect{
Config: &b.config.Comm,
Host: communicator.CommHost(b.config.Comm.SSHHost, "ipaddress"),
+8 -2
View File
@@ -21,6 +21,7 @@ type Config struct {
common.PackerConfig `mapstructure:",squash"`
common.HTTPConfig `mapstructure:",squash"`
Comm communicator.Config `mapstructure:",squash"`
// The CloudStack API endpoint we will connect to. It can
// also be specified via environment variable CLOUDSTACK_API_URL, if set.
APIURL string `mapstructure:"api_url" required:"true"`
@@ -58,6 +59,10 @@ type Config struct {
// The size (in GB) of the root disk of the new
// instance. This option is only available when using source_template.
DiskSize int64 `mapstructure:"disk_size" required:"false"`
//
EjectISO bool `mapstructure:"eject_iso"`
//
EjectISODelay time.Duration `mapstructure:"eject_iso_delay"`
// Set to true to expunge the instance when it is
// destroyed. Defaults to false.
Expunge bool `mapstructure:"expunge" required:"false"`
@@ -144,8 +149,9 @@ type Config struct {
// Set to true to indicate that the template
// contains tools to support dynamic scaling of VM cpu/memory. Defaults to
// false.
TemplateScalable bool `mapstructure:"template_scalable" required:"false"`
TemplateTag string `mapstructure:"template_tag"`
TemplateScalable bool `mapstructure:"template_scalable" required:"false"`
//
TemplateTag string `mapstructure:"template_tag"`
Tags map[string]string `mapstructure:"tags"`
+60
View File
@@ -0,0 +1,60 @@
package cloudstack
import (
"context"
"fmt"
"time"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/xanzy/go-cloudstack/cloudstack"
)
type stepDetachIso struct{}
// Detaches currently ISO file attached to a virtual machine if any.
func (s *stepDetachIso) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
config := state.Get("config").(*Config)
// Check if state uses iso file and has need to eject it
if !config.EjectISO || config.SourceISO == "" {
return multistep.ActionContinue
}
ui.Say("Checking attached iso...")
// Wait to make call detachIso
if config.EjectISODelay > 0 {
ui.Message(fmt.Sprintf("Waiting for %v before detaching ISO from virtual machine...", config.EjectISODelay))
time.Sleep(config.EjectISODelay)
}
client := state.Get("client").(*cloudstack.CloudStackClient)
instanceID, ok := state.Get("instance_id").(string)
if !ok || instanceID == "" {
err := fmt.Errorf("Could not retrieve instance_id from state")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
ui.Message("Detaching iso from virtual machine...")
// Get a new DetachIsoParams and detaches Iso file from given virtualMachine instance
detachIsoParams := client.ISO.NewDetachIsoParams(instanceID)
response, err := client.ISO.DetachIso(detachIsoParams)
if err != nil || response == nil {
err := fmt.Errorf("Error detaching ISO from virtual machine: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
return multistep.ActionContinue
}
func (s *stepDetachIso) Cleanup(state multistep.StateBag) {
// Nothing to cleanup for this step.
}