Skip to content
Permalink
Browse files
Begin addition of support for tags
  • Loading branch information
brogand93 committed May 19, 2014
1 parent c71a1a0 commit 43589256dce04a0eb1487041a111a9c37006c561
Showing 2 changed files with 92 additions and 1 deletion.
@@ -8,7 +8,7 @@
from ec2stack.core import Ec2stackError
from ec2stack.services import USERS
from ec2stack.providers.cloudstack import images, instances, keypairs, \
passwords, security_groups, zones, volumes
passwords, security_groups, zones, volumes, tags


DEFAULT = Blueprint('default', __name__)
@@ -56,6 +56,7 @@ def _get_action(action):
'DescribeInstances': instances.describe_instances,
'DescribeKeyPairs': keypairs.describe_keypairs,
'DescribeSecurityGroups': security_groups.describe_security_groups,
'DescribeTags': tags.describe_tags,
'DescribeVolumes': volumes.describe_volumes,
'DetachVolume': volumes.detach_volume,
'GetPasswordData': passwords.get_password_data,
@@ -0,0 +1,90 @@
#!/usr/bin/env python
# encoding: utf-8

"""This module contains functions for handling requests in relation to tags.
"""

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


@helpers.authentication_required
def create_tag():
"""
Create a tag.
@return: Response.
"""
_create_tag_request()
return _create_tag_response()


def _create_tag_request():
"""
Request to create a tag.
@return: Response.
"""

args = {
'command': 'createTags',
'name': helpers.get('ResourceId')
}

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 = response['createtagsresponse']

return response


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


@helpers.authentication_required
def describe_tags():
"""
Describe all tags.
@return: Response.
"""
args = {'command': 'listTags'}
response = cloudstack.describe_item(
args, 'tag', {}, 'TagId'
)

return _describe_tags_response(
response
)


def _describe_tags_response(response):
"""
Generates a response for a describe tags request.
@param response: Response from Cloudstack.
@return: Response.
"""
return {
'template_name_or_list': 'images.xml',
'response_type': 'DescribeTagsResponse',
'response': response
}

0 comments on commit 4358925

Please sign in to comment.