Skip to content

Commit

Permalink
Added ec2 tags to volumes and snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
echupriyanov committed Feb 24, 2016
1 parent 0deafa7 commit d1f2f89
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions drivers/storage/ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import (
)

const providerName = "ec2"
const rexrayTag = "rexraySet"

// The EC2 storage driver.
type driver struct {
instanceDocument *instanceIdentityDocument
ec2Instance *ec2.EC2
ec2Tag string
r *core.RexRay
}

Expand Down Expand Up @@ -84,6 +86,12 @@ func (d *driver) Init(r *core.RexRay) error {
if region == "" {
region = d.instanceDocument.Region
}

d.ec2Tag = d.rexrayTag()
if d.ec2Tag == "" {
d.ec2Tag = "rexray"
}

d.ec2Instance = ec2.New(
auth,
aws.Regions[region],
Expand Down Expand Up @@ -233,7 +241,8 @@ func (d *driver) CreateSnapshot(

if snapshotName != "" {
_, err := d.ec2Instance.CreateTags(
[]string{resp.Id}, []ec2.Tag{{"Name", snapshotName}})
[]string{resp.Id}, []ec2.Tag{{"Name", snapshotName},
{rexrayTag, d.ec2Tag}})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -268,6 +277,8 @@ func (d *driver) getSnapshot(
filter.Add("volume-id", volumeID)
}

filter.Add(fmt.Sprintf("tag:%s", rexrayTag), d.ec2Tag)

snapshotList := []string{}
if snapshotID != "" {
//using snapshotList is returning stale data
Expand Down Expand Up @@ -514,7 +525,8 @@ func (d *driver) createVolumeCreateTags(
return
}
_, err = d.ec2Instance.CreateTags(
[]string{resp.VolumeId}, []ec2.Tag{{"Name", volumeName}})
[]string{resp.VolumeId}, []ec2.Tag{{"Name", volumeName},
{rexrayTag, d.ec2Tag}})

return
}
Expand Down Expand Up @@ -553,6 +565,8 @@ func (d *driver) getVolume(
filter.Add("tag:Name", fmt.Sprintf("%s", volumeName))
}

filter.Add(fmt.Sprintf("tag:%s", rexrayTag), d.ec2Tag)

volumeList := []string{}
if volumeID != "" {
volumeList = append(volumeList, volumeID)
Expand Down Expand Up @@ -902,6 +916,10 @@ func (d *driver) CopySnapshot(runAsync bool,
return snapshot[0], nil
}

func (d *driver) rexrayTag() string {
return d.r.Config.GetString("aws.rexrayTag")
}

func (d *driver) accessKey() string {
return d.r.Config.GetString("aws.accessKey")
}
Expand All @@ -919,5 +937,6 @@ func configRegistration() *gofig.Registration {
r.Key(gofig.String, "", "", "", "aws.accessKey")
r.Key(gofig.String, "", "", "", "aws.secretKey")
r.Key(gofig.String, "", "", "", "aws.region")
r.Key(gofig.String, "", "", "", "aws.rexrayTag")
return r
}

0 comments on commit d1f2f89

Please sign in to comment.