blob: 85c37562e68d1501651299e05c9c027e6db836ce [file] [log] [blame]
Jamie Hannaford80c70672015-10-06 16:09:33 +02001// +build acceptance db rackspace
Jamie Hannaford05d200d2015-02-20 14:49:05 +01002
3package v1
4
5import (
Jamie Hannaford11108402015-02-23 10:31:41 +01006 "github.com/rackspace/gophercloud/acceptance/tools"
Jamie Hannaford05d200d2015-02-20 14:49:05 +01007 "github.com/rackspace/gophercloud/pagination"
Jamie Hannaford11108402015-02-23 10:31:41 +01008 config "github.com/rackspace/gophercloud/rackspace/db/v1/configurations"
9 "github.com/rackspace/gophercloud/rackspace/db/v1/instances"
Jamie Hannaford05d200d2015-02-20 14:49:05 +010010)
11
Jamie Hannaford99eced52015-03-02 15:24:22 +010012func (c *context) createConfigGrp() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010013 opts := config.CreateOpts{
Jamie Hannaford11108402015-02-23 10:31:41 +010014 Name: tools.RandomString("config_", 5),
Jamie Hannaford05d200d2015-02-20 14:49:05 +010015 Values: map[string]interface{}{
16 "connect_timeout": 300,
17 "join_buffer_size": 900000,
18 },
19 }
20
Jamie Hannaford11108402015-02-23 10:31:41 +010021 cg, err := config.Create(c.client, opts).Extract()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010022
23 c.AssertNoErr(err)
24 c.Logf("Created config group %#v", cg)
25
26 c.configGroupID = cg.ID
27}
28
Jamie Hannaford99eced52015-03-02 15:24:22 +010029func (c *context) getConfigGrp() {
Jamie Hannaford11108402015-02-23 10:31:41 +010030 cg, err := config.Get(c.client, c.configGroupID).Extract()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010031 c.Logf("Getting config group: %#v", cg)
32 c.AssertNoErr(err)
33}
34
Jamie Hannaford99eced52015-03-02 15:24:22 +010035func (c *context) updateConfigGrp() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010036 opts := config.UpdateOpts{
Jamie Hannaford11108402015-02-23 10:31:41 +010037 Name: tools.RandomString("new_name_", 5),
Jamie Hannaford05d200d2015-02-20 14:49:05 +010038 Values: map[string]interface{}{
39 "connect_timeout": 250,
40 },
41 }
42 err := config.Update(c.client, c.configGroupID, opts).ExtractErr()
43 c.Logf("Updated config group %s", c.configGroupID)
44 c.AssertNoErr(err)
45}
46
Jamie Hannaford99eced52015-03-02 15:24:22 +010047func (c *context) replaceConfigGrp() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010048 opts := config.UpdateOpts{
49 Values: map[string]interface{}{
50 "expire_logs_days": 7,
51 },
52 }
53
54 err := config.Replace(c.client, c.configGroupID, opts).ExtractErr()
55 c.Logf("Replaced values for config group %s", c.configGroupID)
56 c.AssertNoErr(err)
57}
58
Jamie Hannaford99eced52015-03-02 15:24:22 +010059func (c *context) associateInstanceWithConfigGrp() {
Jamie Hannaford11108402015-02-23 10:31:41 +010060 err := instances.AssociateWithConfigGroup(c.client, c.instanceID, c.configGroupID).ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010061 c.Logf("Associated instance %s with config group %s", c.instanceID, c.configGroupID)
62 c.AssertNoErr(err)
63}
64
Jamie Hannaford99eced52015-03-02 15:24:22 +010065func (c *context) listConfigGrpInstances() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010066 c.Logf("Listing all instances associated with config group %s", c.configGroupID)
67
68 err := config.ListInstances(c.client, c.configGroupID).EachPage(func(page pagination.Page) (bool, error) {
69 instanceList, err := instances.ExtractInstances(page)
70 c.AssertNoErr(err)
71
Jamie Hannaford11108402015-02-23 10:31:41 +010072 for _, instance := range instanceList {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010073 c.Logf("Instance: %#v", instance)
74 }
75
76 return true, nil
77 })
78
Jamie Hannaford11108402015-02-23 10:31:41 +010079 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010080}
81
Jamie Hannaford99eced52015-03-02 15:24:22 +010082func (c *context) deleteConfigGrp() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010083 err := config.Delete(c.client, c.configGroupID).ExtractErr()
84 c.Logf("Deleted config group %s", c.configGroupID)
85 c.AssertNoErr(err)
86}
Jamie Hannaford99eced52015-03-02 15:24:22 +010087
88func (c *context) detachInstanceFromGrp() {
89 err := instances.DetachFromConfigGroup(c.client, c.instanceID).ExtractErr()
90 c.Logf("Detached instance %s from config groups", c.instanceID)
91 c.AssertNoErr(err)
92}