-
Notifications
You must be signed in to change notification settings - Fork 7
/
requests.go
51 lines (43 loc) · 1.34 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
package configurations
import (
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud"
)
type ApplyOpts struct {
InstanceIds []string `json:"instance_ids" required:"true"`
}
type ApplyBuilder interface {
ToConfigApplyMap() (map[string]interface{}, error)
}
func (opts ApplyOpts) ToConfigApplyMap() (map[string]interface{}, error) {
b, err := golangsdk.BuildRequestBody(opts, "")
if err != nil {
return nil, err
}
return b, nil
}
func Apply(client *golangsdk.ServiceClient, id string, opts ApplyBuilder) (r ApplyResult) {
b, err := opts.ToConfigApplyMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Put(applyURL(client, id), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
MoreHeaders: map[string]string{"Content-Type": "application/json"},
})
return
}
func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
_, r.Err = client.Get(getURL(client, id), &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
MoreHeaders: map[string]string{"Content-Type": "application/json"},
})
return
}
func GetInstanceConfig(client *golangsdk.ServiceClient, id string) (r GetResult) {
_, r.Err = client.Get(instanceConfigURL(client, id), &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
MoreHeaders: map[string]string{"Content-Type": "application/json"},
})
return
}