func loadGet(client *ec2.Client, values Values, i interface{}) error { rsp, e := client.DoSignedRequest("GET", endpoint(client.Client), values.Encode(), nil) if e != nil { return e } return xml.Unmarshal(rsp.Content, i) }
func grabSecurityGroupNames(stub map[string]map[string]interface{}, ec2Client *ec2.Client) error { names := make(map[string]interface{}) stub["SecurityGroupName"] = names securityGroupIds := []string{} nameForId := make(map[string]string) for name, id := range stub["SecurityGroup"] { securityGroupIds = append(securityGroupIds, id.(string)) nameForId[id.(string)] = name } groups, err := ec2Client.DescribeSecurityGroups( &ec2.DescribeSecurityGroupsParameters{ GroupIds: securityGroupIds, }, ) if err != nil { return err } for _, group := range groups { name := nameForId[group.GroupId] names[name] = group.GroupName } return nil }
func (action *ListMetrics) Execute(client *ec2.Client) (*ListMetricsResponse, error) { rsp, e := client.DoSignedRequest("GET", endpoint(client.Client), action.query(), nil) if e != nil { return nil, e } o := &ListMetricsResponse{} e = xml.Unmarshal(rsp.Content, o) return o, e }
func grabSubnetInfo(stub map[string]map[string]interface{}, ec2Client *ec2.Client) error { zones := make(map[string]interface{}) octets := make(map[string]interface{}) cidrs := make(map[string]interface{}) stub["SubnetAvailabilityZone"] = zones stub["SubnetOctets"] = octets stub["SubnetCIDR"] = cidrs subnetIds := []string{} nameForId := make(map[string]string) for name, id := range stub["Subnet"] { subnetIds = append(subnetIds, id.(string)) nameForId[id.(string)] = name } subnets, err := ec2Client.DescribeSubnets( &ec2.DescribeSubnetsParameters{ Filters: []*ec2.Filter{ { Name: "subnet-id", Values: subnetIds, }, }, }, ) if err != nil { return err } for _, subnet := range subnets.Subnets { name := nameForId[subnet.SubnetId] _, ipNet, err := net.ParseCIDR(subnet.CidrBlock) if err != nil { return err } zones[name] = subnet.AvailabilityZone cidrs[name] = subnet.CidrBlock octets[name] = []string{ fmt.Sprintf("%d", ipNet.IP[0]), fmt.Sprintf("%d.%d", ipNet.IP[0], ipNet.IP[1]), fmt.Sprintf("%d.%d.%d", ipNet.IP[0], ipNet.IP[1], ipNet.IP[2]), fmt.Sprintf("%d.%d.%d.%d", ipNet.IP[0], ipNet.IP[1], ipNet.IP[2], ipNet.IP[3]), } } return nil }
func (action *GetMetricStatistics) Execute(client *ec2.Client) (*GetMetricStatisticsResponse, error) { if action.StartTime.IsZero() { return nil, fmt.Errorf("StartTime must not be zero") } if action.EndTime.IsZero() { return nil, fmt.Errorf("EndTime must not be zero") } if action.Period == 0 { action.Period = 60 } values := Values{ "Version": VERSION, "Action": "GetMetricStatistics", "MetricName": action.MetricName, "Namespace": action.Namespace, "Period": strconv.Itoa(action.Period), "EndTime": action.EndTime.UTC().Format(time.RFC3339), "StartTime": action.StartTime.UTC().Format(time.RFC3339), "Unit": action.Unit, } for i, s := range action.Statistics { values.Add("Statistics.member."+strconv.Itoa(i+1), s) } values.addDimensions("", action.Dimensions) rsp, e := client.DoSignedRequest("GET", endpoint(client.Client), values.Encode(), nil) if e != nil { return nil, e } i := &GetMetricStatisticsResponse{} e = xml.Unmarshal(rsp.Content, i) return i, e }