Esempio n. 1
0
// Fill in tags for volume or snapshot
func (d *driver) createTags(ctx types.Context, id, name string) (err error) {
	var (
		ctInput   *awsec2.CreateTagsInput
		inputName string
	)
	initCTInput := func() {
		if ctInput != nil {
			return
		}
		ctInput = &awsec2.CreateTagsInput{
			Resources: []*string{&id},
			Tags:      []*awsec2.Tag{},
		}
		// Append config tag to name
		inputName = d.getFullName(d.getPrintableName(name))
	}

	initCTInput()
	ctInput.Tags = append(
		ctInput.Tags,
		&awsec2.Tag{
			Key:   aws.String("Name"),
			Value: &inputName,
		})

	// TODO rexrayTag
	/*	if d.ec2Tag != "" {
			initCTInput()
			ctInput.Tags = append(
				ctInput.Tags,
				&awsec2.Tag{
					Key:   aws.String(d.rexrayTag()),
					Value: &d.ec2Tag,
				})
		}
	*/
	_, err = mustSession(ctx).CreateTags(ctInput)
	if err != nil {
		return goof.WithError("error creating tags", err)
	}
	return nil
}
Esempio n. 2
0
func CreateSnapshotTags(svc *ec2.EC2, resourceID, volumeName, volumeID string) error {
	var nKey, nVal string

	var tags []*ec2.Tag

	nKey = "Name"

	if volumeName == "" {
		nVal = fmt.Sprintf("%s: %s, %s", *tagPrefix, volumeID, time.Now().Format("2006-01-02"))
	} else {
		nVal = fmt.Sprintf("%s: %s, %s", *tagPrefix, volumeName, time.Now().Format("2006-01-02"))
	}
	tags = append(tags, &ec2.Tag{Key: &nKey, Value: &nVal})

	if *purgeAfterDays > 0 {
		var paKey, paVal string
		var pKey, pVal string
		paKey = PurgeAfterKey
		paVal = time.Now().Add(time.Duration(*purgeAfterDays*24) * time.Hour).Format(PurgeAfterFormat)
		tags = append(tags, &ec2.Tag{Key: &paKey, Value: &paVal})

		pKey = PurgeAllowKey
		pVal = "true"
		tags = append(tags, &ec2.Tag{Key: &pKey, Value: &pVal})
	}

	cti := ec2.CreateTagsInput{Tags: tags}
	cti.Resources = append(cti.Resources, &resourceID)

	_, err := svc.CreateTags(&cti)
	if err != nil {
		return err
	}

	return nil
}