Skip to content
Permalink
Browse files
Clean images controller a little
  • Loading branch information
brogand93 committed Feb 21, 2014
1 parent 35fdc50 commit 2ab012296ab9f258957ea967e16dda290d5d4108
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
@@ -70,16 +70,17 @@ def contains_parameter(parameter):


def get_request_paramaters(parameter_type):
root_parameter_id = parameter_type + '.'
root_parameter = parameter_type + '.'
current_parameter_num = 1
current_parameter = root_parameter_id + str(current_parameter_num)
current_parameter = root_parameter + str(current_parameter_num)

parameters = []

while contains_parameter(current_parameter):
paramater = get(current_parameter, request.form)
parameters.append(get(current_parameter, request.form))
current_parameter_num += 1
current_parameter = root_parameter_id + str(current_parameter_num)
current_parameter = root_parameter + str(current_parameter_num)

return parameters

@@ -16,13 +16,13 @@ def describe_item_by_id(item_id, request_function):
def get_items_from_response(response, item_type,
cloudstack_item_attributes_to_aws):
items = []
if response:
for cloudstack_item in response[item_type]:
items.append(
translator.cloudstack_item_to_aws(
cloudstack_item,
cloudstack_item_attributes_to_aws
)

for cloudstack_item in response[item_type]:
items.append(
translator.cloudstack_item_to_aws(
cloudstack_item,
cloudstack_item_attributes_to_aws
)
)

return items
return items
@@ -3,6 +3,7 @@

from ec2stack.helpers import *
from ec2stack.providers.cloudstack import requester, translator
from ec2stack.providers.cloudstack.cloudstack_helpers import *


cloudstack_image_attributes_to_aws = {
@@ -21,11 +22,14 @@ def describe_images():

@authentication_required
def describe_image_attribute():
require_parameters(['ImageId', 'Attribute'])
image_id = get('ImageId', request.form)
attribute = get('Attribute', request.form)

response = _describe_image_by_id(image_id)
response = describe_item_by_id(image_id, _describe_templates_request)

if 'errortext' in response:
invalid_image_id()

template = response['template'][0]

image_attribute = translator.cloudstack_item_attribute_to_aws(
@@ -38,7 +42,8 @@ def describe_image_attribute():

def _describe_all_images():
response = _describe_templates_request()
images = _get_images_from_response(response)
images = get_items_from_response(
response, 'template', cloudstack_image_attributes_to_aws)

return images

@@ -48,18 +53,22 @@ def _describe_specific_images():
images = []

for image_id in image_ids:
response = _describe_image_by_id(image_id)
images = images + _get_images_from_response(response)
response = describe_item_by_id(image_id, _describe_templates_request)
if 'errortext' in response:
invalid_image_id()

return images
images = images + get_items_from_response(
response, 'template', cloudstack_image_attributes_to_aws)

return images

def _describe_image_by_id(image_id):
args = {
'id': image_id
}

return _describe_templates_request(args)
def invalid_image_id():
raise Ec2stackError(
'400',
'InvalidImageId.Malformed',
'The specified Image ID is not valid'
)


def _describe_templates_request(args=None):
@@ -78,20 +87,6 @@ def _describe_templates_request(args=None):
return cloudstack_response


def _get_images_from_response(response):
images = []
if response:
for template in response['template']:
images.append(
translator.cloudstack_item_to_aws(
template,
cloudstack_image_attributes_to_aws
)
)

return images


def _create_describe_image_attribute_response(item_attribute):
response = {
'template_name_or_list': 'image_attribute.xml',
@@ -28,11 +28,13 @@ def describe_instances():

@authentication_required
def describe_instance_attribute():
require_parameters(['InstanceId', 'Attribute'])
instance_id = get('InstanceId', request.form)
attribute = get('Attribute', request.form)

response = describe_item_by_id(instance_id, _describe_virtual_machines_request)
if 'errortext' in response:
invalid_instance_id()

virtual_machine = response['virtualmachine'][0]

instance_attribute = translator.cloudstack_item_attribute_to_aws(
@@ -70,12 +72,23 @@ def _describe_specific_instances():

for instance_id in instance_ids:
response = describe_item_by_id(instance_id, _describe_virtual_machines_request)
if 'errortext' in response:
invalid_instance_id()

instances = instances + get_items_from_response(
response, 'virtualmachine', cloudstack_instance_attributes_to_aws)

return instances


def invalid_instance_id():
raise Ec2stackError(
'400',
'InvalidInstanceId.Malformed',
'The specified Instance ID is not valid'
)


def _create_describe_instance_attribute_response(item_attribute):
response = {
'template_name_or_list': 'instance_attribute.xml',

0 comments on commit 2ab0122

Please sign in to comment.