Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
538 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,152 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
"""This module contains functions for handling requests in relation to tags. | ||
""" | ||
|
||
from flask import current_app | ||
|
||
from ec2stack import helpers, errors | ||
from ec2stack.providers.cloudstack import requester | ||
|
||
|
||
@helpers.authentication_required | ||
def create_tags(): | ||
""" | ||
Create a tag. | ||
@return: Response. | ||
""" | ||
response = _create_tag_request() | ||
return _create_tag_response(response) | ||
|
||
|
||
def _create_tag_request(): | ||
""" | ||
Request to create a tag. | ||
@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', | ||
'resourceids': resource_id, | ||
'resourcetype': resource_type, | ||
'tags[0].key': key, | ||
'tags[0].value': value | ||
} | ||
|
||
response = requester.make_request_async(args) | ||
|
||
return response | ||
|
||
|
||
def _create_tag_response(response): | ||
""" | ||
Generates a response for a create tag request. | ||
@return: Response. | ||
""" | ||
if 'errortext' in response: | ||
if 'Unable to find resource by id' in response['errortext']: | ||
errors.invalid_resource_id() | ||
|
||
return { | ||
'template_name_or_list': 'status.xml', | ||
'response_type': 'CreateTagsResponse', | ||
'return': 'true' | ||
} | ||
|
||
|
||
@helpers.authentication_required | ||
def delete_tags(): | ||
""" | ||
delete a tag. | ||
@return: Response. | ||
""" | ||
response = _delete_tag_request() | ||
return _delete_tag_response(response) | ||
|
||
|
||
def _delete_tag_request(): | ||
""" | ||
Request to delete a tag. | ||
@return: Response. | ||
""" | ||
key = helpers.get('Tag.1.Key') | ||
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': 'deleteTags', | ||
'resourceids': resource_id, | ||
'resourcetype': resource_type, | ||
'tags[0].key': key | ||
} | ||
|
||
response = requester.make_request_async(args) | ||
|
||
return response | ||
|
||
|
||
def _delete_tag_response(response): | ||
""" | ||
Generates a response for a delete tag request. | ||
@return: Response. | ||
""" | ||
if 'errortext' in response: | ||
if 'Unable to find resource by id' in response['errortext']: | ||
errors.invalid_resource_id() | ||
|
||
return { | ||
'template_name_or_list': 'status.xml', | ||
'response_type': 'DeleteTagsResponse', | ||
'return': 'true' | ||
} | ||
|
||
|
||
@helpers.authentication_required | ||
def describe_tags(): | ||
""" | ||
Describe all tags. | ||
@return: Response. | ||
""" | ||
args = {'command': 'listTags'} | ||
response = requester.make_request(args) | ||
|
||
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': 'tags.xml', | ||
'response_type': 'DescribeTagsResponse', | ||
'response': response | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,11 @@ | ||
{% extends "response.xml" %} | ||
{% block response_content %} | ||
{% for tag in response.tag %} | ||
<item> | ||
<resourceId>{{tag.resourceid}}</resourceId> | ||
<resourceType>{{tag.resourcetype}}</resourceType> | ||
<key>{{tag.key}}</key> | ||
<value>{{tag.value}}</value> | ||
</item> | ||
{% endfor %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -2,6 +2,10 @@ | ||
# encoding: utf-8 | ||
|
||
import os | ||
<<<<<<< HEAD | ||
======= | ||
|
||
>>>>>>> tag_support | ||
from setuptools import setup | ||
|
||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,16 @@ | ||
{ | ||
"queryasyncjobresultresponse": { | ||
"jobprocstatus": 0, | ||
"created": "2014-06-01T12:00:56+0200", | ||
"cmd": "org.apache.cloudstack.api.command.user.tag.CreateTagsCmd", | ||
"userid": "26a772da-dc25-4f2b-b0f1-e095e3717a30", | ||
"jobstatus": 1, | ||
"jobid": "036bf202-6fe5-4b73-8823-d9e22cd3c63f", | ||
"jobresultcode": 0, | ||
"jobresulttype": "object", | ||
"jobresult": { | ||
"success": true | ||
}, | ||
"accountid": "ddbdf378-e8d9-47e0-964b-661d0d8414b8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,16 @@ | ||
{ | ||
"queryasyncjobresultresponse": { | ||
"jobprocstatus": 0, | ||
"created": "2014-06-01T12:22:48+0200", | ||
"cmd": "org.apache.cloudstack.api.command.user.tag.DeleteTagsCmd", | ||
"userid": "26a772da-dc25-4f2b-b0f1-e095e3717a30", | ||
"jobstatus": 1, | ||
"jobid": "5af5c011-c708-4f36-8a99-caca51590458", | ||
"jobresultcode": 0, | ||
"jobresulttype": "object", | ||
"jobresult": { | ||
"success": true | ||
}, | ||
"accountid": "ddbdf378-e8d9-47e0-964b-661d0d8414b8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,17 @@ | ||
{ | ||
"queryasyncjobresultresponse": { | ||
"jobprocstatus": 0, | ||
"created": "2014-06-01T13:43:16+0200", | ||
"cmd": "org.apache.cloudstack.api.command.user.tag.CreateTagsCmd", | ||
"userid": "26a772da-dc25-4f2b-b0f1-e095e3717a30", | ||
"jobstatus": 2, | ||
"jobid": "3cca108f-53df-4a57-8975-3caf29e9d313", | ||
"jobresultcode": 530, | ||
"jobresulttype": "object", | ||
"jobresult": { | ||
"errorcode": 530, | ||
"errortext": "Unable to find resource by id a0ae3a53-1f4d-42d3-bbb8-7227bb0e0d and type UserVm" | ||
}, | ||
"accountid": "ddbdf378-e8d9-47e0-964b-661d0d8414b8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,17 @@ | ||
{ | ||
"queryasyncjobresultresponse": { | ||
"jobprocstatus": 0, | ||
"created": "2014-06-01T13:43:16+0200", | ||
"cmd": "org.apache.cloudstack.api.command.user.tag.DeleteTagsCmd", | ||
"userid": "26a772da-dc25-4f2b-b0f1-e095e3717a30", | ||
"jobstatus": 2, | ||
"jobid": "3cca108f-53df-4a57-8975-3caf29e9d313", | ||
"jobresultcode": 530, | ||
"jobresulttype": "object", | ||
"jobresult": { | ||
"errorcode": 530, | ||
"errortext": "Unable to find resource by id a0ae3a53-1f4d-42d3-bbb8-7227bb0e0d and type UserVm" | ||
}, | ||
"accountid": "ddbdf378-e8d9-47e0-964b-661d0d8414b8" | ||
} | ||
} |
Oops, something went wrong.