Add support for managing volumes #41

Merged
merged 3 commits into from Mar 19, 2015

Conversation

Projects
None yet
2 participants
Member

wallyworld commented Mar 19, 2015

With this branch, it is now possible to:

  • create, delete list volumes
  • attach and detach volumes from instances

Tested live.

ec2/ec2test/server.go
+ srv.mu.Lock()
+ defer srv.mu.Unlock()
+
+ delete(srv.volumes, v.Id)
@axw

axw Mar 19, 2015

Member

Should we also delete attachments here? What's the behaviour of EC2 if you try to delete a volume with attachments?

@wallyworld

wallyworld Mar 19, 2015

Member

EC2 requires a volume be in the available state before deletion (ie not attached). Added a check here in the test server.

ec2/ec2test/server.go
+ srv.mu.Lock()
+ defer srv.mu.Unlock()
+ va := &volumeAttachment{ec2VolAttachment}
+ srv.volumeAttachments[va.VolumeId] = va
@axw

axw Mar 19, 2015

Member

should probably return an error if it's already attached

+ resp.XMLName = xml.Name{defaultXMLName, "AttachVolumeResponse"}
+ resp.RequestId = reqId
+ resp.VolumeId = va.VolumeId
+ resp.InstanceId = va.InstanceId
@axw

axw Mar 19, 2015

Member

validate instance ID is valid, and that the AZs match?

@wallyworld

wallyworld Mar 19, 2015

Member

Instance id validation is done in parseVolume attachment. Added availability zone check.

+ XMLName xml.Name
+ ec2.VolumeAttachmentResp
+ }
+ resp.XMLName = xml.Name{defaultXMLName, "AttachVolumeResponse"}
@axw

axw Mar 19, 2015

Member

DetachVolumeResponse, surely?

+//
+// See http://goo.gl/uXCf9F for more details.
+type CreateVolume struct {
+ AvailZone string
@axw

axw Mar 19, 2015

Member

xml tags on fields?

EDIT: I see other request types don't have it... I guess that's okay, if AWS doesn't care.

ec2/volumes_test.go
+
+ volumeToCreate := ec2.CreateVolume{
+ AvailZone: "us-east-1a",
+ VolumeType: "ssd",
@axw

axw Mar 19, 2015

Member

I think you mean "gp2"? :)

+ resp.Device = va.Device
+ resp.Status = "attaching"
+ resp.AttachTime = time.Now().Format(time.RFC3339)
+ return resp
@axw

axw Mar 19, 2015

Member

It's probably worth updating the instance-deletion code to handle DeleteOnTermination, as we'll need to test that functionality soon enough.

+ VolumeSize: 20,
+ }
+ resp1, err := s.ec2.CreateVolume(vol1)
+ c.Assert(err, IsNil)
@axw

axw Mar 19, 2015

Member

I think you ought to add a deferred DeleteVolume right after creating the volume, in case the rest of the test fails.

@wallyworld

wallyworld Mar 19, 2015

Member

I was conforming with how other existing tests were written :-)
Done in this case.

+ VolumeSize: 20,
+ }
+ resp1, err := s.ec2.CreateVolume(vol1)
+ c.Assert(err, IsNil)
@axw

axw Mar 19, 2015

Member

ditto

Member

axw commented Mar 19, 2015

LGTM, thanks!

wallyworld added a commit that referenced this pull request Mar 19, 2015

Merge pull request #41 from wallyworld/volume-support
Add support for managing volumes

@wallyworld wallyworld merged commit 436847f into go-amz:v3 Mar 19, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment