Remove unnecessary individual description functions
Project: http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/commit/787b7208 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/tree/787b7208 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/diff/787b7208 Branch: refs/heads/master Commit: 787b72084d552ee7052fb9d7e4b65ec9a9375d96 Parents: b7e296d Author: BroganD1993 <darrenbro...@hotmail.com> Authored: Tue Jun 17 22:48:18 2014 +0100 Committer: BroganD1993 <darrenbro...@hotmail.com> Committed: Tue Jun 17 22:48:18 2014 +0100 ---------------------------------------------------------------------- gstack/__init__.py | 6 +- gstack/controllers/disks.py | 34 ----------- gstack/controllers/firewalls.py | 22 +++---- gstack/controllers/images.py | 53 ++-------------- gstack/controllers/instances.py | 33 ---------- gstack/controllers/machine_type.py | 104 ++++---------------------------- gstack/controllers/networks.py | 32 ---------- gstack/controllers/project.py | 33 ---------- gstack/controllers/regions.py | 15 ----- gstack/controllers/zones.py | 32 ---------- 10 files changed, 31 insertions(+), 333 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/787b7208/gstack/__init__.py ---------------------------------------------------------------------- diff --git a/gstack/__init__.py b/gstack/__init__.py index 0fae091..c96f7b1 100644 --- a/gstack/__init__.py +++ b/gstack/__init__.py @@ -22,7 +22,6 @@ import sys 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__) http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/787b7208/gstack/controllers/disks.py ---------------------------------------------------------------------- diff --git a/gstack/controllers/disks.py b/gstack/controllers/disks.py index 20fa073..16a1a0c 100644 --- a/gstack/controllers/disks.py +++ b/gstack/controllers/disks.py @@ -26,40 +26,6 @@ from gstack import controllers 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' http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/787b7208/gstack/controllers/firewalls.py ---------------------------------------------------------------------- diff --git a/gstack/controllers/firewalls.py b/gstack/controllers/firewalls.py index 3286390..d3810a6 100755 --- a/gstack/controllers/firewalls.py +++ b/gstack/controllers/firewalls.py @@ -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']) http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/787b7208/gstack/controllers/images.py ---------------------------------------------------------------------- diff --git a/gstack/controllers/images.py b/gstack/controllers/images.py index 695affd..be550a2 100755 --- a/gstack/controllers/images.py +++ b/gstack/controllers/images.py @@ -26,41 +26,6 @@ from gstack.controllers import errors 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) http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/787b7208/gstack/controllers/instances.py ---------------------------------------------------------------------- diff --git a/gstack/controllers/instances.py b/gstack/controllers/instances.py index 175bfe9..fc1ce8e 100755 --- a/gstack/controllers/instances.py +++ b/gstack/controllers/instances.py @@ -27,21 +27,6 @@ from gstack.services import requester 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): http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/787b7208/gstack/controllers/machine_type.py ---------------------------------------------------------------------- diff --git a/gstack/controllers/machine_type.py b/gstack/controllers/machine_type.py index 9dfd71b..5b2c4ed 100755 --- a/gstack/controllers/machine_type.py +++ b/gstack/controllers/machine_type.py @@ -22,42 +22,11 @@ from gstack import app 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 http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/787b7208/gstack/controllers/networks.py ---------------------------------------------------------------------- diff --git a/gstack/controllers/networks.py b/gstack/controllers/networks.py index ae2aef5..37ee672 100644 --- a/gstack/controllers/networks.py +++ b/gstack/controllers/networks.py @@ -27,38 +27,6 @@ from gstack.services import requester from gstack.controllers import errors -def _get_networks(authorization, args=None): - command = 'listSecurityGroups' - if not args: - args = {} - cloudstack_response = requester.make_request( - command, - args, - authorization.client_id, - authorization.client_secret - ) - - return cloudstack_response - - -def get_network_by_name(authorization, securitygroup): - securitygroup_list = _get_networks( - authorization=authorization, - args={ - 'keyword': securitygroup - } - ) - - if securitygroup_list['listsecuritygroupsresponse']: - response = controllers.filter_by_name( - data=securitygroup_list['listsecuritygroupsresponse']['securitygroup'], - name=securitygroup - ) - return response - else: - return None - - def _add_network(authorization, args=None): command = 'createSecurityGroup' if not args: http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/787b7208/gstack/controllers/project.py ---------------------------------------------------------------------- diff --git a/gstack/controllers/project.py b/gstack/controllers/project.py index 066724c..96e2eef 100755 --- a/gstack/controllers/project.py +++ b/gstack/controllers/project.py @@ -65,39 +65,6 @@ def _list_ssh_keys(authorization): return sshkeys -def _get_accounts(authorization, args=None): - command = 'listAccounts' - if not args: - args = {} - - cloudstack_response = requester.make_request( - command, - args, - authorization.client_id, - authorization.client_secret - ) - - return cloudstack_response - - -def _get_account_by_name(authorization, projectid): - account_list = _get_accounts( - authorization=authorization, - args={ - 'keyword': projectid - } - ) - - if account_list['listaccountsresponse']: - response = controllers.filter_by_name( - data=account_list['listaccountsresponse']['account'], - name=projectid - ) - return response - else: - return None - - def _format_quota(metric, limit, usage): quota = {} quota['metric'] = metric http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/787b7208/gstack/controllers/regions.py ---------------------------------------------------------------------- diff --git a/gstack/controllers/regions.py b/gstack/controllers/regions.py index dc7d071..642e55c 100755 --- a/gstack/controllers/regions.py +++ b/gstack/controllers/regions.py @@ -21,25 +21,10 @@ from gstack import app from gstack import helpers from gstack import authentication -from gstack.services import requester from gstack.controllers import errors from flask import request, url_for -def _get_regions(authorization, args=None): - command = 'listRegions' - if not args: - args = {} - - cloudstack_response = requester.make_request( - command, - args, - authorization.client_id, - authorization.client_secret - ) - return cloudstack_response - - def _cloudstack_region_to_gce(response_item): response = {} response['kind'] = 'compute#region' http://git-wip-us.apache.org/repos/asf/cloudstack-gcestack/blob/787b7208/gstack/controllers/zones.py ---------------------------------------------------------------------- diff --git a/gstack/controllers/zones.py b/gstack/controllers/zones.py index 7738333..fa72cdb 100755 --- a/gstack/controllers/zones.py +++ b/gstack/controllers/zones.py @@ -25,38 +25,6 @@ from gstack.services import requester 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_by_name(authorization, zone): - zone_list = _get_zones( - authorization=authorization, - args={ - 'keyword': zone - } - ) - - if zone_list['listzonesresponse']: - response = controllers.filter_by_name( - data=zone_list['listzonesresponse']['zone'], - name=zone - ) - return response - else: - return None - - def get_zone_names(authorization): zone_list = _get_zones(authorization)