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 ( |
| 6 | "github.com/rackspace/gophercloud/acceptance/tools" |
| 7 | "github.com/rackspace/gophercloud/pagination" |
| 8 | |
| 9 | "github.com/rackspace/gophercloud/rackspace/db/v1/backups" |
| 10 | "github.com/rackspace/gophercloud/rackspace/db/v1/instances" |
| 11 | ) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 12 | |
| 13 | func (c context) createBackup() { |
| 14 | opts := backups.CreateOpts{ |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 15 | Name: tools.RandomString("backup_", 5), |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 16 | InstanceID: c.instanceID, |
| 17 | } |
| 18 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 19 | backup, err := backups.Create(c.client, opts).Extract() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 20 | |
| 21 | c.Logf("Created backup %#v", backup) |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 22 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 23 | |
| 24 | c.backupID = backup.ID |
| 25 | } |
| 26 | |
| 27 | func (c context) getBackup() { |
| 28 | backup, err := backups.Get(c.client, c.backupID).Extract() |
| 29 | c.AssertNoErr(err) |
| 30 | c.Logf("Getting backup %s", backup.ID) |
| 31 | } |
| 32 | |
| 33 | func (c context) listAllBackups() { |
| 34 | c.Logf("Listing backups") |
| 35 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 36 | 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] | 37 | backupList, err := backups.ExtractBackups(page) |
| 38 | c.AssertNoErr(err) |
| 39 | |
| 40 | for _, b := range backupList { |
| 41 | c.Logf("Backup: %#v", b) |
| 42 | } |
| 43 | |
| 44 | return true, nil |
| 45 | }) |
| 46 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 47 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | func (c context) listInstanceBackups() { |
| 51 | c.Logf("Listing backups for instance %s", c.instanceID) |
| 52 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 53 | 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] | 54 | backupList, err := backups.ExtractBackups(page) |
| 55 | c.AssertNoErr(err) |
| 56 | |
| 57 | for _, b := range backupList { |
| 58 | c.Logf("Backup: %#v", b) |
| 59 | } |
| 60 | |
| 61 | return true, nil |
| 62 | }) |
| 63 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 64 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | func (c context) deleteBackup() { |
| 68 | err := backups.Delete(c.client, c.backupID).ExtractErr() |
| 69 | c.AssertNoErr(err) |
| 70 | c.Logf("Deleted backup %s", c.backupID) |
| 71 | } |