Skip to content
Permalink
Browse files
Remove unnecessary individual description functions
  • Loading branch information
brogand93 committed Jun 17, 2014
1 parent b7e296d commit 787b72084d552ee7052fb9d7e4b65ec9a9375d96
Showing 10 changed files with 31 additions and 333 deletions.
@@ -22,7 +22,6 @@

from flask import Flask
from gstack.core import db
from flask.ext.sqlalchemy import SQLAlchemy


def _load_config_file():
@@ -52,15 +51,14 @@ def configure_app(settings=None):
app.config['DATA'] = os.path.abspath(os.path.dirname(__file__)) + '/data'

db.init_app(app)
database_uri = _load_database()

if settings:
app.config.from_object(settings)
else:
config_file = _load_config_file()
database_uri = _load_database()
app.config.from_pyfile(config_file)

app.config['SQLALCHEMY_DATABASE_URI'] = database_uri
app.config['SQLALCHEMY_DATABASE_URI'] = database_uri


app = Flask(__name__)
@@ -26,40 +26,6 @@
from gstack.controllers import zones, errors


def _get_disks(authorization, args=None):
command = 'listVolumes'
if not args:
args = {}

cloudstack_response = requester.make_request(
command,
args,
authorization.client_id,
authorization.client_secret
)

return cloudstack_response


def get_disk_by_name(authorization, disk):
disk_list = helpers._get_items(
authorization=authorization,
args={
'keyword': disk,
'command': 'listVolumes'
}
)

if disk_list['listvolumesresponse']:
response = controllers.filter_by_name(
data=disk_list['listvolumesresponse']['volume'],
name=disk
)
return response
else:
return None


def _cloudstack_volume_to_gce(cloudstack_response, projectid, zone):
response = {}
response['kind'] = 'compute#disk'
@@ -19,15 +19,17 @@

from gstack import app
from gstack import authentication
from gstack import controllers
from gstack import helpers
from gstack.services import requester
from gstack.controllers import errors
from flask import jsonify, request, url_for
import json


def _cloudstack_securitygroup_to_gce(response_item):
if 'ingressrule' in response_item:
rules = response_item['ingressrule']
def _cloudstack_securitygroup_to_gce(cloudstack_response):
if 'ingressrule' in cloudstack_response:
rules = cloudstack_response['ingressrule']
allowed = []
sourceranges = []
for rule in rules:
@@ -44,16 +46,16 @@ def _cloudstack_securitygroup_to_gce(response_item):
return ({
"kind": "compute#firewall",
"selfLink": '',
"id": response_item['id'],
"id": cloudstack_response['id'],
"creationTimestamp": '',
"name": response_item['name'],
"description": response_item['description'],
"name": cloudstack_response['name'],
"description": cloudstack_response['description'],
"network": '',
"sourceRanges": sourceranges,
"sourceTags": [
''
],
"targetTags": response_item['tags'],
"targetTags": cloudstack_response['tags'],
"allowed": allowed
})

@@ -64,7 +66,7 @@ def listsecuritygroups(projectid, authorization):
args = {'command':'listSecurityGroups'}
items = controllers.describe_items(
authorization, args, 'securitygroup',
projectid, zone, _cloudstack_securitygroup_to_gce)
_cloudstack_securitygroup_to_gce, **{})

populated_response = {
'kind': 'compute#firewallList',
@@ -73,9 +75,7 @@ def listsecuritygroups(projectid, authorization):
'items': items
}

res = jsonify(populated_response)
res.status_code = 200
return res
return helpers.create_response(data=populated_response)


@app.route('/compute/v1/projects/<projectid>/global/firewalls/<firewall>', methods=['GET'])
@@ -26,41 +26,6 @@
from flask import request, url_for


def _get_templates(authorization, args=None):
command = 'listTemplates'
if not args:
args = {}

if 'templatefilter' not in args:
args['templatefilter'] = 'executable'

cloudstack_response = requester.make_request(
command,
args,
authorization.client_id,
authorization.client_secret
)
return cloudstack_response


def get_template_by_name(authorization, image):
image_list = _get_templates(
authorization=authorization,
args={
'keyword': image
}
)

if image_list['listtemplatesresponse']:
response = controllers.filter_by_name(
data=image_list['listtemplatesresponse']['template'],
name=image
)
return response
else:
return None


def _create_populated_image_response(projectid, images=None):
if not images:
images = []
@@ -91,7 +56,7 @@ def _cloudstack_template_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

