Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 1 | // +build acceptance db |
| 2 | |
| 3 | package v1 |
| 4 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 5 | import ( |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame^] | 6 | "github.com/rackspace/gophercloud" |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud/acceptance/tools" |
| 8 | "github.com/rackspace/gophercloud/pagination" |
| 9 | |
| 10 | "github.com/rackspace/gophercloud/rackspace/db/v1/backups" |
| 11 | "github.com/rackspace/gophercloud/rackspace/db/v1/instances" |
| 12 | ) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 13 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame^] | 14 | func (c *context) createBackup() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 15 | opts := backups.CreateOpts{ |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 16 | Name: tools.RandomString("backup_", 5), |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 17 | InstanceID: c.instanceID, |
| 18 | } |
| 19 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 20 | backup, err := backups.Create(c.client, opts).Extract() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 21 | |
| 22 | c.Logf("Created backup %#v", backup) |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 23 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 24 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame^] | 25 | err = gophercloud.WaitFor(60, func() (bool, error) { |
| 26 | b, err := backups.Get(c.client, backup.ID).Extract() |
| 27 | if err != nil { |
| 28 | return false, err |
| 29 | } |
| 30 | if b.Status == "COMPLETED" { |
| 31 | return true, nil |
| 32 | } |
| 33 | return false, nil |
| 34 | }) |
| 35 | c.AssertNoErr(err) |
| 36 | |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 37 | c.backupID = backup.ID |
| 38 | } |
| 39 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame^] | 40 | func (c *context) getBackup() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 41 | backup, err := backups.Get(c.client, c.backupID).Extract() |
| 42 | c.AssertNoErr(err) |
| 43 | c.Logf("Getting backup %s", backup.ID) |
| 44 | } |
| 45 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame^] | 46 | func (c *context) listAllBackups() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 47 | c.Logf("Listing backups") |
| 48 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 49 | err := backups.List(c.client, nil).EachPage(func(page pagination.Page) (bool, error) { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 50 | backupList, err := backups.ExtractBackups(page) |
| 51 | c.AssertNoErr(err) |
| 52 | |
| 53 | for _, b := range backupList { |
| 54 | c.Logf("Backup: %#v", b) |
| 55 | } |
| 56 | |
| 57 | return true, nil |
| 58 | }) |
| 59 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 60 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame^] | 63 | func (c *context) listInstanceBackups() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 64 | c.Logf("Listing backups for instance %s", c.instanceID) |
| 65 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 66 | err := instances.ListBackups(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 67 | backupList, err := backups.ExtractBackups(page) |
| 68 | c.AssertNoErr(err) |
| 69 | |
| 70 | for _, b := range backupList { |
| 71 | c.Logf("Backup: %#v", b) |
| 72 | } |
| 73 | |
| 74 | return true, nil |
| 75 | }) |
| 76 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 77 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame^] | 80 | func (c *context) deleteBackup() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 81 | err := backups.Delete(c.client, c.backupID).ExtractErr() |
| 82 | c.AssertNoErr(err) |
| 83 | c.Logf("Deleted backup %s", c.backupID) |
| 84 | } |