blob: af60620d597bc6f456c026acf4f33f763980baab [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 (
Jamie Hannaford99eced52015-03-02 15:24:22 +01006 "github.com/rackspace/gophercloud"
Jamie Hannaford11108402015-02-23 10:31:41 +01007 "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 Hannaford05d200d2015-02-20 14:49:05 +010013
Jamie Hannaford99eced52015-03-02 15:24:22 +010014func (c *context) createBackup() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010015 opts := backups.CreateOpts{
Jamie Hannaford11108402015-02-23 10:31:41 +010016 Name: tools.RandomString("backup_", 5),
Jamie Hannaford05d200d2015-02-20 14:49:05 +010017 InstanceID: c.instanceID,
18 }
19
Jamie Hannaford11108402015-02-23 10:31:41 +010020 backup, err := backups.Create(c.client, opts).Extract()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010021
22 c.Logf("Created backup %#v", backup)
Jamie Hannaford11108402015-02-23 10:31:41 +010023 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010024
Jamie Hannaford99eced52015-03-02 15:24:22 +010025 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 Hannaford05d200d2015-02-20 14:49:05 +010037 c.backupID = backup.ID
38}
39
Jamie Hannaford99eced52015-03-02 15:24:22 +010040func (c *context) getBackup() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010041 backup, err := backups.Get(c.client, c.backupID).Extract()
42 c.AssertNoErr(err)
43 c.Logf("Getting backup %s", backup.ID)
44}
45
Jamie Hannaford99eced52015-03-02 15:24:22 +010046func (c *context) listAllBackups() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010047 c.Logf("Listing backups")
48
Jamie Hannaford11108402015-02-23 10:31:41 +010049 err := backups.List(c.client, nil).EachPage(func(page pagination.Page) (bool, error) {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010050 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 Hannaford11108402015-02-23 10:31:41 +010060 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010061}
62
Jamie Hannaford99eced52015-03-02 15:24:22 +010063func (c *context) listInstanceBackups() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010064 c.Logf("Listing backups for instance %s", c.instanceID)
65
Jamie Hannaford11108402015-02-23 10:31:41 +010066 err := instances.ListBackups(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010067 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 Hannaford11108402015-02-23 10:31:41 +010077 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010078}
79
Jamie Hannaford99eced52015-03-02 15:24:22 +010080func (c *context) deleteBackup() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010081 err := backups.Delete(c.client, c.backupID).ExtractErr()
82 c.AssertNoErr(err)
83 c.Logf("Deleted backup %s", c.backupID)
84}