@@ -113,18 +78,12 @@ def listnodebiancloudimages(authorization):
@app.route('/compute/v1/projects/<projectid>/global/images', methods=['GET'])
@authentication.required
def listimages(projectid, authorization):
image_list = _get_templates(
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']))
args = {'templatefilter': 'executable', 'command':'listTemplates'}
items = controllers.describe_items(
authorization, args, 'template',
_cloudstack_template_to_gce, **{})

populated_response = _create_populated_image_response(projectid, images)
populated_response = _create_populated_image_response(projectid, items)
return helpers.create_response(data=populated_response)


@@ -27,21 +27,6 @@
from gstack.controllers import zones, operations, images, errors, machine_type, networks


def _get_virtual_machines(authorization, args=None):
command = 'listVirtualMachines'
if not args:
args = {}

cloudstack_response = requester.make_request(
command,
args,
authorization.client_id,
authorization.client_secret
)

return cloudstack_response


def _deploy_virtual_machine(authorization, args, projectid):
command = 'deployVirtualMachine'

@@ -148,24 +133,6 @@ def _cloudstack_virtual_machine_to_gce(cloudstack_response, projectid, zone, **k
return response


def _get_virtual_machine_by_name(authorization, instance):
virtual_machine_list = _get_virtual_machines(
authorization=authorization,
args={
'keyword': instance
}
)

if virtual_machine_list['listvirtualmachinesresponse']:
response = controllers.filter_by_name(
data=virtual_machine_list['listvirtualmachinesresponse']['virtualmachine'],
name=instance
)
return response
else:
return None


@app.route('/compute/v1/projects/<projectid>/aggregated/instances', methods=['GET'])
@authentication.required
def aggregatedlistinstances(authorization, projectid):
@@ -22,42 +22,11 @@
from gstack import authentication
from gstack import helpers
from gstack import controllers
from gstack.services import requester
from gstack.controllers import errors, zones
from flask import request, url_for


def _get_machinetypes(authorization, args=None):
command = 'listServiceOfferings'
if not args:
args = {}

cloudstack_response = requester.make_request(
command,
args,
authorization.client_id,
authorization.client_secret
)
return cloudstack_response


def get_machinetype_by_name(authorization, machinetype):
machinetype_list = _get_machinetypes(
authorization=authorization
)

if machinetype_list['listserviceofferingsresponse']:
response = controllers.filter_by_name(
data=machinetype_list['listserviceofferingsresponse'][
'serviceoffering'],
name=machinetype
)
return response
else:
return None


def _cloudstack_machinetype_to_gce(cloudstack_response, projectid, zone):
def _cloudstack_service_offering_to_gce(cloudstack_response, projectid, zone):
response = {}
response['kind'] = 'compute#machineType'
response['name'] = cloudstack_response['name']
@@ -81,27 +50,11 @@ def _cloudstack_machinetype_to_gce(cloudstack_response, projectid, zone):
@app.route('/compute/v1/projects/<projectid>/aggregated/machineTypes', methods=['GET'])
@authentication.required
def aggregatedlistmachinetypes(projectid, authorization):
machine_types = _get_machinetypes(authorization)
zonelist = zones.get_zone_names(authorization)

items = {}
for zone in zonelist:
zone_machine_types = []
if machine_types['listserviceofferingsresponse']:
for machineType in machine_types['listserviceofferingsresponse']['serviceoffering']:
zone_machine_types.append(
_cloudstack_machinetype_to_gce(
cloudstack_response=machineType,
projectid=projectid,
zone=zone
)
)
else:
zone_machine_types.append(errors.no_results_found(zone))

items['zone/' + zone] = {}
items['zone/' + zone]['zone'] = zone
items['zone/' + zone]['machineTypes'] = zone_machine_types
args = {'command':'listServiceOfferings'}
kwargs = {'projectid':projectid}
items = controllers.describe_items_aggregated(
authorization, args, 'serviceoffering', 'machineTypes',
_cloudstack_service_offering_to_gce, **kwargs)

populated_response = {
'kind': 'compute#machineTypeAggregatedList',
@@ -115,44 +68,11 @@ def aggregatedlistmachinetypes(projectid, authorization):
@app.route('/compute/v1/projects/<projectid>/zones/<zone>/machineTypes', methods=['GET'])
@authentication.required
def listmachinetype(projectid, authorization, zone):
machinetype = None
filter = helpers.get_filter(request.args)

if 'name' in filter:
machinetype = filter['name']

items = []

if machinetype:
machinetype_list = _get_machinetypes(
authorization=authorization,
args={'keyword': machinetype}
)
if machinetype_list['listserviceofferingsresponse']:
machinetype = controllers.filter_by_name(
data=machinetype_list['listserviceofferingsresponse'][
'serviceoffering'],
name=machinetype
)
if machinetype:
items.append(
_cloudstack_machinetype_to_gce(
cloudstack_response=machinetype,
projectid=projectid,
zone=zone
)
)
else:
machinetype_list = _get_machinetypes(authorization=authorization)
if machinetype_list['listserviceofferingsresponse']:
for machinetype in machinetype_list['listserviceofferingsresponse']['serviceoffering']:
items.append(
_cloudstack_machinetype_to_gce(
cloudstack_response=machinetype,
projectid=projectid,
zone=zone
)
)
args = {'command':'listServiceOfferings'}
kwargs = {'projectid':projectid, 'zone':zone}
items = controllers.describe_items(
authorization, args, 'serviceoffering',
_cloudstack_service_offering_to_gce, **kwargs)

populated_response = {
'kind': 'compute#imageList',
@@ -174,7 +94,7 @@ def getmachinetype(projectid, authorization, zone, machinetype):

if response:
return helpers.create_response(
data=_cloudstack_machinetype_to_gce(
data=_cloudstack_service_offering_to_gce(
cloudstack_response=response,
projectid=projectid,
zone=zone

0 comments on commit 787b720

Please sign in to comment.