add configurable snapshot timeout to oracle-classic builder

This commit is contained in:
Megan Marsh 2018-02-21 14:33:00 -08:00
parent df45e0916d
commit 597ddc2192
4 changed files with 22 additions and 6 deletions

View File

@ -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{

View File

@ -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)

View File

@ -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)

View File

@ -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