Alter get_tags to use the backend associated with the taggable object. Also give volume and snapshot an additional backend attribute.
This commit is contained in:
parent
2f1f993793
commit
f28ad8ee29
@ -109,7 +109,15 @@ class StateReason(object):
|
||||
|
||||
class TaggedEC2Resource(object):
|
||||
def get_tags(self, *args, **kwargs):
|
||||
tags = ec2_backend.describe_tags(filters={'resource-id': [self.id]})
|
||||
if hasattr(self,"ec2_backend"):
|
||||
backend = self.ec2_backend
|
||||
elif hasattr(self,"ebs_backend"):
|
||||
backend = self.ebs_backend
|
||||
else:
|
||||
raise NotImplementedError("Tagging of an object with backend that differs from ec2_backend or ebs_backend.")
|
||||
|
||||
|
||||
tags = backend.describe_tags(filters={'resource-id': [self.id]})
|
||||
return tags
|
||||
|
||||
def get_filter_value(self, filter_name):
|
||||
@ -1224,11 +1232,12 @@ class VolumeAttachment(object):
|
||||
|
||||
|
||||
class Volume(TaggedEC2Resource):
|
||||
def __init__(self, volume_id, size, zone):
|
||||
def __init__(self, ebs_backend, volume_id, size, zone):
|
||||
self.id = volume_id
|
||||
self.size = size
|
||||
self.zone = zone
|
||||
self.attachment = None
|
||||
self.ebs_backend = ebs_backend
|
||||
|
||||
@classmethod
|
||||
def create_from_cloudformation_json(cls, resource_name, cloudformation_json):
|
||||
@ -1253,11 +1262,12 @@ class Volume(TaggedEC2Resource):
|
||||
|
||||
|
||||
class Snapshot(TaggedEC2Resource):
|
||||
def __init__(self, snapshot_id, volume, description):
|
||||
def __init__(self, ebs_backend, snapshot_id, volume, description):
|
||||
self.id = snapshot_id
|
||||
self.volume = volume
|
||||
self.description = description
|
||||
self.create_volume_permission_groups = set()
|
||||
self.ebs_backend = ebs_backend
|
||||
|
||||
|
||||
class EBSBackend(object):
|
||||
@ -1270,7 +1280,7 @@ class EBSBackend(object):
|
||||
def create_volume(self, size, zone_name):
|
||||
volume_id = random_volume_id()
|
||||
zone = self.get_zone_by_name(zone_name)
|
||||
volume = Volume(volume_id, size, zone)
|
||||
volume = Volume(self, volume_id, size, zone)
|
||||
self.volumes[volume_id] = volume
|
||||
return volume
|
||||
|
||||
@ -1312,7 +1322,7 @@ class EBSBackend(object):
|
||||
def create_snapshot(self, volume_id, description):
|
||||
snapshot_id = random_snapshot_id()
|
||||
volume = self.get_volume(volume_id)
|
||||
snapshot = Snapshot(snapshot_id, volume, description)
|
||||
snapshot = Snapshot(self, snapshot_id, volume, description)
|
||||
self.snapshots[snapshot_id] = snapshot
|
||||
return snapshot
|
||||
|
||||
|
@ -315,8 +315,8 @@ def test_retrieved_snapshots_must_contain_their_tags():
|
||||
tag_key = 'Tag name'
|
||||
tag_value = 'Tag value'
|
||||
tags_to_be_set = {tag_key: tag_value}
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
volume = conn.create_volume(80, "us-east-1a")
|
||||
conn = boto.connect_ec2(aws_access_key_id='the_key', aws_secret_access_key='the_secret')
|
||||
volume = conn.create_volume(80, "eu-west-1a")
|
||||
snapshot = conn.create_snapshot(volume.id)
|
||||
conn.create_tags([snapshot.id], tags_to_be_set)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user