Storing tags on create db instance and getting tags back in list_tags_for_resource

This commit is contained in:
Mike Fuller 2015-01-27 09:04:39 +11:00
parent 6559d11dd5
commit 2dde94c9be
2 changed files with 21 additions and 7 deletions

View File

@ -14,7 +14,7 @@ class RDS2Response(BaseResponse):
return rds2_backends[self.region]
def _get_db_kwargs(self):
return {
args = {
"auto_minor_version_upgrade": self._get_param('AutoMinorVersionUpgrade'),
"allocated_storage": self._get_int_param('AllocatedStorage'),
"availability_zone": self._get_param("AvailabilityZone"),
@ -39,7 +39,16 @@ class RDS2Response(BaseResponse):
"security_groups": self._get_multi_param('DBSecurityGroups.member'),
"storage_type": self._get_param("StorageType"),
# VpcSecurityGroupIds.member.N
"tags": []
}
count = 1
while self._get_param('Tags.member.{}.Key'.format(count)):
args["tags"].append({
"Key": self._get_param('Tags.member.{}.Key'.format(count)),
"Value": self._get_param('Tags.member.{}.Value'.format(count))
})
count += 1
return args
def _get_db_replica_kwargs(self):
return {
@ -414,9 +423,10 @@ LIST_TAGS_FOR_RESOURCE_TEMPLATE = \
{"TagList": [
{%- for tag in tags -%}
{%- if loop.index != 1 -%},{%- endif -%}
{%- for key in tag -%}
{"Value": "{{ tag[key] }}", "Key": "{{ key }}"}
{%- endfor -%}
{
"Key": "{{ tag['Key'] }}",
"Value": "{{ tag['Value'] }}"
}
{%- endfor -%}
]},
"ResponseMetadata": {

View File

@ -277,15 +277,19 @@ def test_list_tags():
conn = boto.rds2.connect_to_region("us-west-2")
result = conn.list_tags_for_resource('arn:aws:rds:us-west-2:1234567890:db:foo')
result['ListTagsForResourceResponse']['ListTagsForResourceResult']['TagList'].should.equal([])
conn.create_db_instance(db_instance_identifier='db-master-1',
conn.create_db_instance(db_instance_identifier='db-with-tags',
allocated_storage=10,
engine='postgres',
db_instance_class='db.m1.small',
master_username='root',
master_user_password='hunter2',
db_security_groups=["my_sg"],
tags=[{'Key': 'foo', 'Value': 'bar'}])
result = conn.list_tags_for_resource('arn:aws:rds:us-west-2:1234567890:db:db-master-1')
tags=[('foo', 'bar'), ('foo1', 'bar1')])
result = conn.list_tags_for_resource('arn:aws:rds:us-west-2:1234567890:db:db-with-tags')
result['ListTagsForResourceResponse']['ListTagsForResourceResult']['TagList'].should.equal([{'Value': 'bar',
'Key': 'foo'},
{'Value': 'bar1',
'Key': 'foo1'}])
#@disable_on_py3()
#@mock_rds2