예제 #1
0
파일: eni.go 프로젝트: dekokun/grabeni
func (c *ENIClient) DescribeInstancesByIDs(instanceIDs []string) ([]*model.Instance, error) {
	p := &ec2.DescribeInstancesInput{
		InstanceIds: aws.StringSlice(instanceIDs),
	}
	resp, err := c.svc.DescribeInstances(p)
	if err != nil {
		return nil, err
	}

	instances := make([]*model.Instance, 0)

	for _, r := range resp.Reservations {
		for _, i := range r.Instances {
			instances = append(instances, model.NewInstance(i))
		}
	}

	return instances, nil
}
예제 #2
0
파일: eni.go 프로젝트: dekokun/grabeni
func (c *ENIClient) DescribeInstanceByID(instanceID string) (*model.Instance, error) {
	p := &ec2.DescribeInstancesInput{
		InstanceIds: []*string{aws.String(instanceID)},
		MaxResults:  aws.Int64(1),
	}
	resp, err := c.svc.DescribeInstances(p)
	if err != nil {
		return nil, err
	}

	if len(resp.Reservations) < 1 {
		return nil, nil // Not found
	}

	instances := resp.Reservations[0].Instances

	if len(instances) < 1 {
		return nil, nil // Not found
	}

	return model.NewInstance(instances[0]), nil
}