Merge pull request #2982 from minimum2scp/features/support-googlecompute-preemptible

Added support of preemptible instance in googlecompute builder
This commit is contained in:
Chris Bednarski 2015-12-14 14:34:09 -08:00
commit 00ea5ff7de
6 changed files with 23 additions and 0 deletions

View File

@ -31,6 +31,7 @@ type Config struct {
MachineType string `mapstructure:"machine_type"`
Metadata map[string]string `mapstructure:"metadata"`
Network string `mapstructure:"network"`
Preemptible bool `mapstructure:"preemptible"`
SourceImage string `mapstructure:"source_image"`
SourceImageProjectId string `mapstructure:"source_image_project_id"`
RawStateTimeout string `mapstructure:"state_timeout"`

View File

@ -93,6 +93,21 @@ func TestConfigPrepare(t *testing.T) {
"SO VERY BAD",
true,
},
{
"preemptible",
nil,
false,
},
{
"preemptible",
false,
false,
},
{
"preemptible",
"SO VERY BAD",
true,
},
}
for _, tc := range cases {

View File

@ -47,6 +47,7 @@ type InstanceConfig struct {
Metadata map[string]string
Name string
Network string
Preemptible bool
Tags []string
Zone string
}

View File

@ -255,6 +255,9 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) {
Network: network.SelfLink,
},
},
Scheduling: &compute.Scheduling{
Preemptible: c.Preemptible,
},
ServiceAccounts: []*compute.ServiceAccount{
&compute.ServiceAccount{
Email: "default",

View File

@ -59,6 +59,7 @@ func (s *StepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
Metadata: config.getInstanceMetadata(sshPublicKey),
Name: name,
Network: config.Network,
Preemptible: config.Preemptible,
Tags: config.Tags,
Zone: config.Zone,
})

View File

@ -144,6 +144,8 @@ builder.
- `use_internal_ip` (boolean) - If true, use the instance's internal IP
instead of its external IP during building.
- `preemptible` (boolean) - If true, launch a preembtible instance.
## Gotchas
Centos images have root ssh access disabled by default. Set `ssh_username` to