This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
requests.go
112 lines (97 loc) · 3.57 KB
/
requests.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package replications
import (
"github.com/huaweicloud/golangsdk"
)
var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{
MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
}
// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToReplicationCreateMap() (map[string]interface{}, error)
}
// CreateOpts contains all the values needed to create a new replication.
type CreateOpts struct {
//Protection Group ID
GroupID string `json:"server_group_id" required:"true"`
//Volume ID
VolumeID string `json:"volume_id" required:"true"`
//Replication Name
Name string `json:"name" required:"true"`
//Replication Description
Description string `json:"description,omitempty"`
}
// ToReplicationCreateMap builds a create request body from CreateOpts.
func (opts CreateOpts) ToReplicationCreateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "replication")
}
// Create will create a new Replication based on the values in CreateOpts.
func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r JobResult) {
b, err := opts.ToReplicationCreateMap()
if err != nil {
r.Err = err
return
}
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
_, r.Err = c.Post(rootURL(c), b, &r.Body, reqOpt)
return
}
// UpdateOptsBuilder allows extensions to add additional parameters to the
// Update request.
type UpdateOptsBuilder interface {
ToReplicationUpdateMap() (map[string]interface{}, error)
}
// UpdateOpts contains all the values needed to update a Replication.
type UpdateOpts struct {
//Replication name
Name string `json:"name" required:"true"`
}
// ToReplicationUpdateMap builds a update request body from UpdateOpts.
func (opts UpdateOpts) ToReplicationUpdateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "replication")
}
// Update accepts a UpdateOpts struct and uses the values to update a Replication.The response code from api is 200
func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToReplicationUpdateMap()
if err != nil {
r.Err = err
return
}
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
_, r.Err = c.Put(resourceURL(c, id), b, nil, reqOpt)
return
}
// Get retrieves a particular Replication based on its unique ID.
func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
_, r.Err = c.Get(resourceURL(c, id), &r.Body, &golangsdk.RequestOpts{
MoreHeaders: RequestOpts.MoreHeaders,
})
return
}
// DeleteOptsBuilder allows extensions to add additional parameters to the
// Delete request.
type DeleteOptsBuilder interface {
ToReplicationDeleteMap() (map[string]interface{}, error)
}
// DeleteOpts contains all the values needed to delete a Replication.
type DeleteOpts struct {
//Group ID
GroupID string `json:"server_group_id,omitempty"`
//Delete Target Volume
DeleteVolume bool `json:"delete_target_volume,omitempty"`
}
// ToReplicationDeleteMap builds a update request body from DeleteOpts.
func (opts DeleteOpts) ToReplicationDeleteMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "replication")
}
// Delete will permanently delete a particular Replication based on its unique ID.
func Delete(c *golangsdk.ServiceClient, id string, opts DeleteOptsBuilder) (r JobResult) {
b, err := opts.ToReplicationDeleteMap()
if err != nil {
r.Err = err
return
}
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
_, r.Err = c.DeleteWithBodyResp(resourceURL(c, id), b, &r.Body, reqOpt)
return
}