Skip to content
Permalink
Browse files
Reformatting
  • Loading branch information
brogand93 committed Feb 21, 2014
1 parent 2ab0122 commit 85108b1f21a19b7711f2395445e7470954b16f77
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 37 deletions.
@@ -73,11 +73,10 @@ def get_request_paramaters(parameter_type):
root_parameter = parameter_type + '.'
current_parameter_num = 1
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 + str(current_parameter_num)
@@ -2,7 +2,7 @@
# encoding: utf-8

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


def describe_item_by_id(item_id, request_function):
@@ -13,15 +13,15 @@ def describe_item_by_id(item_id, request_function):
return request_function(args)


def get_items_from_response(response, item_type,
cloudstack_item_attributes_to_aws):
def get_items_from_response(response, item_type,
cloudstack_item_attributes_to_aws):
items = []

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

@@ -10,6 +10,7 @@
'isready': 'state'
}


@authentication_required
def describe_images():
if contains_parameter('ImageId.1'):
@@ -51,14 +52,14 @@ def _describe_all_images():
def _describe_specific_images():
image_ids = get_request_paramaters('ImageId')
images = []

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

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

return images

@@ -21,7 +21,7 @@ def describe_instances():
else:
instances = _describe_all_instances()

response = _create_describe_instances_response(instances)
response = _create_describe_instances_response(instances)

return response

@@ -31,12 +31,15 @@ def describe_instance_attribute():
instance_id = get('InstanceId', request.form)
attribute = get('Attribute', request.form)

response = describe_item_by_id(instance_id, _describe_virtual_machines_request)
response = describe_item_by_id(
instance_id,
_describe_virtual_machines_request)

if 'errortext' in response:
invalid_instance_id()
invalid_instance_id()

virtual_machine = response['virtualmachine'][0]

instance_attribute = translator.cloudstack_item_attribute_to_aws(
virtual_machine, cloudstack_instance_attributes_to_aws, attribute)

@@ -69,9 +72,11 @@ def _describe_all_instances():
def _describe_specific_instances():
instance_ids = get_request_paramaters('InstanceId')
instances = []

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

@@ -8,43 +8,35 @@
'hypervisor': 'hypervisor',
'displaytext': 'description',
'zonename': 'availability_zone',
'displaytext': 'description',
}


def cloudstack_item_to_aws(cloudstack_item, cloudstack_item_attributes_to_aws):
item = {}

'''
Add general cloudstack attributes map to cloudstack attributes map
specific to item (passed in as arg)
# Add general cloudstack attributes map to cloudstack attributes map
# specific to item (passed in as arg)
# If there is a duplicate the second dictionary takes preference and
# ovverrides the first dictionaries value

If there is a duplicate the second dictionary takes preference and
ovverrides the first dictionaries value
attributes_to_aws_mapping = dict(cloudstack_attributes_to_aws.items() +
cloudstack_item_attributes_to_aws.items())

'''

attributes_to_aws_mapping = dict(cloudstack_attributes_to_aws.items() +
cloudstack_item_attributes_to_aws.items())

for cloudstack_attr, aws_attr in attributes_to_aws_mapping.iteritems():
if cloudstack_attr in cloudstack_item:
item[aws_attr] = cloudstack_item[cloudstack_attr]


return item


def cloudstack_item_attribute_to_aws(
cloudstack_item, cloudstack_item_attributes_to_aws, attribute):
cloudstack_item, cloudstack_item_attributes_to_aws, attribute):

attributes_to_aws_mapping = dict(cloudstack_attributes_to_aws.items() +
cloudstack_item_attributes_to_aws.items())
attributes_to_aws_mapping = dict(cloudstack_attributes_to_aws.items() +
cloudstack_item_attributes_to_aws.items())

item = {}

print(cloudstack_item)

if cloudstack_item[attribute] is not None:
item[
attributes_to_aws_mapping[attribute]
@@ -34,15 +34,14 @@ def _get_volumes_from_response(response, attribute=None):
for volume in response['volume']:
volumes.append(
translator.cloudstack_item_to_aws(
volume,
cloudstack_volume_attributes_to_aws
volume,
cloudstack_volume_attributes_to_aws
)
)

return volumes



def _describe_volumes_response(volumes):
response = {
'template_name_or_list': 'volumes.xml',

0 comments on commit 85108b1

Please sign in to comment.