blob: cfebd5d1b5052c76427bbb7fa45fdef0879d7a51 [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
9func GetDefaultConfig(client *gophercloud.ServiceClient, id string) ConfigResult {
10 var res ConfigResult
11
Jamie Hannaforda50d1352015-02-18 11:38:38 +010012 _, res.Err = client.Request("GET", configURL(client, id), gophercloud.RequestOpts{
13 JSONResponse: &res.Body,
14 OkCodes: []int{200},
Jamie Hannaford936a5472015-02-10 14:38:28 +010015 })
16
Jamie Hannaford936a5472015-02-10 14:38:28 +010017 return res
18}
Jamie Hannafordf77fc102015-02-10 14:56:02 +010019
20func AssociateWithConfigGroup(client *gophercloud.ServiceClient, instanceID, configGroupID string) UpdateResult {
21 reqBody := map[string]string{
22 "configuration": configGroupID,
23 }
24
25 var res UpdateResult
26
Jamie Hannaforda50d1352015-02-18 11:38:38 +010027 _, res.Err = client.Request("PUT", resourceURL(client, instanceID), gophercloud.RequestOpts{
28 JSONBody: map[string]map[string]string{"instance": reqBody},
29 OkCodes: []int{202},
Jamie Hannafordf77fc102015-02-10 14:56:02 +010030 })
31
Jamie Hannafordf77fc102015-02-10 14:56:02 +010032 return res
33}
Jamie Hannaford302c0b62015-02-16 14:12:34 +010034
35func ListBackups(client *gophercloud.ServiceClient, instanceID string) pagination.Pager {
Jamie Hannaford2e817322015-02-16 15:29:17 +010036 pageFn := func(r pagination.PageResult) pagination.Page {
37 return backups.BackupPage{pagination.SinglePageBase(r)}
38 }
39 return pagination.NewPager(client, backupsURL(client, instanceID), pageFn)
Jamie Hannaford302c0b62015-02-16 14:12:34 +010040}
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +010041
42func DetachReplica(client *gophercloud.ServiceClient, replicaID string) DetachResult {
43 var res DetachResult
44
Jamie Hannaforda50d1352015-02-18 11:38:38 +010045 _, res.Err = client.Request("PATCH", resourceURL(client, replicaID), gophercloud.RequestOpts{
46 JSONBody: map[string]interface{}{"instance": map[string]string{"replica_of": "", "slave_of": ""}},
47 OkCodes: []int{202},
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +010048 })
49
50 return res
51}