forked from huaweicloud/huaweicloud-sdk-go
/
requests.go
60 lines (51 loc) · 1.79 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
package notifications
import (
"github.com/gophercloud/gophercloud"
)
func Delete(client *gophercloud.ServiceClient, scalingGroupId string, topicUrn string) (r DeleteResult) {
url := DeleteURL(client, scalingGroupId, topicUrn)
_, r.Err = client.Delete(url, &gophercloud.RequestOpts{
JSONResponse: nil,
OkCodes: []int{204},
})
return
}
type ConfigNotificationOpts struct {
// Specifies a unified topic in SMN.
TopicUrn string `json:"topic_urn" required:"true"`
// Specifies a notification scenario, which can be one of the
// following:SCALING_UP: indicates that the capacity is expanded.SCALING_UP_FAIL:
// indicates that the capacity expansion failed.SCALING_DOWN: indicates that the
// capacity is reduced.SCALING_DOWN_FAIL: indicates that the capacity reduction
// failed.SCALING_GROUP_ABNORMAL: indicates that an exception has occurred in the AS
// group.
TopicScene []string `json:"topic_scene" required:"true"`
}
type ConfigNotificationOptsBuilder interface {
ToNotificationsOptsMap() (map[string]interface{}, error)
}
func (opts ConfigNotificationOpts) ToNotificationsOptsMap() (map[string]interface{}, error) {
b, err := gophercloud.BuildRequestBody(&opts, "")
if err != nil {
return nil, err
}
return b, nil
}
func ConfigNotification(client *gophercloud.ServiceClient, scalingGroupId string, opts ConfigNotificationOptsBuilder) (r EnableResult) {
b, err := opts.ToNotificationsOptsMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Put(EnableURL(client, scalingGroupId), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
return
}
func List(client *gophercloud.ServiceClient, scalingGroupId string) (r ListResult) {
url := ListURL(client, scalingGroupId)
_, r.Err = client.Get(url, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
return
}