This repository has been archived by the owner on Jul 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
describe_scaling_activities.go
113 lines (100 loc) · 3.45 KB
/
describe_scaling_activities.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
113
package autoscaling
import (
"encoding/xml"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strconv"
"time"
"github.com/dynport/gocloud/aws"
)
type DescribeScalingActivities struct {
ActivityIds []string
AutoScalingGroupName string
MaxRecords string
NextToken string
}
type Values map[string]string
func (v Values) query() string {
out := url.Values{}
for k, v := range v {
if v != "" {
out[k] = []string{v}
}
}
if len(out) > 0 {
return "?" + out.Encode()
}
return ""
}
func NewFromEnv() *Client {
return &Client{
Client: aws.NewFromEnv(),
}
}
type Client struct {
*aws.Client
}
func (d *DescribeScalingActivities) Execute(client *Client) (*DescribeScalingActivitiesResponse, error) {
ep, e := client.Endpoint()
if e != nil {
return nil, e
}
req, e := http.NewRequest("GET", ep+d.query(), nil)
if e != nil {
return nil, e
}
now := time.Now()
client.SignAwsRequestV2(req, now)
rsp, e := http.DefaultClient.Do(req)
if e != nil {
return nil, e
}
defer rsp.Body.Close()
b, e := ioutil.ReadAll(rsp.Body)
if e != nil {
return nil, e
}
if rsp.Status[0] != '2' {
return nil, fmt.Errorf("expected status 2xx, got %s. %s", rsp.Status, string(b))
}
dsa := &DescribeScalingActivitiesResponse{}
e = xml.Unmarshal(b, dsa)
if e != nil {
return nil, fmt.Errorf(e.Error() + ": " + string(b))
}
return dsa, e
}
func (d *DescribeScalingActivities) query() string {
values := Values{
"NextToken": d.NextToken,
"MaxRecords": d.MaxRecords,
"AutoScalingGroupName": d.AutoScalingGroupName,
"Action": "DescribeScalingActivities",
"Version": "2011-01-01",
}
for i, id := range d.ActivityIds {
values["ActivityIds.member."+strconv.Itoa(i+1)] = id
}
return values.query()
}
type DescribeScalingActivitiesResponse struct {
XMLName xml.Name `xml:"DescribeScalingActivitiesResponse"`
DescribeScalingActivitiesResult *DescribeScalingActivitiesResult `xml:"DescribeScalingActivitiesResult"`
}
type DescribeScalingActivitiesResult struct {
Activities []*Activity `xml:"Activities>member"`
}
type Activity struct {
StatusCode string `xml:"StatusCode"` // Failed</StatusCode>
Progress int `xml:"Progress"` // 0</Progress>
ActivityId string `xml:"ActivityId"` // 063308ae-aa22-4a9b-94f4-9faeEXAMPLE</ActivityId>
StartTime time.Time `xml:"StartTime"` // 2012-04-12T17:32:07.882Z</StartTime>
AutoScalingGroupName string `xml:"AutoScalingGroupName"` // my-test-asg</AutoScalingGroupName>
Cause string `xml:"Cause"` // At 2012-04-12T17:31:30Z a user request created an AutoScalingGroup changing the desired capacity from 0 to 1. At 2012-04-12T17:32:07Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 0 to 1.</Cause>
Details string `xml:"Details"` // {}</Details>
Description string `xml:"Description"` // Launching a new EC2 instance. Status Reason: The image id 'ami-4edb0327' does not exist. Launching EC2 instance failed.</Description>
EndTime time.Time `xml:"EndTime"` // 2012-04-12T17:32:08Z</EndTime>
StatusMessage string `xml:"StatusMessage"` // The image id 'ami-4edb0327' does not exist. Launching EC2 instance failed.</StatusMessage>
}