From 597ddc2192392624970b4e832c352deb6f6de6d8 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 21 Feb 2018 14:33:00 -0800 Subject: [PATCH] add configurable snapshot timeout to oracle-classic builder --- builder/oracle/classic/config.go | 14 ++++++++++---- builder/oracle/classic/step_snapshot.go | 3 +-- builder/vmware/common/driver.go | 3 +++ .../source/docs/builders/oracle-classic.html.md | 8 ++++++++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/builder/oracle/classic/config.go b/builder/oracle/classic/config.go index 7916478f0..b9f5d808f 100644 --- a/builder/oracle/classic/config.go +++ b/builder/oracle/classic/config.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "net/url" "os" + "time" "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/communicator" @@ -27,10 +28,11 @@ type Config struct { apiEndpointURL *url.URL // Image - ImageName string `mapstructure:"image_name"` - Shape string `mapstructure:"shape"` - SourceImageList string `mapstructure:"source_image_list"` - DestImageList string `mapstructure:"dest_image_list"` + ImageName string `mapstructure:"image_name"` + Shape string `mapstructure:"shape"` + SourceImageList string `mapstructure:"source_image_list"` + SnapshotTimeout time.Duration `mapstructure:"snapshot_timeout"` + DestImageList string `mapstructure:"dest_image_list"` // Attributes and Atributes file are both optional and mutually exclusive. Attributes string `mapstructure:"attributes"` AttributesFile string `mapstructure:"attributes_file"` @@ -71,6 +73,10 @@ func NewConfig(raws ...interface{}) (*Config, error) { c.Comm.SSHUsername = "opc" } + if c.SnapshotTimeout == 0 { + c.SnapshotTimeout = 20 * time.Minute + } + // Validate that all required fields are present var errs *packer.MultiError required := map[string]string{ diff --git a/builder/oracle/classic/step_snapshot.go b/builder/oracle/classic/step_snapshot.go index 68c059897..e0ebf3091 100644 --- a/builder/oracle/classic/step_snapshot.go +++ b/builder/oracle/classic/step_snapshot.go @@ -3,7 +3,6 @@ package classic import ( "context" "fmt" - "time" "github.com/hashicorp/go-oracle-terraform/compute" "github.com/hashicorp/packer/helper/multistep" @@ -30,7 +29,7 @@ func (s *stepSnapshot) Run(_ context.Context, state multistep.StateBag) multiste snapshotInput := &compute.CreateSnapshotInput{ Instance: fmt.Sprintf("%s/%s", config.ImageName, instanceID), MachineImage: config.ImageName, - Timeout: time.Minute * 20, + Timeout: config.SnapshotTimeout, } snap, err := snapshotClient.CreateSnapshot(snapshotInput) diff --git a/builder/vmware/common/driver.go b/builder/vmware/common/driver.go index 8fa185efd..c8fea88f4 100644 --- a/builder/vmware/common/driver.go +++ b/builder/vmware/common/driver.go @@ -309,12 +309,14 @@ func (d *VmwareDriver) GuestIP(state multistep.StateBag) (string, error) { // grab network mapper netmap, err := d.NetworkMapper() + log.Printf("MEGAN: NEtworkMapper is %#v", netmap) if err != nil { return "", err } // convert the stashed network to a device network := state.Get("vmnetwork").(string) + log.Printf("MEGAN: network is %#v", network) device, err := netmap.NameIntoDevice(network) // we were unable to find the device, maybe it's a custom one... @@ -337,6 +339,7 @@ func (d *VmwareDriver) GuestIP(state multistep.StateBag) (string, error) { if err != nil { return "", err } + log.Printf("MEGAN mac address is %s", MACAddress) // figure out the correct dhcp leases dhcpLeasesPath := d.DhcpLeasesPath(device) diff --git a/website/source/docs/builders/oracle-classic.html.md b/website/source/docs/builders/oracle-classic.html.md index 208a0a088..1ea03dc46 100644 --- a/website/source/docs/builders/oracle-classic.html.md +++ b/website/source/docs/builders/oracle-classic.html.md @@ -84,6 +84,14 @@ This builder currently only works with the SSH communicator. - `image_name` (string) - The name to assign to the resulting custom image. + - `snapshot_timeout` (string) - How long to wait for a snapshot to be + created. Expects a positive golang Time.Duration string, which is + a sequence of decimal numbers and a unit suffix; valid suffixes are `ns` + (nanoseconds), `us` (microseconds), `ms` (milliseconds), `s` (seconds), `m` + (minutes), and `h` (hours). Examples of valid inputs: `100ms`, `250ms`, `1s`, + `2.5s`, `2.5m`, `1m30s`. + Example: `"snapshot_timeout": "15m"`. Default: `20m`. + ## Basic Example Here is a basic example. Note that account specific configuration has been