From 336c11c54a056466ef2ecbb2ec5a09910669f51e Mon Sep 17 00:00:00 2001 From: "Johannes J. Schmidt" Date: Tue, 18 Dec 2018 23:58:27 +0100 Subject: [PATCH 1/2] add openstack volume_size option Adds an option to OpenStack, `volume_size` (int), which is the size of the Block Storage service volume in GB. --- builder/openstack/run_config.go | 1 + website/source/docs/builders/openstack.html.md | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/builder/openstack/run_config.go b/builder/openstack/run_config.go index 56fccb4f3..5a2efd023 100644 --- a/builder/openstack/run_config.go +++ b/builder/openstack/run_config.go @@ -40,6 +40,7 @@ type RunConfig struct { UseBlockStorageVolume bool `mapstructure:"use_blockstorage_volume"` VolumeName string `mapstructure:"volume_name"` VolumeType string `mapstructure:"volume_type"` + VolumeSize int `mapstructure:"volume_size"` VolumeAvailabilityZone string `mapstructure:"volume_availability_zone"` // Not really used, but here for BC diff --git a/website/source/docs/builders/openstack.html.md b/website/source/docs/builders/openstack.html.md index 263610c0f..3320f7ea2 100644 --- a/website/source/docs/builders/openstack.html.md +++ b/website/source/docs/builders/openstack.html.md @@ -275,6 +275,11 @@ builder. isn't specified, the default enforced by your OpenStack cluster will be used. +- `volume_size` (int) - Size of the Block Storage service volume in GB. If this + isn't specified, it is set to source image min disk value (if set) or + calculated from the source image bytes size. Note that in some cases this + needs to be specified, if `use_blockstorage_volume` is true. + - `volume_availability_zone` (string) - Availability zone of the Block Storage service volume. If omitted, Compute instance availability zone will be used. If both of Compute instance and Block Storage volume availability From a545caa24a3ebfb9b12ea124f17686aeb9ac871d Mon Sep 17 00:00:00 2001 From: "Johannes J. Schmidt" Date: Tue, 18 Dec 2018 23:59:54 +0100 Subject: [PATCH 2/2] use openstack volume_size option on creation if present. Otherwise fallback to to source image min disk value (if set) or calculated from the source image bytes size. Note that in some cases this needs to be specified, if `use_blockstorage_volume` is true. See #6957 for the discussion. --- builder/openstack/step_create_volume.go | 29 +++++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/builder/openstack/step_create_volume.go b/builder/openstack/step_create_volume.go index 28b01c0b4..ec1734a06 100644 --- a/builder/openstack/step_create_volume.go +++ b/builder/openstack/step_create_volume.go @@ -35,20 +35,25 @@ func (s *StepCreateVolume) Run(_ context.Context, state multistep.StateBag) mult state.Put("error", err) return multistep.ActionHalt } - imageClient, err := config.imageV2Client() - if err != nil { - err = fmt.Errorf("Error initializing image client: %s", err) - state.Put("error", err) - return multistep.ActionHalt - } + + volumeSize := config.VolumeSize // Get needed volume size from the source image. - volumeSize, err := GetVolumeSize(imageClient, sourceImage) - if err != nil { - err := fmt.Errorf("Error creating volume: %s", err) - state.Put("error", err) - ui.Error(err.Error()) - return multistep.ActionHalt + if volumeSize == 0 { + imageClient, err := config.imageV2Client() + if err != nil { + err = fmt.Errorf("Error initializing image client: %s", err) + state.Put("error", err) + return multistep.ActionHalt + } + + volumeSize, err = GetVolumeSize(imageClient, sourceImage) + if err != nil { + err := fmt.Errorf("Error creating volume: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } } ui.Say("Creating volume...")