blob: bd8a899878e33a0e6ddf04a74c77cfecb72035fa [file] [log] [blame]
Jamie Hannaford936a5472015-02-10 14:38:28 +01001package instances
2
3import (
Jamie Hannaford936a5472015-02-10 14:38:28 +01004 "github.com/rackspace/gophercloud"
Jamie Hannaford302c0b62015-02-16 14:12:34 +01005 "github.com/rackspace/gophercloud/pagination"
Jamie Hannaford2e817322015-02-16 15:29:17 +01006 "github.com/rackspace/gophercloud/rackspace/db/v1/backups"
Jamie Hannaford936a5472015-02-10 14:38:28 +01007)
8
Jamie Hannafordb0d267b2015-02-19 11:59:53 +01009// 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 Hannaford936a5472015-02-10 14:38:28 +010013func GetDefaultConfig(client *gophercloud.ServiceClient, id string) ConfigResult {
14 var res ConfigResult
15
Jamie Hannaforda50d1352015-02-18 11:38:38 +010016 _, res.Err = client.Request("GET", configURL(client, id), gophercloud.RequestOpts{
17 JSONResponse: &res.Body,
18 OkCodes: []int{200},
Jamie Hannaford936a5472015-02-10 14:38:28 +010019 })
20
Jamie Hannaford936a5472015-02-10 14:38:28 +010021 return res
22}
Jamie Hannafordf77fc102015-02-10 14:56:02 +010023
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010024// 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 Hannafordf77fc102015-02-10 14:56:02 +010027func AssociateWithConfigGroup(client *gophercloud.ServiceClient, instanceID, configGroupID string) UpdateResult {
28 reqBody := map[string]string{
29 "configuration": configGroupID,
30 }
31
32 var res UpdateResult
33
Jamie Hannaforda50d1352015-02-18 11:38:38 +010034 _, res.Err = client.Request("PUT", resourceURL(client, instanceID), gophercloud.RequestOpts{
35 JSONBody: map[string]map[string]string{"instance": reqBody},
36 OkCodes: []int{202},
Jamie Hannafordf77fc102015-02-10 14:56:02 +010037 })
38
Jamie Hannafordf77fc102015-02-10 14:56:02 +010039 return res
40}
Jamie Hannaford302c0b62015-02-16 14:12:34 +010041
Jamie Hannaford99eced52015-03-02 15:24:22 +010042// DetachFromConfigGroup will detach an instance from all config groups.
43func DetachFromConfigGroup(client *gophercloud.ServiceClient, instanceID string) UpdateResult {
44 return AssociateWithConfigGroup(client, instanceID, "")
45}
46
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010047// ListBackups will list all the backups for a specified database instance.
Jamie Hannaford302c0b62015-02-16 14:12:34 +010048func ListBackups(client *gophercloud.ServiceClient, instanceID string) pagination.Pager {
Jamie Hannaford2e817322015-02-16 15:29:17 +010049 pageFn := func(r pagination.PageResult) pagination.Page {
50 return backups.BackupPage{pagination.SinglePageBase(r)}
51 }
52 return pagination.NewPager(client, backupsURL(client, instanceID), pageFn)
Jamie Hannaford302c0b62015-02-16 14:12:34 +010053}
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +010054
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010055// DetachReplica will detach a specified replica instance from its source
56// instance, effectively allowing it to operate independently. Detaching a
57// replica will restart the MySQL service on the instance.
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +010058func DetachReplica(client *gophercloud.ServiceClient, replicaID string) DetachResult {
59 var res DetachResult
60
Jamie Hannaforda50d1352015-02-18 11:38:38 +010061 _, res.Err = client.Request("PATCH", resourceURL(client, replicaID), gophercloud.RequestOpts{
62 JSONBody: map[string]interface{}{"instance": map[string]string{"replica_of": "", "slave_of": ""}},
63 OkCodes: []int{202},
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +010064 })
65
66 return res
67}