blob: 7a1a4f8d5926df5a1ff329c8cd1a665c78be15aa [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 Hannafordb0d267b2015-02-19 11:59:53 +010042// ListBackups will list all the backups for a specified database instance.
Jamie Hannaford302c0b62015-02-16 14:12:34 +010043func ListBackups(client *gophercloud.ServiceClient, instanceID string) pagination.Pager {
Jamie Hannaford2e817322015-02-16 15:29:17 +010044 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 Hannaford302c0b62015-02-16 14:12:34 +010048}
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +010049
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010050// 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 Hannaford4ec6afe2015-02-16 16:52:49 +010053func DetachReplica(client *gophercloud.ServiceClient, replicaID string) DetachResult {
54 var res DetachResult
55
Jamie Hannaforda50d1352015-02-18 11:38:38 +010056 _, 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 Hannaford4ec6afe2015-02-16 16:52:49 +010059 })
60
61 return res
62}