Merge branch 'pr/4544'
This commit is contained in:
commit
4f92b9fb61
|
@ -39,6 +39,7 @@ type Config struct {
|
||||||
Network string `mapstructure:"network"`
|
Network string `mapstructure:"network"`
|
||||||
NetworkProjectId string `mapstructure:"network_project_id"`
|
NetworkProjectId string `mapstructure:"network_project_id"`
|
||||||
OmitExternalIP bool `mapstructure:"omit_external_ip"`
|
OmitExternalIP bool `mapstructure:"omit_external_ip"`
|
||||||
|
OnHostMaintenance string `mapstructure:"on_host_maintenance"`
|
||||||
Preemptible bool `mapstructure:"preemptible"`
|
Preemptible bool `mapstructure:"preemptible"`
|
||||||
RawStateTimeout string `mapstructure:"state_timeout"`
|
RawStateTimeout string `mapstructure:"state_timeout"`
|
||||||
Region string `mapstructure:"region"`
|
Region string `mapstructure:"region"`
|
||||||
|
@ -92,6 +93,22 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
||||||
if c.ImageDescription == "" {
|
if c.ImageDescription == "" {
|
||||||
c.ImageDescription = "Created by Packer"
|
c.ImageDescription = "Created by Packer"
|
||||||
}
|
}
|
||||||
|
// Setting OnHostMaintenance Correct Defaults
|
||||||
|
// "MIGRATE" : Possible if Preemptible is false
|
||||||
|
// "TERMINATE": Posssible if Preemptible is true
|
||||||
|
if c.OnHostMaintenance == "" && c.Preemptible {
|
||||||
|
c.OnHostMaintenance = "MIGRATE"
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.OnHostMaintenance == "" && !c.Preemptible {
|
||||||
|
c.OnHostMaintenance = "TERMINATE"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure user sets a valid value for on_host_maintenance option
|
||||||
|
if !(c.OnHostMaintenance == "MIGRATE" || c.OnHostMaintenance == "TERMINATE") {
|
||||||
|
errs = packer.MultiErrorAppend(errs,
|
||||||
|
errors.New("on_host_maintenance must be one of MIGRATE or TERMINATE."))
|
||||||
|
}
|
||||||
|
|
||||||
if c.ImageName == "" {
|
if c.ImageName == "" {
|
||||||
img, err := interpolate.Render("packer-{{timestamp}}", nil)
|
img, err := interpolate.Render("packer-{{timestamp}}", nil)
|
||||||
|
|
|
@ -104,6 +104,21 @@ func TestConfigPrepare(t *testing.T) {
|
||||||
"SO VERY BAD",
|
"SO VERY BAD",
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"on_host_maintenance",
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"on_host_maintenance",
|
||||||
|
"TERMINATE",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"on_host_maintenance",
|
||||||
|
"SO VERY BAD",
|
||||||
|
true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"preemptible",
|
"preemptible",
|
||||||
nil,
|
nil,
|
||||||
|
|
|
@ -69,6 +69,7 @@ type InstanceConfig struct {
|
||||||
Network string
|
Network string
|
||||||
NetworkProjectId string
|
NetworkProjectId string
|
||||||
OmitExternalIP bool
|
OmitExternalIP bool
|
||||||
|
OnHostMaintenance string
|
||||||
Preemptible bool
|
Preemptible bool
|
||||||
Region string
|
Region string
|
||||||
Scopes []string
|
Scopes []string
|
||||||
|
|
|
@ -386,7 +386,8 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Scheduling: &compute.Scheduling{
|
Scheduling: &compute.Scheduling{
|
||||||
Preemptible: c.Preemptible,
|
OnHostMaintenance: c.OnHostMaintenance,
|
||||||
|
Preemptible: c.Preemptible,
|
||||||
},
|
},
|
||||||
ServiceAccounts: []*compute.ServiceAccount{
|
ServiceAccounts: []*compute.ServiceAccount{
|
||||||
{
|
{
|
||||||
|
|
|
@ -110,6 +110,7 @@ func (s *StepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
|
||||||
Network: c.Network,
|
Network: c.Network,
|
||||||
NetworkProjectId: c.NetworkProjectId,
|
NetworkProjectId: c.NetworkProjectId,
|
||||||
OmitExternalIP: c.OmitExternalIP,
|
OmitExternalIP: c.OmitExternalIP,
|
||||||
|
OnHostMaintenance: c.OnHostMaintenance,
|
||||||
Preemptible: c.Preemptible,
|
Preemptible: c.Preemptible,
|
||||||
Region: c.Region,
|
Region: c.Region,
|
||||||
ServiceAccountEmail: c.Account.ClientEmail,
|
ServiceAccountEmail: c.Account.ClientEmail,
|
||||||
|
|
|
@ -179,6 +179,14 @@ builder.
|
||||||
|
|
||||||
- `preemptible` (boolean) - If true, launch a preembtible instance.
|
- `preemptible` (boolean) - If true, launch a preembtible instance.
|
||||||
|
|
||||||
|
- `on_host_maintenance` (string) - Sets Host Maintenance Option. Valid
|
||||||
|
choices are `MIGRATE` and `TERMINATE`. Please see [GCE Instance Scheduling
|
||||||
|
Options](https://cloud.google.com/compute/docs/instances/setting-instance-scheduling-options),
|
||||||
|
as not all machine_types support `MIGRATE` (i.e. machines with GPUs). The
|
||||||
|
default value depends on preemtability.
|
||||||
|
- when preemptible == true, defaults to `TERMINATE`
|
||||||
|
- when preemptible == false, defaults to `MIGRATE`
|
||||||
|
|
||||||
- `region` (string) - The region in which to launch the instance. Defaults to
|
- `region` (string) - The region in which to launch the instance. Defaults to
|
||||||
to the region hosting the specified `zone`.
|
to the region hosting the specified `zone`.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue