Skip to content
Permalink
Browse files
Begin refactor process
  • Loading branch information
brogand93 committed Feb 21, 2014
1 parent 71eb064 commit c80c4748d37f43b66c06cf8568f2932ed66d480c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 51 deletions.
@@ -2,18 +2,13 @@
# encoding: utf-8

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


cloudstack_attributes_to_aws = {
'id': 'id',
'name': 'name',
'isready': 'state',
'hypervisor': 'hypervisor',
'displaytext': 'description'
cloudstack_image_attributes_to_aws = {
'isready': 'state'
}


@authentication_required
def describe_images():
if contains_parameter('ImageId.1'):
@@ -86,26 +81,15 @@ def _get_images_from_response(response, attribute=None):
if response:
for template in response['template']:
images.append(
_cloudstack_template_to_aws_image(template, attribute)
translator.cloudstack_item_to_aws(
template,
cloudstack_image_attributes_to_aws
)
)

return images


def _cloudstack_template_to_aws_image(response, attribute=None):
image = {}
if attribute is not None:
if response[attribute] is not None:
image[
cloudstack_attributes_to_aws[attribute]
] = response[attribute]
else:
for cloudstack_attr, aws_attr in cloudstack_attributes_to_aws.iteritems():
image[aws_attr] = response[cloudstack_attr]

return image


def _create_describe_image_attribute_response(images, attribute):
response = {
'template_name_or_list': 'images.xml',
@@ -2,18 +2,14 @@
# encoding: utf-8

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


cloudstack_attributes_to_aws = {
'id': 'id',
'name': 'name',
'state': 'state',
'zonename': 'availability_zone',
'hypervisor': 'hypervisor',
cloudstack_instance_attributes_to_aws = {
'templateid': 'imageid',
'created': 'launchTime',
'serviceofferingname': 'instanceType'
'serviceofferingname': 'instanceType',
'id': 'instanceId',
'created': 'launchTime'
}


@@ -37,6 +33,7 @@ def describe_instance_attribute():

response = _create_describe_instance_attribute_response(
instance, attribute)

return response


@@ -87,7 +84,10 @@ def _get_instances_from_response(response, attribute=None):
if response:
for virtual_machine in response['virtualmachine']:
instances.append(
_cloudstack_virtual_machine_to_aws(virtual_machine, attribute)
translator.cloudstack_item_to_aws(
virtual_machine,
cloudstack_instance_attributes_to_aws
)
)

return instances
@@ -0,0 +1,47 @@
#!/usr/bin/env python
# encoding: utf-8

cloudstack_attributes_to_aws = {
'id': 'id',
'name': 'name',
'state': 'state',
'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)
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())

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(attribute):
item = {}

if response[attribute] is not None:
item[
cloudstack_attributes_to_aws[attribute]
] = response[attribute]
item['id'] = item['id']

return item
@@ -7,15 +7,13 @@

from ec2stack import helpers
from ec2stack.helpers import authentication_required
from ec2stack.providers.cloudstack import requester
from . import disk_offerings
from ec2stack.providers.cloudstack import requester, translator, disk_offerings


cloudstack_attributes_to_aws = {
cloudstack_volume_attributes_to_aws = {
'id': 'volumeId',
'name': 'name',
'virtualmachineid': 'instanceId',
'created': 'attachTime'
'created': 'createTime'
}


@@ -35,21 +33,15 @@ def _get_volumes_from_response(response, attribute=None):
if response:
for volume in response['volume']:
volumes.append(
_cloudstack_volume_to_aws_volume(volume, attribute)
translator.cloudstack_item_to_aws(
volume,
cloudstack_volume_attributes_to_aws
)
)

return volumes


def _cloudstack_volume_to_aws_volume(response, attribute=None):
volume = {}

for cloudstack_attr, aws_attr in cloudstack_attributes_to_aws.iteritems():
if cloudstack_attr in response:
volume[aws_attr] = response[cloudstack_attr]

return volume


def _describe_volumes_response(volumes):
response = {
@@ -7,7 +7,7 @@
{% for instance in instances %}
<item>
<instanceId>
{{ instance.id }}
{{ instance.instanceId }}
</instanceId>
<name>{{ instance.name }}</name>
<name>{{ instance.state }}</name>
@@ -4,10 +4,10 @@
{% for volume in volumes %}
<item>
<volumeId>
{{ volume.volumeId }}
{{ volume.volumeId }}
</volumeId>
<name>{{ volume.name }}</name>
<createTime>{{ volume.status }}</createTime>
<createTime>{{ volume.createTime }}</createTime>
<attachmentSet>
<item>
<volumeId>

0 comments on commit c80c474

Please sign in to comment.