From 5428d7a1aef45bc2ea3dc2256b2b4932b92cb155 Mon Sep 17 00:00:00 2001 From: akutz Date: Sat, 12 Nov 2016 14:16:04 -0600 Subject: [PATCH] Rackspace Get Volumes Attachment States Fix This patch fixes an issue where the Rackspace storage driver always assumed that the local devices information should be available when inspecting a volume or that a volume's attachment information should always be fetched. --- .../rackspace/storage/rackspace_storage.go | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/drivers/storage/rackspace/storage/rackspace_storage.go b/drivers/storage/rackspace/storage/rackspace_storage.go index cb4154cc..1c56294f 100644 --- a/drivers/storage/rackspace/storage/rackspace_storage.go +++ b/drivers/storage/rackspace/storage/rackspace_storage.go @@ -138,7 +138,7 @@ func (d *driver) Volumes( ctx types.Context, opts *types.VolumesOpts) ([]*types.Volume, error) { // always return attachments to align against other drivers for now - return d.getVolume(ctx, "", "", types.VolAttReqTrue) + return d.getVolume(ctx, "", "", opts.Attachments) } // // VolumeInspect inspects a single volume. @@ -592,31 +592,21 @@ func (d *driver) createVolume( //Reformats from volumes.Volume to types.Volume credit to github.com/MatMaul func translateVolume( volume *volumes.Volume, - includeAttachments types.VolumeAttachmentsTypes) *types.Volume { + attachments types.VolumeAttachmentsTypes) *types.Volume { - var attachments []*types.VolumeAttachment - if includeAttachments.Requested() { - for _, attachment := range volume.Attachments { - libstorageAttachment := &types.VolumeAttachment{ - VolumeID: attachment["volume_id"].(string), + var atts []*types.VolumeAttachment + if attachments.Requested() { + for _, att := range volume.Attachments { + lsAtt := &types.VolumeAttachment{ + VolumeID: att["volume_id"].(string), InstanceID: &types.InstanceID{ - ID: attachment["server_id"].(string), + ID: att["server_id"].(string), Driver: rackspace.Name}, - DeviceName: attachment["device"].(string), - Status: "", } - attachments = append(attachments, libstorageAttachment) - } - } else { - for _, attachment := range volume.Attachments { - libstorageAttachment := &types.VolumeAttachment{ - VolumeID: attachment["volume_id"].(string), - InstanceID: &types.InstanceID{ID: attachment["server_id"].(string), Driver: rackspace.Name}, - DeviceName: "", - Status: "", + if attachments.Devices() { + lsAtt.DeviceName = att["device"].(string) } - attachments = append(attachments, libstorageAttachment) - break + atts = append(atts, lsAtt) } } @@ -628,7 +618,7 @@ func translateVolume( Type: volume.VolumeType, IOPS: 0, Size: int64(volume.Size), - Attachments: attachments, + Attachments: atts, } }