Merge lp:~mirtchovski/goamz/ec2 into lp:~gophers/goamz/trunk

Proposed by andrey mirtchovski
Status: Needs review
Proposed branch: lp:~mirtchovski/goamz/ec2
Merge into: lp:~gophers/goamz/trunk
Diff against target: 525 lines (+376/-21)
7 files modified
ec2/ec2.go (+119/-18)
ec2/ec2_test.go (+38/-0)
ec2/ec2i_test.go (+69/-0)
ec2/ec2test/filter.go (+2/-2)
ec2/ec2test/server.go (+1/-1)
ec2/responses_test.go (+16/-0)
ec2/volume.go (+131/-0)
To merge this branch: bzr merge lp:~mirtchovski/goamz/ec2
Reviewer Review Type Date Requested Status
The Go Language Gophers Pending
Review via email: mp+129325@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
andrey mirtchovski (mirtchovski) wrote :

This change adds the 'Images' command allowing clients to examine their, as well as public, images available on AWS.

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

This is looking great. We just need some testing.

Revision history for this message
andrey mirtchovski (mirtchovski) wrote :

> This is looking great. We just need some testing.

done. PTAL :)

Revision history for this message
andrey mirtchovski (mirtchovski) wrote :
Download full text (3.4 KiB)

Reviewers: mp+129325_code.launchpad.net,

Message:
Please take a look.

Description:

https://code.launchpad.net/~mirtchovski/goamz/ec2/+merge/129325

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/6745044/

Affected files:
   A [revision details]
   M ec2/ec2i_test.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: ec2/ec2i_test.go
=== modified file 'ec2/ec2i_test.go'
--- ec2/ec2i_test.go 2012-10-17 22:47:42 +0000
+++ ec2/ec2i_test.go 2012-10-18 19:44:38 +0000
@@ -203,3 +203,72 @@
    }
   }
  }
