Skip to content
Permalink
Browse files
Code cutdown in controllers
  • Loading branch information
brogand93 committed Jun 17, 2014
1 parent 787b720 commit d705e338d49fb0a72ef038f7df0caff7385dbfba
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
@@ -173,19 +173,14 @@ def listinstances(authorization, projectid, zone):
@app.route('/compute/v1/projects/<projectid>/zones/<zone>/instances/<instance>', methods=['GET'])
@authentication.required
def getinstance(projectid, authorization, zone, instance):
response = _get_virtual_machine_by_name(
authorization=authorization,
instance=instance
)
args = {'command':'listVirtualMachines'}
kwargs = {'projectid':projectid, 'zone':zone}
items = controllers.describe_items(
authorization, args, 'virtualmachine',
_cloudstack_virtual_machine_to_gce, name=instance, **kwargs)

if response:
return helpers.create_response(
data=_cloudstack_virtual_machine_to_gce(
cloudstack_response=response,
projectid=projectid,
zone=zone
)
)
if items:
helpers.create_response(items)
else:
function_route = url_for(
'getinstance',
@@ -72,7 +72,7 @@ def _cloudstack_network_to_gce(cloudstack_response, selfLink=None):
if selfLink:
response['selfLink'] = urllib.unquote_plus(selfLink)
else:
response['selfLink'] = urllib.unquote_plus(request.base_url)
response['selfLink'] = urllib.unquote_plus(request.base_url) + '/' + response['name']

return response

@@ -93,20 +93,15 @@ def _create_populated_network_response(projectid, networks=None):
@app.route('/compute/v1/projects/<projectid>/global/networks', methods=['GET'])
@authentication.required
def listnetworks(projectid, authorization):
securitygroup_list = _get_networks(
authorization=authorization
)

networks = []
if securitygroup_list['listsecuritygroupsresponse']:
for network in securitygroup_list['listsecuritygroupsresponse']['securitygroup']:
networks.append(_cloudstack_network_to_gce(
cloudstack_response=network,
selfLink=request.base_url + '/' + network['name']))
args = {'command':'listSecurityGroups'}
kwargs = {}
items = controllers.describe_items(
authorization, args, 'securitygroup',
_cloudstack_network_to_gce, **kwargs)

populated_response = _create_populated_network_response(
projectid,
networks
items
)
return helpers.create_response(data=populated_response)

@@ -20,36 +20,36 @@

from gstack import app
from gstack import helpers
from gstack import controllers
from gstack import authentication
from gstack.controllers import errors
from flask import request, url_for


def _cloudstack_region_to_gce(response_item):
def _cloudstack_account_to_gce(cloudstack_response):
response = {}
response['kind'] = 'compute#region'
response['description'] = response_item['name']
response['id'] = response_item['id']
response['description'] = cloudstack_response['name']
response['name'] = cloudstack_response['name']
response['id'] = cloudstack_response['id']
response['status'] = 'UP'
return response


@app.route('/compute/v1/projects/<projectid>/regions', methods=['GET'])
@authentication.required
def listregions(projectid, authorization):
cloudstack_response = _get_regions(authorization)

regions = []

if cloudstack_response['listregionsresponse']:
for region in cloudstack_response['listregionsresponse']['region']:
regions.append(_cloudstack_region_to_gce(region))
args = {'command':'listAccounts'}
kwargs = {}
items = controllers.describe_items(
authorization, args, 'account',
_cloudstack_account_to_gce, **kwargs)

populated_response = {
'kind': 'compute#regionList',
'id': 'projects/' + projectid + '/regions',
'selfLink': request.base_url,
'items': regions
'items': items
}
return helpers.create_response(data=populated_response)

@@ -64,7 +64,7 @@ def getregion(projectid, authorization, region):

if region == cloudstack_response['listregionsresponse']['region'][0]['name']:
return helpers.create_response(
data=_cloudstack_region_to_gce(
data=_cloudstack_account_to_gce(
cloudstack_response['listregionsresponse']['region'][0]
)
)
@@ -25,6 +25,20 @@
from gstack.controllers import errors


def _get_zones(authorization, args=None):
command = 'listZones'
if not args:
args = {}
cloudstack_response = requester.make_request(
command,
args,
authorization.client_id,
authorization.client_secret
)

return cloudstack_response


def get_zone_names(authorization):
zone_list = _get_zones(authorization)

0 comments on commit d705e33

Please sign in to comment.