Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 1 | // +build acceptance db |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 6 | "github.com/rackspace/gophercloud/acceptance/tools" |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud/pagination" |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 8 | config "github.com/rackspace/gophercloud/rackspace/db/v1/configurations" |
| 9 | "github.com/rackspace/gophercloud/rackspace/db/v1/instances" |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 10 | ) |
| 11 | |
| 12 | func (c context) createConfigGrp() { |
| 13 | opts := config.CreateOpts{ |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 14 | Name: tools.RandomString("config_", 5), |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 15 | Values: map[string]interface{}{ |
| 16 | "connect_timeout": 300, |
| 17 | "join_buffer_size": 900000, |
| 18 | }, |
| 19 | } |
| 20 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 21 | cg, err := config.Create(c.client, opts).Extract() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 22 | |
| 23 | c.AssertNoErr(err) |
| 24 | c.Logf("Created config group %#v", cg) |
| 25 | |
| 26 | c.configGroupID = cg.ID |
| 27 | } |
| 28 | |
| 29 | func (c context) getConfigGrp() { |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 30 | cg, err := config.Get(c.client, c.configGroupID).Extract() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 31 | c.Logf("Getting config group: %#v", cg) |
| 32 | c.AssertNoErr(err) |
| 33 | } |
| 34 | |
| 35 | func (c context) updateConfigGrp() { |
| 36 | opts := config.UpdateOpts{ |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 37 | Name: tools.RandomString("new_name_", 5), |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 38 | 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 | |
| 47 | func (c context) replaceConfigGrp() { |
| 48 | 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 | |
| 59 | func (c context) associateInstanceWithConfigGrp() { |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 60 | err := instances.AssociateWithConfigGroup(c.client, c.instanceID, c.configGroupID).ExtractErr() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 61 | c.Logf("Associated instance %s with config group %s", c.instanceID, c.configGroupID) |
| 62 | c.AssertNoErr(err) |
| 63 | } |
| 64 | |
| 65 | func (c context) listConfigGrpInstances() { |
| 66 | 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 Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 72 | for _, instance := range instanceList { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 73 | c.Logf("Instance: %#v", instance) |
| 74 | } |
| 75 | |
| 76 | return true, nil |
| 77 | }) |
| 78 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 79 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | func (c context) deleteConfigGrp() { |
| 83 | err := config.Delete(c.client, c.configGroupID).ExtractErr() |
| 84 | c.Logf("Deleted config group %s", c.configGroupID) |
| 85 | c.AssertNoErr(err) |
| 86 | } |