+
+// Cost: unknown
+func (s *ClientTests) TestImages(c *C) {
+ filter := ec2.NewFilter()
+ filter.Add("architecture", "i386")
+ filter.Add("image-type", "machine")
+ filter.Add("description", "http://bitnami.org")
+ filter.Add("is-public", "true")
+
+ id := []string{"ami-fd20ff94"}
+
+ resp1, err := s.ec2.Images(id, filter)
+ c.Assert(err, IsNil)
+
+ i0 := resp1.Images[0]
+ c.Check(i0.Id, Equals, "ami-fd20ff94")
+ c.Check(i0.Name,
Equals, "bitnami-webpack-1.0-0-linux-ubuntu-10.04.3-i386-mp-0b295d82-395d-4b81-89df-5ac5f0b66975-ami-3820fc51.1")
+ c.Check(i0.Description, Equals, "http://bitnami.org")
+ c.Check(i0.Type, Equals, "machine")
+ c.Check(i0.State, Equals, "available")
+ c.Check(i0.Location,
Equals, "aws-marketplace/bitnami-webpack-1.0-0-linux-ubuntu-10.04.3-i386-mp-0b295d82-395d-4b81-89df-5ac5f0b66975-ami-3820fc51.1")
+ c.Check(i0.Public, Equals, true)
+ c.Check(i0.Architecture, Equals, "i386")
+ c.Check(i0.Platform, Equals, "")
+ c.Check(i0.ProductCodes, HasLen, 0)
+ c.Check(i0.KernelId, Equals, "i386")
+ c.Check(i0.RamdiskId, Equals, "")
+ c.Check(i0.StateReason, Equals, "")
+ c.Check(i0.OwnerId, Equals, "679593333241")
+ c.Check(i0.OwnerAlias, Equals, "aws-marketplace")
+ c.Check(i0.RootDeviceType, Equals, "ebs")
+ c.Check(i0.RootDeviceName, Equals, "/dev/sda1")
+ c.Check(i0.VirtualizationType, Equals, "paravirtual")
+ c.Check(i0.Hypervisor, Equals, "xen")
+
+ c.Assert(i0.BlockDevices, HasLen, 1)
+ c.Assert(i0.BlockDevices[0].DeviceName, Equals, "/dev/sda1")
+ c.Assert(i0.BlockDevices[0].SnapshotId, Equals, "snap-5d581d27")
+ c.Assert(i0.BlockDevices[0].VolumeSize, Equals, int64(10))
+ c.Assert(i0.BlockDevices[0].DeleteOnTermination, Equals, true)
+ c.Assert(i0.BlockDevices[0].VolumeType, Equals, "")
+ c.Assert(i0.BlockDevices[0].IOPS, Equals, int64(0))
+}
+
+// Cost: unknown
+func (s *ClientTests) TestSnapshots(c *C) {
+ filter := ec2.NewFilter()
+ filter.Add("volume-id", "vol-37ac485e")
+ filter.Add("status", "completed")
+ filter.Add("start-time", "2008-11-19T10:03:00.000Z")
+
+ id := []string{"snap-9df717f4"}
+
+ resp, err := s.ec2.Snapshots(id, filter)
+ c.Assert(err, IsNil)
+ c.Check(resp.Snapshots, HasLen, 1)
+
+ s0 := resp.Snapshots[0]
+ c.Check(s0.Id, Equals, "snap-9df717f4")
+ c.Check(s0.VolumeId, Equals, "vol-37ac485e")
+ c.Check(s0.Status, Equals, "completed")
+ c.Check(s0.StartTime, Equals, "20...

Read more...

Revision history for this message
andrey mirtchovski (mirtchovski) wrote :

here's what my own command returns (pretty-printed). these public images
were the basis for the tests:

   // $ ./aws images -all architecture=i386
description="http://bitnami.org" image-type="machine"
   ec2.Image{
    ImageId:"ami-fd20ff94",

Location:"aws-marketplace/bitnami-webpack-1.0-0-linux-ubuntu-10.04.3-i386-mp-0b295d82-395d-4b81-89df-5ac5f0b66975-ami-3820fc51.1",

    State:"available",
    Owner:"679593333241",
    Public:true,
    Architecture:"i386",
    ImageType:"machine", ProductCodes:[]string(nil),
KernelId:"aki-805ea7e9", RamdiskId:"", Platform:"",
    StateReason:"",
    OwnerAlias:"aws-marketplace",

Name:"bitnami-webpack-1.0-0-linux-ubuntu-10.04.3-i386-mp-0b295d82-395d-4b81-89df-5ac5f0b66975-ami-3820fc51.1",

    Description:"http://bitnami.org",
    RootDeviceType:"ebs",
    RootDeviceName:"/dev/sda1",
    VirtualizationType:"paravirtual",
    Hypervisor:"xen",
    BlockDevices:[]ec2.BlockDeviceMapping{
     ec2.BlockDeviceMapping{
      DeviceName:"/dev/sda1",
      VirtualName:"",
      Ebs:ec2.EbsBlockDevice{
       SnapshotId:"snap-5d581d27",
       VolumeSize:10,
       DeleteOnTermination:true,
       VolumeType:"",
       Iops:0
      }
     }
    }
   }

   // $ ./aws snapshots snapshot-id=snap-9df717f4 status=completed
start-time=2008-11-19T10:03:00.000Z
   ec2.Snapshot{
    SnapshotId:"snap-9df717f4",
    VolumeId:"vol-37ac485e",
    Status:"completed",
    StartTime:"2008-11-19T10:03:00.000Z",
    Progress:"100%",
    OwnerId:"947081328633",
    VolumeSize:"2",
    Description:"1980 US Census (Linux)",
    OwnerAlias:"amazon",
    Tags:[]ec2.Tag(nil)
   }

https://codereview.appspot.com/6745044/

lp:~mirtchovski/goamz/ec2 updated
22. By Dave Cheney

ec2: sort keys before encoding

Fixes issue #1061941.

R=niemeyer
CC=
https://codereview.appspot.com/6734043

23. By Francisco Souza

iam: add iamtest package

For now, it implements two actions: CreateUser and DeleteUser. More actions
will come in future CLs.

R=niemeyer
CC=
https://codereview.appspot.com/6631063

Revision history for this message
andrey mirtchovski (mirtchovski) wrote :
Revision history for this message
andrey mirtchovski (mirtchovski) wrote :

On 2012/11/08 19:17:30, aam wrote:
> Please take a look.

the new thing here is CreateImage and related tests. the rest are
gofmt-induced changes.

https://codereview.appspot.com/6745044/

Revision history for this message
andrey mirtchovski (mirtchovski) wrote :
lp:~mirtchovski/goamz/ec2 updated
24. By Dave Cheney

aws: add ap-southeast-2 region

Welcome to Sydney.

R=TheMue, rog
CC=
https://codereview.appspot.com/6846050

25. By Dave Cheney

s3: add support for 409 responses

Required to fix LP 1042107

R=fwereade, jameinel, rog
CC=
https://codereview.appspot.com/6901061

26. By andrey mirtchovski

Volume management for ec2

27. By andrey mirtchovski

merge

Unmerged revisions

27. By andrey mirtchovski

merge

26. By andrey mirtchovski

Volume management for ec2

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ec2/ec2.go'
--- ec2/ec2.go 2012-10-28 16:05:46 +0000
+++ ec2/ec2.go 2013-01-21 23:50:27 +0000
@@ -86,7 +86,7 @@
86// ----------------------------------------------------------------------------86// ----------------------------------------------------------------------------
87// Request dispatching logic.87// Request dispatching logic.
8888
89// Error encapsulates an error returned by EC2. 89// Error encapsulates an error returned by EC2.
90//90//
91// See http://goo.gl/VZGuC for more details.91// See http://goo.gl/VZGuC for more details.
92type Error struct {92type Error struct {
@@ -425,15 +425,15 @@
425//425//
426// See http://goo.gl/wnDBf for more details.426// See http://goo.gl/wnDBf for more details.
427type BlockDeviceMapping struct {427type BlockDeviceMapping struct {
428 DeviceName string `xml:"deviceName"`428 DeviceName string `xml:"deviceName"`
429 VirtualName string `xml:"virtualName"`429 VirtualName string `xml:"virtualName"`
430 SnapshotId string `xml:"ebs>snapshotId"`430 SnapshotId string `xml:"ebs>snapshotId"`
431 VolumeType string `xml:"ebs>volumeType"`431 VolumeType string `xml:"ebs>volumeType"`
432 VolumeSize int64 `xml:"ebs>volumeSize"`432 VolumeSize int64 `xml:"ebs>volumeSize"`
433 DeleteOnTermination bool `xml:"ebs>deleteOnTermination"`433 DeleteOnTermination bool `xml:"ebs>deleteOnTermination"`
434434
435 // The number of I/O operations per second (IOPS) that the volume supports.435 // The number of I/O operations per second (IOPS) that the volume supports.
436 IOPS int64 `xml:"ebs>iops"`436 IOPS int64 `xml:"ebs>iops"`
437}437}
438438
439// Image represents details about an image.439// Image represents details about an image.
@@ -467,7 +467,7 @@
467// For example, to get all the private images associated with this account set467// For example, to get all the private images associated with this account set
468// the boolean filter "is-private" to true.468// the boolean filter "is-private" to true.
469//469//
470// Note: calling this function with nil ids and filter parameters will result in 470// Note: calling this function with nil ids and filter parameters will result in
471// a very large number of images being returned.471// a very large number of images being returned.
472//472//
473// See http://goo.gl/SRBhW for more details.473// See http://goo.gl/SRBhW for more details.
@@ -486,6 +486,67 @@
486 return486 return
487}487}
488488
489// The CreateImage type encapsulates options for the respective request in EC2.
490//
491// See http://goo.gl/He9Le for more details.
492type CreateImage struct {
493 InstanceId string
494 Name string
495 Description string
496 NoReboot bool
497 BlockDevices []BlockDeviceMapping
498}
499
500// Response to a CreateImage request.
501//
502// See http://goo.gl/He9Le for more details.
503type CreateImageResp struct {
504 RequestId string `xml:"requestId"`
505 Id string `xml:"imageId"`
506}
507
508// CreateImage creates an EBS-backed image from a running instance.
509//
510// See http://goo.gl/He9Le for more details.
511func (ec2 *EC2) CreateImage(options *CreateImage) (resp *CreateImageResp, err error) {
512 params := makeParams("CreateImage")
513 params["InstanceId"] = options.InstanceId
514 params["Name"] = options.Name
515 params["Description"] = options.Description
516 params["NoReboot"] = strconv.FormatBool(options.NoReboot)
517 //params["BlockDevices"] = options.BlockDevices
518
519 resp = &CreateImageResp{}
520 err = ec2.query(params, resp)
521 if err != nil {
522 return nil, err
523 }
524 return
525}
526
527// The DeregisterImage type encapsulates options for the respective request in EC2.
528//
529// See http://goo.gl/JnVO7 for more details.
530type DeregisterImage struct {
531 ImageId string
532}
533
534// DeregisterImage Deregisters the specified AMI. Once deregistered, the AMI
535// cannot be used to launch new instances.
536//
537// See http://goo.gl/JnVO7 for more details.
538func (ec2 *EC2) DeregisterImage(id string) (resp *SimpleResp, err error) {
539 params := makeParams("DeregisterImage")
540 params["ImageId"] = id
541
542 resp = &SimpleResp{}
543 err = ec2.query(params, resp)
544 if err != nil {
545 return nil, err
546 }
547 return
548}
549
489// Response to a CreateSnapshot request.550// Response to a CreateSnapshot request.
490//551//
491// See http://goo.gl/ttcda for more details.552// See http://goo.gl/ttcda for more details.
@@ -512,11 +573,11 @@
512573
513// DeleteSnapshots deletes the volume snapshots with the given ids.574// DeleteSnapshots deletes the volume snapshots with the given ids.
514//575//
515// Note: If you make periodic snapshots of a volume, the snapshots are 576// Note: If you make periodic snapshots of a volume, the snapshots are
516// incremental so that only the blocks on the device that have changed 577// incremental so that only the blocks on the device that have changed
517// since your last snapshot are incrementally saved in the new snapshot. 578// since your last snapshot are incrementally saved in the new snapshot.
518// Even though snapshots are saved incrementally, the snapshot deletion 579// Even though snapshots are saved incrementally, the snapshot deletion
519// process is designed so that you need to retain only the most recent 580// process is designed so that you need to retain only the most recent
520// snapshot in order to restore the volume.581// snapshot in order to restore the volume.
521//582//
522// See http://goo.gl/vwU1y for more details.583// See http://goo.gl/vwU1y for more details.
@@ -558,7 +619,7 @@
558 Tags []Tag `xml:"tagSet>item"`619 Tags []Tag `xml:"tagSet>item"`
559}620}
560621
561// Snapshots returns details about volume snapshots available to the user. 622// Snapshots returns details about volume snapshots available to the user.
562// The ids and filter parameters, if provided, limit the snapshots returned.623// The ids and filter parameters, if provided, limit the snapshots returned.
563//624//
564// See http://goo.gl/ogJL4 for more details.625// See http://goo.gl/ogJL4 for more details.
@@ -620,7 +681,7 @@
620 Groups []SecurityGroupInfo `xml:"securityGroupInfo>item"`681 Groups []SecurityGroupInfo `xml:"securityGroupInfo>item"`
621}682}
622683
623// SecurityGroup encapsulates details for a security group in EC2. 684// SecurityGroup encapsulates details for a security group in EC2.
624//685//
625// See http://goo.gl/CIdyP for more details.686// See http://goo.gl/CIdyP for more details.
626type SecurityGroupInfo struct {687type SecurityGroupInfo struct {
@@ -785,7 +846,7 @@
785}846}
786847
787// CreateTags adds or overwrites one or more tags for the specified instance ids.848// CreateTags adds or overwrites one or more tags for the specified instance ids.
788// 849//
789// See http://goo.gl/Vmkqc for more details850// See http://goo.gl/Vmkqc for more details
790func (ec2 *EC2) CreateTags(instIds []string, tags []Tag) (resp *SimpleResp, err error) {851func (ec2 *EC2) CreateTags(instIds []string, tags []Tag) (resp *SimpleResp, err error) {
791 params := makeParams("CreateTags")852 params := makeParams("CreateTags")
@@ -863,5 +924,45 @@
863 if err != nil {924 if err != nil {
864 return nil, err925 return nil, err
865 }926 }
866 return resp, nil927 return
928}
929
930// Describes an availability zone
931//
932// See http://goo.gl/Hncxm for more details.
933type AvailZone struct {
934 Name string `xml:"zoneName"`
935 State string `xml:"zoneState"`
936 Region string `xml:"regionName"`
937 Message []string `xml:"messageSet>item"`
938}
939
940// Response to a AvailZone request.
941//
942// See http://goo.gl/bt2rz for more details.
943type AvailZoneResp struct {
944 RequestId string `xml:"requestId"`
945 Zones []AvailZone `xml:"availabilityZoneInfo>item"`
946}
947
948// AvailZones describes one or more of the Availability Zones that are currently
949// available to the account.
950//
951// The results include zones only for the region you're currently using.
952//
953// Filter can contain:
954//
955// message, region-name, state, zone-name
956//
957// See http://goo.gl/bt2rz for more details.
958func (ec2 *EC2) AvailZones(names []string, filter *Filter) (resp *AvailZoneResp, err error) {
959 params := makeParams("DescribeAvailabilityZones")
960 addParamsList(params, "ZoneName", names)
961
962 resp = &AvailZoneResp{}
963 err = ec2.query(params, resp)
964 if err != nil {
965 return nil, err
966 }
967 return
867}968}
868969
=== modified file 'ec2/ec2_test.go'
--- ec2/ec2_test.go 2012-10-18 18:56:09 +0000
+++ ec2/ec2_test.go 2013-01-21 23:50:27 +0000
@@ -291,6 +291,44 @@
291 c.Assert(i0.BlockDevices[0].DeleteOnTermination, Equals, true)291 c.Assert(i0.BlockDevices[0].DeleteOnTermination, Equals, true)
292}292}
293293
294func (s *S) TestCreateImageExample(c *C) {
295 testServer.PrepareResponse(200, nil, CreateImageExample)
296
297 options := ec2.CreateImage{
298 InstanceId: "i-10a64379",
299 Name: "standard-web-server-v1.0",
300 Description: "Standard Web Server v1.0",
301 //NoReboot: false,
302 //BlockDevices: nil,
303 }
304
305 resp, err := s.ec2.CreateImage(&options)
306
307 req := testServer.WaitRequest()
308 c.Assert(req.Form["Action"], DeepEquals, []string{"CreateImage"})
309 c.Assert(req.Form["InstanceId"], DeepEquals, []string{"i-10a64379"})
310 c.Assert(req.Form["Name"], DeepEquals, []string{"standard-web-server-v1.0"})
311 c.Assert(req.Form["Description"], DeepEquals, []string{"Standard Web Server v1.0"})
312 c.Assert(req.Form["NoReboot"], DeepEquals, []string{"false"})
313
314 c.Assert(err, IsNil)
315 c.Assert(resp.RequestId, Equals, "59dbff89-35bd-4eac-99ed-be587EXAMPLE")
316 c.Assert(resp.Id, Equals, "ami-4fa54026")
317}
318
319func (s *S) TestDeregisterImageExample(c *C) {
320 testServer.PrepareResponse(200, nil, DeregisterImageExample)
321
322 resp, err := s.ec2.DeregisterImage("ami-4fa54026")
323
324 req := testServer.WaitRequest()
325 c.Assert(req.Form["Action"], DeepEquals, []string{"DeregisterImage"})
326 c.Assert(req.Form["ImageId"], DeepEquals, []string{"ami-4fa54026"})
327
328 c.Assert(err, IsNil)
329 c.Assert(resp.RequestId, Equals, "59dbff89-35bd-4eac-99ed-be587EXAMPLE")
330}
331
294func (s *S) TestCreateSnapshotExample(c *C) {332func (s *S) TestCreateSnapshotExample(c *C) {
295 testServer.PrepareResponse(200, nil, CreateSnapshotExample)333 testServer.PrepareResponse(200, nil, CreateSnapshotExample)
296334
297335
=== modified file 'ec2/ec2i_test.go'
--- ec2/ec2i_test.go 2012-10-28 16:05:46 +0000
+++ ec2/ec2i_test.go 2013-01-21 23:50:27 +0000
@@ -203,3 +203,72 @@
203 }203 }
204 }204 }
205}205}
206
207// Cost: unknown
208func (s *ClientTests) TestImages(c *C) {
209 filter := ec2.NewFilter()
210 filter.Add("architecture", "i386")
211 filter.Add("image-type", "machine")
212 filter.Add("description", "http://bitnami.org")
213 filter.Add("is-public", "true")
214
215 id := []string{"ami-fd20ff94"}
216
217 resp1, err := s.ec2.Images(id, filter)
218 c.Assert(err, IsNil)
219
220 i0 := resp1.Images[0]
221 c.Check(i0.Id, Equals, "ami-fd20ff94")
222 c.Check(i0.Name, Equals, "bitnami-webpack-1.0-0-linux-ubuntu-10.04.3-i386-mp-0b295d82-395d-4b81-89df-5ac5f0b66975-ami-3820fc51.1")
223 c.Check(i0.Description, Equals, "http://bitnami.org")
224 c.Check(i0.Type, Equals, "machine")
225 c.Check(i0.State, Equals, "available")
226 c.Check(i0.Location, Equals, "aws-marketplace/bitnami-webpack-1.0-0-linux-ubuntu-10.04.3-i386-mp-0b295d82-395d-4b81-89df-5ac5f0b66975-ami-3820fc51.1")
227 c.Check(i0.Public, Equals, true)
228 c.Check(i0.Architecture, Equals, "i386")
229 c.Check(i0.Platform, Equals, "")
230 c.Check(i0.ProductCodes, HasLen, 0)
231 c.Check(i0.KernelId, Equals, "i386")
232 c.Check(i0.RamdiskId, Equals, "")
233 c.Check(i0.StateReason, Equals, "")
234 c.Check(i0.OwnerId, Equals, "679593333241")
235 c.Check(i0.OwnerAlias, Equals, "aws-marketplace")
236 c.Check(i0.RootDeviceType, Equals, "ebs")
237 c.Check(i0.RootDeviceName, Equals, "/dev/sda1")
238 c.Check(i0.VirtualizationType, Equals, "paravirtual")
239 c.Check(i0.Hypervisor, Equals, "xen")
240
241 c.Assert(i0.BlockDevices, HasLen, 1)
242 c.Assert(i0.BlockDevices[0].DeviceName, Equals, "/dev/sda1")
243 c.Assert(i0.BlockDevices[0].SnapshotId, Equals, "snap-5d581d27")
244 c.Assert(i0.BlockDevices[0].VolumeSize, Equals, int64(10))
245 c.Assert(i0.BlockDevices[0].DeleteOnTermination, Equals, true)
246 c.Assert(i0.BlockDevices[0].VolumeType, Equals, "")
247 c.Assert(i0.BlockDevices[0].IOPS, Equals, int64(0))
248}
249
250// Cost: unknown
251func (s *ClientTests) TestSnapshots(c *C) {
252 filter := ec2.NewFilter()
253 filter.Add("volume-id", "vol-37ac485e")
254 filter.Add("status", "completed")
255 filter.Add("start-time", "2008-11-19T10:03:00.000Z")
256
257 id := []string{"snap-9df717f4"}
258
259 resp, err := s.ec2.Snapshots(id, filter)
260 c.Assert(err, IsNil)
261 c.Check(resp.Snapshots, HasLen, 1)
262
263 s0 := resp.Snapshots[0]
264 c.Check(s0.Id, Equals, "snap-9df717f4")
265 c.Check(s0.VolumeId, Equals, "vol-37ac485e")
266 c.Check(s0.Status, Equals, "completed")
267 c.Check(s0.StartTime, Equals, "2008-11-19T10:03:00.000Z")
268 c.Check(s0.Progress, Equals, "100%")
269 c.Check(s0.OwnerId, Equals, "947081328633")
270 c.Check(s0.VolumeSize, Equals, "2")
271 c.Check(s0.Description, Equals, "1980 US Census (Linux)")
272 c.Check(s0.OwnerAlias, Equals, "amazon")
273 c.Check(s0.Tags, HasLen, 0)
274}
206275
=== modified file 'ec2/ec2test/filter.go'
--- ec2/ec2test/filter.go 2012-03-09 14:02:34 +0000
+++ ec2/ec2test/filter.go 2013-01-21 23:50:27 +0000
@@ -13,13 +13,13 @@
13type filter map[string][]string13type filter map[string][]string
1414
15// newFilter creates a new filter from the Filter fields in the url form.15// newFilter creates a new filter from the Filter fields in the url form.
16// 16//
17// The filtering is specified through a map of name=>values, where the17// The filtering is specified through a map of name=>values, where the
18// name is a well-defined key identifying the data to be matched,18// name is a well-defined key identifying the data to be matched,
19// and the list of values holds the possible values the filtered19// and the list of values holds the possible values the filtered
20// item can take for the key to be included in the20// item can take for the key to be included in the
21// result set. For example:21// result set. For example:
22// 22//
23// Filter.1.Name=instance-type23// Filter.1.Name=instance-type
24// Filter.1.Value.1=m1.small24// Filter.1.Value.1=m1.small
25// Filter.1.Value.2=m1.large25// Filter.1.Value.2=m1.large
2626
=== modified file 'ec2/ec2test/server.go'
--- ec2/ec2test/server.go 2012-09-11 14:10:43 +0000
+++ ec2/ec2test/server.go 2013-01-21 23:50:27 +0000
@@ -425,7 +425,7 @@
425 // AvailZone ?425 // AvailZone ?
426 // GroupName tag426 // GroupName tag
427 // Monitoring ignore?427 // Monitoring ignore?
428 // SubnetId ? 428 // SubnetId ?
429 // DisableAPITermination bool429 // DisableAPITermination bool
430 // ShutdownBehavior string430 // ShutdownBehavior string
431 // PrivateIPAddress string431 // PrivateIPAddress string
432432
=== modified file 'ec2/responses_test.go'
--- ec2/responses_test.go 2012-10-17 22:47:42 +0000
+++ ec2/responses_test.go 2013-01-21 23:50:27 +0000
@@ -360,6 +360,22 @@
360</DescribeImagesResponse>360</DescribeImagesResponse>
361`361`
362362
363// http://goo.gl/He9Le
364var CreateImageExample = `
365<CreateImageResponse xmlns="http://ec2.amazonaws.com/doc/2012-10-01/">
366 <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
367 <imageId>ami-4fa54026</imageId>
368</CreateImageResponse>
369`
370
371// http://goo.gl/JnVO7
372var DeregisterImageExample = `
373<DeregisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2012-10-01/">
374 <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
375 <return>true</return>
376</DeregisterImageResponse>
377`
378
363// http://goo.gl/ttcda379// http://goo.gl/ttcda
364var CreateSnapshotExample = `380var CreateSnapshotExample = `
365<CreateSnapshotResponse xmlns="http://ec2.amazonaws.com/doc/2012-10-01/">381<CreateSnapshotResponse xmlns="http://ec2.amazonaws.com/doc/2012-10-01/">
366382
=== added file 'ec2/volume.go'
--- ec2/volume.go 1970-01-01 00:00:00 +0000
+++ ec2/volume.go 2013-01-21 23:50:27 +0000
@@ -0,0 +1,131 @@
1package ec2
2
3import (
4 "errors"
5 "strconv"
6)
7
8// ----------------------------------------------------------------------------
9// Volume management functions.
10
11// The CreateVolume type encapsulates options for the respective request in EC2.
12//
13// See http://goo.gl/iqyMB for more details.
14type CreateVolume struct {
15 SnapshotId string
16 Size int64 // 1-1024, GiBs
17 AvailZone string
18 Type string // io1 | standard (default: standard)
19 IOPS int64
20}
21
22// Response to a CreateVolume response.
23//
24// See http://goo.gl/iqyMB for more details.
25type CreateVolumeResp struct {
26 RequestId string `xml:"requestId"`
27 Volume
28}
29
30// CreateVolume creates a volume snapshot and stores it in S3.
31//
32// See http://goo.gl/iqyMB for more details.
33func (ec2 *EC2) CreateVolume(options *CreateVolume) (resp *CreateVolumeResp, err error) {
34 params := makeParams("CreateVolume")
35 if options.SnapshotId != "" {
36 params["SnapshotId"] = options.SnapshotId
37 }
38 if options.Size < 1 || options.Size > 1024 {
39 return nil, errors.New("size must be between 1 and 1024 GiBs")
40 }
41 params["Size"] = strconv.FormatInt(options.Size, 10)
42
43 if options.AvailZone != "" {
44 params["AvailabilityZone"] = options.AvailZone
45 }
46 if options.Type != "" {
47 params["VolumeType"] = options.Type
48 }
49 if options.IOPS != 0 {
50 params["Iops"] = strconv.FormatInt(options.IOPS, 10)
51 }
52
53 resp = &CreateVolumeResp{}
54 err = ec2.query(params, resp)
55 if err != nil {
56 return nil, err
57 }
58 return
59}
60
61// DeleteVolume deletes the volume with the given id.
62//
63// See http://goo.gl/vwU1y for more details.
64func (ec2 *EC2) DeleteVolume(ids []string) (resp *SimpleResp, err error) {
65 params := makeParams("DeleteVolume")
66 for i, id := range ids {
67 params["VolumeId."+strconv.Itoa(i+1)] = id
68 }
69
70 resp = &SimpleResp{}
71 err = ec2.query(params, resp)
72 if err != nil {
73 return nil, err
74 }
75 return
76}
77
78// Response to a DescribeVolumess request.
79//
80// See http://goo.gl/nClDT for more details.
81type VolumesResp struct {
82 RequestId string `xml:"requestId"`
83 Volumes []Volume `xml:"volumeSet>item"`
84}
85
86// Attachment represents details about a VM a volume is attached to
87//
88// Seee http://goo.gl/tQsRB for more details.
89type Attachment struct {
90 VolumeId string `xml:"volumeId"`
91 InstanceId string `xml:"instanceId"`
92 SnapshotId string `xml:"snapshotId"`
93 Device string `xml:"device"` // "/dev/sdh"
94 Status string `xml:"status"`
95 AttachTime string `xml:"attachTime"`
96 DeleteOnTermination bool `xml:"deleteOnTermination"`
97}
98
99// Volume represents details about a volume snapshot.
100//
101// See http://goo.gl/lB3o2 for more details.
102type Volume struct {
103 Id string `xml:"volumeId"`
104 Size string `xml:"size"`
105 SnapshotId string `xml:"snapshotId"`
106 Status string `xml:"status"`
107 Type string `xml:"volumeType"`
108 CreateTime string `xml:"createTime"`
109 Attachments []Attachment `xml:"attachmentSet>item"`
110 Tags []Tag `xml:"tagSet>item"`
111 IOPS int64 `xml:"iops"`
112}
113
114// Snapshots returns details about volume snapshots available to the user.
115// The ids and filter parameters, if provided, limit the snapshots returned.
116//
117// See http://goo.gl/ogJL4 for more details.
118func (ec2 *EC2) Volumes(ids []string, filter *Filter) (resp *VolumesResp, err error) {
119 params := makeParams("DescribeVolumes")
120 for i, id := range ids {
121 params["VolumeId."+strconv.Itoa(i+1)] = id
122 }
123 filter.addParams(params)
124
125 resp = &VolumesResp{}
126 err = ec2.query(params, resp)
127 if err != nil {
128 return nil, err
129 }
130 return
131}

Subscribers

People subscribed via source and target branches