forked from aliyun/terraform-provider-alicloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_alicloud_cms.go
71 lines (55 loc) · 1.61 KB
/
service_alicloud_cms.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
package alicloud
import (
"time"
"strconv"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
"github.com/aliyun/alibaba-cloud-sdk-go/services/cms"
"github.com/terraform-providers/terraform-provider-alicloud/alicloud/connectivity"
)
type CmsService struct {
client *connectivity.AliyunClient
}
func (s *CmsService) BuildCmsCommonRequest(region string) *requests.CommonRequest {
request := requests.NewCommonRequest()
return request
}
func (s *CmsService) BuildCmsAlarmRequest(id string) *requests.CommonRequest {
request := s.BuildCmsCommonRequest(s.client.RegionId)
request.QueryParams["Id"] = id
return request
}
func (s *CmsService) DescribeAlarm(id string) (alarm cms.AlarmInListAlarm, err error) {
request := cms.CreateListAlarmRequest()
request.Id = id
raw, err := s.client.WithCmsClient(func(cmsClient *cms.Client) (interface{}, error) {
return cmsClient.ListAlarm(request)
})
if err != nil {
return alarm, err
}
response, _ := raw.(*cms.ListAlarmResponse)
if len(response.AlarmList.Alarm) < 1 {
return alarm, GetNotFoundErrorFromString(GetNotFoundMessage("Alarm Rule", id))
}
return response.AlarmList.Alarm[0], nil
}
func (s *CmsService) WaitForCmsAlarm(id string, enabled bool, timeout int) error {
if timeout <= 0 {
timeout = DefaultTimeout
}
for {
alarm, err := s.DescribeAlarm(id)
if err != nil {
return err
}
if alarm.Enable == enabled {
break
}
timeout = timeout - DefaultIntervalShort
if timeout <= 0 {
return GetTimeErrorFromString(GetTimeoutMessage("Alarm", strconv.FormatBool(enabled)))
}
time.Sleep(DefaultIntervalShort * time.Second)
}
return nil
}