gophercloud icon indicating copy to clipboard operation
gophercloud copied to clipboard

Attaching volumes

Open mbonell opened this issue 9 years ago • 8 comments

Is supported the volume attachment? I haven't find how to attach a volume to a running instance

mbonell avatar Feb 23 '17 00:02 mbonell

Volume attachment is indeed supported. You can see an example of it in these two places:

  • https://github.com/gophercloud/gophercloud/blob/master/acceptance/openstack/compute/v2/volumeattach_test.go
  • https://github.com/gophercloud/gophercloud/blob/master/acceptance/openstack/compute/v2/compute.go#L504

Hope that helps.

jtopjian avatar Feb 23 '17 03:02 jtopjian

Thanks, I have implemented and it works as expected. But the detach is not working.

https://github.com/gophercloud/gophercloud/blob/master/acceptance/openstack/compute/v2/compute.go#L610

Invalid request due to incorrect syntax or missing required parameters. err = volumeattach.Delete(computeClient, server.ID, volumeAttachment.VolumeID).ExtractErr()

mbonell avatar Feb 23 '17 19:02 mbonell

@MBonell That's strange...

One thing you can try is replacing volumeAttachment.VolumeID with volumeAttachment.ID. Most of the time the attachment ID is the volume ID, but maybe it's not for the volume driver being used.

If that doesn't work, do you have access to the actual Cinder logs? The cause of the error would be logged there.

jtopjian avatar Feb 23 '17 20:02 jtopjian

@jtopjian Super strange.. because if I send the id as string, it works!! err = volumeattach.Delete(computeClient, server.ID, "1b3a52cc-57b5-47c8-b0d6-dd5a7651fda1").ExtractErr() :+1:

But if I send volume.ID or volumeAttachment.VolumeID or volumeAttachment.ID as variable it does not work :-1:

mbonell avatar Feb 24 '17 01:02 mbonell

Yeah that's very strange. Can you do something like the following and see what the contents of these structs are?

fmt.Printf("%#v", volumeattach)
fmt.Printf("%#v", volume)

It sounds like they're not getting populated. Either that, or the OpenStack cloud you're using isn't sending the correct information.

jtopjian avatar Feb 24 '17 02:02 jtopjian

&volumeattach.VolumeAttachment{ID:"2af6b7bc-a8f0-4511-bef0-7366a2b31e36", Device:"/dev/vdb", VolumeID:"2af6b7bc-a8f0-4511-bef0-7366a2b31e36", ServerID:"cd4abf3f-57d8-4ef5-8939-5a9ec06cf053"}

&volumes.Volume{Status:"creating", Name:"test", Attachments:[]map[string]interface {}{}, AvailabilityZone:"nova", Bootable:"false", CreatedAt:gophercloud.JSONRFC3339MilliNoZ{sec:63623552335, nsec:803476000, loc:(*time.Location)(0x9b8d00)}, Description:"", VolumeType:"", SnapshotID:"", SourceVolID:"", Metadata:map[string]string{}, ID:"2af6b7bc-a8f0-4511-bef0-7366a2b31e36", Size:1}

mbonell avatar Feb 24 '17 17:02 mbonell

Finally!! I discovered what is happening. After the attachment I need to wait before proceed with the detach and deletion.

volumes.WaitForStatus(volumeClient, volumeAttach.ID, "available", 60)

mbonell avatar Feb 24 '17 17:02 mbonell

Ahh - that makes sense. Glad to hear it's working. :)

jtopjian avatar Feb 24 '17 20:02 jtopjian