Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 1 | package instances |
| 2 | |
| 3 | import ( |
Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 4 | "github.com/rackspace/gophercloud" |
Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 5 | "github.com/rackspace/gophercloud/pagination" |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 6 | "github.com/rackspace/gophercloud/rackspace/db/v1/backups" |
Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 7 | ) |
| 8 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 9 | // GetDefaultConfig lists the default configuration settings from the template |
| 10 | // that was applied to the specified instance. In a sense, this is the vanilla |
| 11 | // configuration setting applied to an instance. Further configuration can be |
| 12 | // applied by associating an instance with a configuration group. |
Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 13 | func GetDefaultConfig(client *gophercloud.ServiceClient, id string) ConfigResult { |
| 14 | var res ConfigResult |
| 15 | |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame] | 16 | _, res.Err = client.Request("GET", configURL(client, id), gophercloud.RequestOpts{ |
| 17 | JSONResponse: &res.Body, |
| 18 | OkCodes: []int{200}, |
Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 19 | }) |
| 20 | |
Jamie Hannaford | 936a547 | 2015-02-10 14:38:28 +0100 | [diff] [blame] | 21 | return res |
| 22 | } |
Jamie Hannaford | f77fc10 | 2015-02-10 14:56:02 +0100 | [diff] [blame] | 23 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 24 | // AssociateWithConfigGroup associates a specified instance to a specified |
| 25 | // configuration group. If any of the parameters within a configuration group |
| 26 | // require a restart, then the instance will transition into a restart. |
Jamie Hannaford | f77fc10 | 2015-02-10 14:56:02 +0100 | [diff] [blame] | 27 | func AssociateWithConfigGroup(client *gophercloud.ServiceClient, instanceID, configGroupID string) UpdateResult { |
| 28 | reqBody := map[string]string{ |
| 29 | "configuration": configGroupID, |
| 30 | } |
| 31 | |
| 32 | var res UpdateResult |
| 33 | |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame] | 34 | _, res.Err = client.Request("PUT", resourceURL(client, instanceID), gophercloud.RequestOpts{ |
| 35 | JSONBody: map[string]map[string]string{"instance": reqBody}, |
| 36 | OkCodes: []int{202}, |
Jamie Hannaford | f77fc10 | 2015-02-10 14:56:02 +0100 | [diff] [blame] | 37 | }) |
| 38 | |
Jamie Hannaford | f77fc10 | 2015-02-10 14:56:02 +0100 | [diff] [blame] | 39 | return res |
| 40 | } |
Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 41 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 42 | // ListBackups will list all the backups for a specified database instance. |
Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 43 | func ListBackups(client *gophercloud.ServiceClient, instanceID string) pagination.Pager { |
Jamie Hannaford | 2e81732 | 2015-02-16 15:29:17 +0100 | [diff] [blame] | 44 | pageFn := func(r pagination.PageResult) pagination.Page { |
| 45 | return backups.BackupPage{pagination.SinglePageBase(r)} |
| 46 | } |
| 47 | return pagination.NewPager(client, backupsURL(client, instanceID), pageFn) |
Jamie Hannaford | 302c0b6 | 2015-02-16 14:12:34 +0100 | [diff] [blame] | 48 | } |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 49 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 50 | // DetachReplica will detach a specified replica instance from its source |
| 51 | // instance, effectively allowing it to operate independently. Detaching a |
| 52 | // replica will restart the MySQL service on the instance. |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 53 | func DetachReplica(client *gophercloud.ServiceClient, replicaID string) DetachResult { |
| 54 | var res DetachResult |
| 55 | |
Jamie Hannaford | a50d135 | 2015-02-18 11:38:38 +0100 | [diff] [blame] | 56 | _, res.Err = client.Request("PATCH", resourceURL(client, replicaID), gophercloud.RequestOpts{ |
| 57 | JSONBody: map[string]interface{}{"instance": map[string]string{"replica_of": "", "slave_of": ""}}, |
| 58 | OkCodes: []int{202}, |
Jamie Hannaford | 4ec6afe | 2015-02-16 16:52:49 +0100 | [diff] [blame] | 59 | }) |
| 60 | |
| 61 | return res |
| 62 | } |