From bab590c177f7dde893b2e8c38fdd01ea952d05b3 Mon Sep 17 00:00:00 2001 From: Dimitri Rudnev Date: Fri, 10 Feb 2017 10:58:57 -0800 Subject: [PATCH] Adding OnHostMaintenance option for googlecompue builder --- builder/googlecompute/config.go | 7 +++++++ builder/googlecompute/config_test.go | 15 +++++++++++++++ builder/googlecompute/driver.go | 1 + builder/googlecompute/driver_gce.go | 3 ++- builder/googlecompute/step_create_instance.go | 1 + 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/builder/googlecompute/config.go b/builder/googlecompute/config.go index 460437b6e..8fa374306 100644 --- a/builder/googlecompute/config.go +++ b/builder/googlecompute/config.go @@ -39,6 +39,7 @@ type Config struct { Network string `mapstructure:"network"` NetworkProjectId string `mapstructure:"network_project_id"` OmitExternalIP bool `mapstructure:"omit_external_ip"` + OnHostMaintenance string `mapstructure:"on_host_maintenance"` Preemptible bool `mapstructure:"preemptible"` RawStateTimeout string `mapstructure:"state_timeout"` Region string `mapstructure:"region"` @@ -92,6 +93,12 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { if c.ImageDescription == "" { c.ImageDescription = "Created by Packer" } + // Possible values: + // "MIGRATE" + // "TERMINATE" + if c.OnHostMaintenance == "" { + c.OnHostMaintenance = "MIGRATE" + } if c.ImageName == "" { img, err := interpolate.Render("packer-{{timestamp}}", nil) diff --git a/builder/googlecompute/config_test.go b/builder/googlecompute/config_test.go index c2f469c3d..210601948 100644 --- a/builder/googlecompute/config_test.go +++ b/builder/googlecompute/config_test.go @@ -104,6 +104,21 @@ func TestConfigPrepare(t *testing.T) { "SO VERY BAD", true, }, + { + "on_host_maintenance", + nil, + false, + }, + { + "on_host_maintenance", + "TERMINATE", + false, + }, + { + "on_host_maintenance", + "SO VERY BAD", + false, + }, { "preemptible", nil, diff --git a/builder/googlecompute/driver.go b/builder/googlecompute/driver.go index 1452082bc..d55d267b7 100644 --- a/builder/googlecompute/driver.go +++ b/builder/googlecompute/driver.go @@ -69,6 +69,7 @@ type InstanceConfig struct { Network string NetworkProjectId string OmitExternalIP bool + OnHostMaintenance string Preemptible bool Region string Scopes []string diff --git a/builder/googlecompute/driver_gce.go b/builder/googlecompute/driver_gce.go index bce3fb391..c535c139c 100644 --- a/builder/googlecompute/driver_gce.go +++ b/builder/googlecompute/driver_gce.go @@ -386,7 +386,8 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) { }, }, Scheduling: &compute.Scheduling{ - Preemptible: c.Preemptible, + OnHostMaintenance: c.OnHostMaintenance, + Preemptible: c.Preemptible, }, ServiceAccounts: []*compute.ServiceAccount{ { diff --git a/builder/googlecompute/step_create_instance.go b/builder/googlecompute/step_create_instance.go index d0dcba18f..3f70d422f 100644 --- a/builder/googlecompute/step_create_instance.go +++ b/builder/googlecompute/step_create_instance.go @@ -110,6 +110,7 @@ func (s *StepCreateInstance) Run(state multistep.StateBag) multistep.StepAction Network: c.Network, NetworkProjectId: c.NetworkProjectId, OmitExternalIP: c.OmitExternalIP, + OnHostMaintenance: c.OnHostMaintenance, Preemptible: c.Preemptible, Region: c.Region, ServiceAccountEmail: c.Account.ClientEmail,