Skip to content
Permalink
Browse files
Begin refactoring process, messy template usage
  • Loading branch information
brogand93 committed Jun 11, 2014
1 parent 853231f commit 5bb67d516e5acf9c9e141f2e76e249a4fd8c945b
Showing 16 changed files with 167 additions and 122 deletions.
@@ -20,5 +20,12 @@
import os
import glob

__all__ = [os.path.basename(
f)[:-3] for f in glob.glob(os.path.dirname(__file__) + '/*.py')]
__all__ = [os.path.basename(f)[:-3] for f in glob.glob(os.path.dirname(__file__) + '/*.py')]


def filter_by_name(data, name):
for item in data:
if item['name'] == name:
return item

return None
@@ -21,7 +21,9 @@
from flask import request, url_for
from gstack import app, authentication
from gstack.services import requester
from gstack.controllers import zones, helper, errors
from gstack import helpers
from gstack import controllers
from gstack.controllers import zones, errors


def _get_disks(authorization, args=None):
@@ -47,7 +49,7 @@ def get_disk_by_name(authorization, disk):
)

if disk_list['listvolumesresponse']:
response = helper.filter_by_name(
response = controllers.filter_by_name(
data=disk_list['listvolumesresponse']['volume'],
name=disk
)
@@ -66,7 +68,7 @@ def _cloudstack_volume_to_gce(cloudstack_response, projectid, zone):
response['description'] = cloudstack_response['name']
response['sizeGb'] = cloudstack_response['size']

response['selfLink'] = urllib.unquote_plus(helper.get_root_url() + url_for(
response['selfLink'] = urllib.unquote_plus(helpers.get_root_url() + url_for(
'getmachinetype',
projectid=projectid,
machinetype=cloudstack_response['name'],
@@ -88,7 +90,7 @@ def aggregatedlistdisks(projectid, authorization):
zone_list = zones.get_zone_names(authorization=authorization)

disk = None
filter = helper.get_filter(request.args)
filter = helpers.get_filter(request.args)

if 'name' in filter:
disk = filter['name']
@@ -130,14 +132,14 @@ def aggregatedlistdisks(projectid, authorization):
'items': items
}

return helper.create_response(data=populated_response)
return helpers.create_response(data=populated_response)


@app.route('/compute/v1/projects/<projectid>/zones/<zone>/disks', methods=['GET'])
@authentication.required
def listdisks(projectid, authorization, zone):
disk = None
filter = helper.get_filter(request.args)
filter = helpers.get_filter(request.args)

if 'name' in filter:
disk = filter['name']
@@ -150,7 +152,7 @@ def listdisks(projectid, authorization, zone):
args={'keyword': disk}
)
if disk_list['listvolumesresponse']:
disk = helper.filter_by_name(
disk = controllers.filter_by_name(
data=disk_list['listvolumesresponse']['volume'],
name=disk
)
@@ -181,7 +183,7 @@ def listdisks(projectid, authorization, zone):
'items': items
}

return helper.create_response(data=populated_response)
return helpers.create_response(data=populated_response)


@app.route('/compute/v1/projects/<projectid>/zones/<zone>/disks/<disk>', methods=['GET'])
@@ -193,7 +195,7 @@ def getdisk(projectid, authorization, zone, disk):
)

if response:
return helper.create_response(
return helpers.create_response(
data=_cloudstack_volume_to_gce(
cloudstack_response=response,
projectid=projectid,

This file was deleted.

@@ -20,7 +20,9 @@
import urllib
from gstack import app, authentication
from gstack.services import requester
from gstack.controllers import helper, errors
from gstack import helpers
from gstack import controllers
from gstack.controllers import errors
from flask import request, url_for


@@ -50,7 +52,7 @@ def get_template_by_name(authorization, image):
)

if image_list['listtemplatesresponse']:
response = helper.filter_by_name(
response = controllers.filter_by_name(
data=image_list['listtemplatesresponse']['template'],
name=image
)
@@ -62,6 +64,7 @@ def get_template_by_name(authorization, image):
def _create_populated_image_response(projectid, images=None):
if not images:
images = []

populated_response = {
'kind': 'compute#imageList',
'selfLink': request.base_url,
@@ -98,14 +101,14 @@ def _cloudstack_template_to_gce(cloudstack_response, selfLink=None):
@authentication.required
def listnocentoscloudimages(authorization):
populated_response = _create_populated_image_response('centos-cloud')
return helper.create_response(data=populated_response)
return helpers.create_response(data=populated_response)


@app.route('/compute/v1/projects/debian-cloud/global/images', methods=['GET'])
@authentication.required
def listnodebiancloudimages(authorization):
populated_response = _create_populated_image_response('debian-cloud')
return helper.create_response(data=populated_response)
return helpers.create_response(data=populated_response)


@app.route('/compute/v1/projects/<projectid>/global/images', methods=['GET'])
@@ -115,15 +118,20 @@ def listimages(projectid, authorization):
authorization=authorization
)

images = []
if image_list['listtemplatesresponse']:
for image in image_list['listtemplatesresponse']['template']:
images.append(_cloudstack_template_to_gce(
cloudstack_response=image,
selfLink=request.base_url + '/' + image['name']))

populated_response = _create_populated_image_response(projectid, images)
return helper.create_response(data=populated_response)
image['selflink'] = request.base_url + '/' + image['name']

kwargs = {
'template_name_or_list': 'images.json',
'selflink': request.base_url,
'request_id': 'projects/' + projectid + '/global/images',
'request_kind': 'compute#imageList',
'response': image_list['listtemplatesresponse']
}
return helpers.successful_response(
**kwargs
)


@app.route('/compute/v1/projects/<projectid>/global/images/<image>', methods=['GET'])
@@ -135,7 +143,7 @@ def getimage(projectid, authorization, image):
)

if response:
return helper.create_response(
return helpers.create_response(
data=_cloudstack_template_to_gce(response)
)
else:
@@ -19,7 +19,7 @@


from gstack import app
from gstack.controllers import helper
from gstack import helpers
import json


@@ -28,9 +28,9 @@ def discovery():
with open(app.config['DATA'] + '/v1.json') as template:
discovery_template = json.loads(template.read())

discovery_template['baseUrl'] = helper.get_root_url() + '/' + app.config['PATH']
discovery_template['baseUrl'] = helpers.get_root_url() + '/' + app.config['PATH']
discovery_template['basePath'] = '/' + app.config['PATH']
discovery_template['rootUrl'] = helper.get_root_url() + '/'
discovery_template['rootUrl'] = helpers.get_root_url() + '/'
discovery_template['servicePath'] = app.config['PATH']

return helper.create_response(data=discovery_template)
return helpers.create_response(data=discovery_template)
@@ -19,10 +19,12 @@

import json
import urllib
from gstack import helpers
from gstack import controllers
from flask import request, url_for
from gstack import app, authentication
from gstack.services import requester
from gstack.controllers import zones, helper, operations, images, errors, machine_type, networks
from gstack.controllers import zones, operations, images, errors, machine_type, networks


def _get_virtual_machines(authorization, args=None):
@@ -134,7 +136,7 @@ def _cloudstack_virtual_machine_to_gce(cloudstack_response, zone, projectid):

response['networkInterfaces'].append(networking)

response['selfLink'] = urllib.unquote_plus(helper.get_root_url() + url_for(
response['selfLink'] = urllib.unquote_plus(helpers.get_root_url() + url_for(
'getinstance',
projectid=projectid,
instance=cloudstack_response['name'],
@@ -154,7 +156,7 @@ def _get_virtual_machine_by_name(authorization, instance):
)

if virtual_machine_list['listvirtualmachinesresponse']:
response = helper.filter_by_name(
response = controllers.filter_by_name(
data=virtual_machine_list['listvirtualmachinesresponse']['virtualmachine'],
name=instance
)
@@ -170,7 +172,7 @@ def aggregatedlistinstances(authorization, projectid):
virtual_machine_list = _get_virtual_machines(authorization=authorization)

instance = None
filter = helper.get_filter(request.args)
filter = helpers.get_filter(request.args)

if 'name' in filter:
instance = filter['name']
@@ -211,14 +213,14 @@ def aggregatedlistinstances(authorization, projectid):
'selfLink': request.base_url,
'items': items
}
return helper.create_response(data=populated_response)
return helpers.create_response(data=populated_response)


@app.route('/compute/v1/projects/<projectid>/zones/<zone>/instances', methods=['GET'])
@authentication.required
def listinstances(authorization, projectid, zone):
instance = None
filter = helper.get_filter(request.args)
filter = helpers.get_filter(request.args)

if 'name' in filter:
instance = filter['name']
@@ -258,7 +260,7 @@ def listinstances(authorization, projectid, zone):
'items': items
}

return helper.create_response(data=populated_response)
return helpers.create_response(data=populated_response)


@app.route('/compute/v1/projects/<projectid>/zones/<zone>/instances/<instance>', methods=['GET'])
@@ -270,7 +272,7 @@ def getinstance(projectid, authorization, zone, instance):
)

if response:
return helper.create_response(
return helpers.create_response(
data=_cloudstack_virtual_machine_to_gce(
cloudstack_response=response,
projectid=projectid,
@@ -325,7 +327,7 @@ def addinstance(authorization, projectid, zone):
authorization=authorization
)

return helper.create_response(data=populated_response)
return helpers.create_response(data=populated_response)


@app.route('/compute/v1/projects/<projectid>/zones/<zone>/instances/<instance>', methods=['DELETE'])
@@ -339,4 +341,4 @@ def deleteinstance(projectid, authorization, zone, instance):
authorization=authorization
)

return helper.create_response(data=populated_response)
return helpers.create_response(data=populated_response)

0 comments on commit 5bb67d5

Please sign in to comment.