Exemple #1
0
func GetBackupVolumes(svc *ec2.EC2) ([]*ec2.Volume, error) {
	dvi := ec2.DescribeVolumesInput{}

	for _, tag := range tags {
		filter := &ec2.Filter{}
		filterName := "tag:" + *tag
		filter.Name = &filterName
		value := "true"
		filter.Values = []*string{&value}
		dvi.Filters = append(dvi.Filters, filter)
	}

	dvo, err := svc.DescribeVolumes(&dvi)
	if err != nil {
		return nil, fmt.Errorf("describeVolumes error, %s", err)
	}

	return dvo.Volumes, nil
}
Exemple #2
0
// Volumes is a wrapper for (*ec2.EC2).DescribeVolumesPages.
func (c *Client) Volumes() ([]*ec2.Volume, error) {
	var volumes []*ec2.Volume
	var params ec2.DescribeVolumesInput
	if c.MaxResults != 0 {
		params.MaxResults = aws.Int64(c.MaxResults)
	}
	var page int
	err := c.EC2.DescribeVolumesPages(&params, func(resp *ec2.DescribeVolumesOutput, _ bool) bool {
		page++
		c.Log.Debug("received %d volumes (page=%d)", len(resp.Volumes), page)
		volumes = append(volumes, resp.Volumes...)
		return true
	})
	if err != nil {
		return nil, awsError(err)
	}
	if len(volumes) == 0 {
		return nil, newNotFoundError("Volume", errors.New("no volume found"))
	}
	return volumes, nil
}