blob: 7c50e19a5016e4bfb45279474e53fcc6aea3e36c [file] [log] [blame]
Jamie Hannaford05d200d2015-02-20 14:49:05 +01001// +build acceptance db
2
3package v1
4
Jamie Hannaford11108402015-02-23 10:31:41 +01005import (
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 Hannaford05d200d2015-02-20 14:49:05 +010012
13func (c context) createBackup() {
14 opts := backups.CreateOpts{
Jamie Hannaford11108402015-02-23 10:31:41 +010015 Name: tools.RandomString("backup_", 5),
Jamie Hannaford05d200d2015-02-20 14:49:05 +010016 InstanceID: c.instanceID,
17 }
18
Jamie Hannaford11108402015-02-23 10:31:41 +010019 backup, err := backups.Create(c.client, opts).Extract()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010020
21 c.Logf("Created backup %#v", backup)
Jamie Hannaford11108402015-02-23 10:31:41 +010022 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010023
24 c.backupID = backup.ID
25}
26
27func (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
33func (c context) listAllBackups() {
34 c.Logf("Listing backups")
35
Jamie Hannaford11108402015-02-23 10:31:41 +010036 err := backups.List(c.client, nil).EachPage(func(page pagination.Page) (bool, error) {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010037 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 Hannaford11108402015-02-23 10:31:41 +010047 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010048}
49
50func (c context) listInstanceBackups() {
51 c.Logf("Listing backups for instance %s", c.instanceID)
52
Jamie Hannaford11108402015-02-23 10:31:41 +010053 err := instances.ListBackups(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010054 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 Hannaford11108402015-02-23 10:31:41 +010064 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010065}
66
67func (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}