blob: 66bc872b5f985b3f9d5cd77c14cb4495e7f00e21 [file] [log] [blame]
Jamie Hannaford936a5472015-02-10 14:38:28 +01001package instances
2
3import (
4 "github.com/racker/perigee"
5 "github.com/rackspace/gophercloud"
Jamie Hannaford302c0b62015-02-16 14:12:34 +01006 "github.com/rackspace/gophercloud/pagination"
Jamie Hannaford2e817322015-02-16 15:29:17 +01007 "github.com/rackspace/gophercloud/rackspace/db/v1/backups"
Jamie Hannaford936a5472015-02-10 14:38:28 +01008)
9
10func GetDefaultConfig(client *gophercloud.ServiceClient, id string) ConfigResult {
11 var res ConfigResult
12
Jamie Hannaford2e817322015-02-16 15:29:17 +010013 _, res.Err = perigee.Request("GET", configURL(client, id), perigee.Options{
Jamie Hannaford936a5472015-02-10 14:38:28 +010014 MoreHeaders: client.AuthenticatedHeaders(),
15 Results: &res.Body,
16 OkCodes: []int{200},
17 })
18
Jamie Hannaford936a5472015-02-10 14:38:28 +010019 return res
20}
Jamie Hannafordf77fc102015-02-10 14:56:02 +010021
22func AssociateWithConfigGroup(client *gophercloud.ServiceClient, instanceID, configGroupID string) UpdateResult {
23 reqBody := map[string]string{
24 "configuration": configGroupID,
25 }
26
27 var res UpdateResult
28
Jamie Hannaford2e817322015-02-16 15:29:17 +010029 _, res.Err = perigee.Request("PUT", resourceURL(client, instanceID), perigee.Options{
Jamie Hannafordf77fc102015-02-10 14:56:02 +010030 MoreHeaders: client.AuthenticatedHeaders(),
31 ReqBody: map[string]map[string]string{"instance": reqBody},
32 OkCodes: []int{202},
33 })
34
Jamie Hannafordf77fc102015-02-10 14:56:02 +010035 return res
36}
Jamie Hannaford302c0b62015-02-16 14:12:34 +010037
38func ListBackups(client *gophercloud.ServiceClient, instanceID string) pagination.Pager {
Jamie Hannaford2e817322015-02-16 15:29:17 +010039 pageFn := func(r pagination.PageResult) pagination.Page {
40 return backups.BackupPage{pagination.SinglePageBase(r)}
41 }
42 return pagination.NewPager(client, backupsURL(client, instanceID), pageFn)
Jamie Hannaford302c0b62015-02-16 14:12:34 +010043}
Jamie Hannaford4ec6afe2015-02-16 16:52:49 +010044
45func DetachReplica(client *gophercloud.ServiceClient, replicaID string) DetachResult {
46 var res DetachResult
47
48 _, res.Err = perigee.Request("PATCH", resourceURL(client, replicaID), perigee.Options{
49 MoreHeaders: client.AuthenticatedHeaders(),
50 ReqBody: map[string]interface{}{"instance": map[string]string{"replica_of": "", "slave_of": ""}},
51 OkCodes: []int{202},
52 })
53
54 return res
55}