Skip to content
Permalink
Browse files
Add broken DeleteTags implementation
  • Loading branch information
brogand93 committed May 23, 2014
1 parent e7528be commit 2539be0b8934dada61a61101494f64e49dee69b3
Showing 2 changed files with 67 additions and 15 deletions.
@@ -45,10 +45,11 @@ def _get_action(action):
security_groups.authenticate_security_group_ingress,
'CreateKeyPair': keypairs.create_keypair,
'CreateSecurityGroup': security_groups.create_security_group,
'CreateTag': tags.create_tags,
'CreateTags': tags.create_tags,
'CreateVolume': volumes.create_volume,
'DeleteKeyPair': keypairs.delete_keypair,
'DeleteSecurityGroup': security_groups.delete_security_group,
'DeleteTags': tags.delete_tags,
'DeleteVolume': volumes.delete_volume,
'DescribeAvailabilityZones': zones.describe_zones,
'DescribeImageAttribute': images.describe_image_attribute,
@@ -4,8 +4,9 @@
"""This module contains functions for handling requests in relation to tags.
"""

from ec2stack import helpers
from ec2stack.providers import cloudstack
from flask import current_app

from ec2stack import helpers, errors
from ec2stack.providers.cloudstack import requester


@@ -27,19 +28,26 @@ def _create_tag_request():
@return: Response.
"""

key = helpers.get('Tag.1.Key')
value = helpers.get('Tag.1.Value')
resource_id = helpers.get('ResourceId.1')

if resource_id in current_app.config['RESOURCE_TYPE_MAP']:
resource_type = current_app.config['RESOURCE_TYPE_MAP'][resource_id]
else:
errors.invalid_request(
str(resource_id) +
" not found in configuration")

args = {
'command': 'createTags',
'name': helpers.get('ResourceId')
'resourceIds': resource_id,
'resourceType': resource_type,
'tags[0].key': key,
'tags[0].value': value
}

keys = helpers.get_request_parameter_keys('Key')
values = helpers.get_request_parameter_keys('value')

for index in range(len(keys)):
args['tags[' + index + '].key'] = keys[index]
args['tags[' + index + '].value'] = values[index]

response = requester.make_request(args)
response = requester.make_request_async(args)

response = response['createtagsresponse']

@@ -59,6 +67,52 @@ def _create_tag_response():
}


@helpers.authentication_required
def delete_tags():
"""
delete a tag.
@return: Response.
"""
_delete_tag_request()
return _delete_tag_response()


def _delete_tag_request():
"""
Request to delete a tag.
@return: Response.
"""
key = helpers.get('Tag.1.Key')
resource_id = helpers.get('ResourceId.1')

args = {
'command': 'deleteTag',
'resourceIds': resource_id,
'tags[0].key': key
}

response = requester.make_request_async(args)

response = response['deletetagsresponse']

return response


def _delete_tag_response():
"""
Generates a response for a delete tag request.
@return: Response.
"""
return {
'template_name_or_list': 'status.xml',
'response_type': 'DeleteTagsResponse',
'return': 'true'
}


@helpers.authentication_required
def describe_tags():
"""
@@ -68,9 +122,6 @@ def describe_tags():
"""
args = {'command': 'listTags'}
response = requester.make_request(args)
response = cloudstack.describe_item(
args, 'tag', {}, 'TagId'
)

return _describe_tags_response(
response

0 comments on commit 2539be0

Please sign in to comment.