Skip to content
Permalink
Browse files
shh travis, it'll all be over soon
  • Loading branch information
brogand93 committed Jun 19, 2014
1 parent 710d7a0 commit f6f5e4ee1961219336c822bede996df94d1a57cd
Showing 18 changed files with 64 additions and 110 deletions.
@@ -29,12 +29,12 @@ def _load_config_file():
os.path.expanduser('~'),
'.gstack/gstack.conf'
)

if not os.path.exists(config_file):
sys.exit('No configuration found, please run gstack-configure')

return config_file


def _load_database():
database_file = os.path.join(
os.path.expanduser('~'),
@@ -74,6 +74,7 @@ def _create_config_file(config_folder):

config_file.close()


def _create_database():
directory = os.path.join(os.path.dirname(__file__), '../migrations')
config = AlembicConfig(os.path.join(
@@ -78,6 +78,7 @@ def get_item_with_name_or_error(authorization, name, args, type, func_route, to_
else:
return errors.resource_not_found(func_route)


def _get_requested_items(authorization, args, type, to_cloudstack, **kwargs):
name = None
filter = helpers.get_filter(request.args)
@@ -131,4 +132,4 @@ def describe_items_aggregated(authorization, args, type, gce_type, to_cloudstack
def describe_items(authorization, args, type, to_cloudstack, **kwargs):
items = _get_requested_items(authorization, args, type, to_cloudstack, **kwargs)

return items
return items
@@ -20,10 +20,8 @@
import urllib
from flask import request, url_for
from gstack import app, authentication
from gstack.services import requester
from gstack import helpers
from gstack import controllers
from gstack.controllers import zones, errors


def _cloudstack_volume_to_gce(cloudstack_response, projectid, zone):
@@ -50,8 +48,8 @@ def _cloudstack_volume_to_gce(cloudstack_response, projectid, zone):
@app.route('/compute/v1/projects/<projectid>/aggregated/disks', methods=['GET'])
@authentication.required
def aggregatedlistdisks(projectid, authorization):
args = {'command':'listVolumes'}
kwargs = {'projectid':projectid}
args = {'command': 'listVolumes'}
kwargs = {'projectid': projectid}
items = controllers.describe_items_aggregated(
authorization, args, 'volume', 'disk',
_cloudstack_volume_to_gce, **kwargs)
@@ -69,8 +67,8 @@ def aggregatedlistdisks(projectid, authorization):
@app.route('/compute/v1/projects/<projectid>/zones/<zone>/disks', methods=['GET'])
@authentication.required
def listdisks(projectid, authorization, zone):
args = {'command':'listVolumes'}
kwargs = {'projectid':projectid, 'zone':zone}
args = {'command': 'listVolumes'}
kwargs = {'projectid': projectid, 'zone': zone}
items = controllers.describe_items(
authorization, args, 'volume',
_cloudstack_volume_to_gce, **kwargs)
@@ -89,8 +87,8 @@ def listdisks(projectid, authorization, zone):
@authentication.required
def getdisk(projectid, authorization, zone, disk):
func_route = url_for('getdisk', projectid=projectid, zone=zone, disk=disk)
args = {'command':'listVolumes'}
kwargs = {'projectid':projectid, 'zone':zone}
args = {'command': 'listVolumes'}
kwargs = {'projectid': projectid, 'zone': zone}
return controllers.get_item_with_name_or_error(
authorization, disk, args, 'volume', func_route,
_cloudstack_volume_to_gce, **kwargs)
@@ -20,7 +20,7 @@
import urllib
from gstack import app
from gstack import helpers
from flask import jsonify, Response
from flask import Response


@app.errorhandler(404)
@@ -63,7 +63,7 @@ def _cloudstack_securitygroup_to_gce(cloudstack_response):
@app.route('/compute/v1/projects/<projectid>/global/firewalls', methods=['GET'])
@authentication.required
def listsecuritygroups(projectid, authorization):
args = {'command':'listSecurityGroups'}
args = {'command': 'listSecurityGroups'}
items = controllers.describe_items(
authorization, args, 'securitygroup',
_cloudstack_securitygroup_to_gce, **{})
@@ -136,7 +136,6 @@ def deletesecuritygroup(projectid, authorization, firewall):
json.dumps(cloudstack_response, indent=4, separators=(',', ': '))
)

# return Global Operations
populated_response = {}

res = jsonify(populated_response)
@@ -19,14 +19,13 @@

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


def get_template_by_name(authorization, image):
args = {'templatefilter': 'executable', 'command':'listTemplates'}
args = {'templatefilter': 'executable', 'command': 'listTemplates'}
return controllers.get_item_with_name(authorization, image, args, 'template')


@@ -44,17 +43,13 @@ def _create_populated_image_response(projectid, images=None):


def _cloudstack_template_to_gce(cloudstack_response):
translate_image_status = {
'True': 'Ready',
'False': 'Failed'}

response = {}
response['kind'] = 'compute#image'
response['id'] = cloudstack_response['id']
response['creationTimestamp'] = cloudstack_response['created']
response['name'] = cloudstack_response['name']
response['description'] = cloudstack_response['displaytext']
response['status'] = translate_image_status[str(cloudstack_response['isready'])]
response['status'] = cloudstack_response['isready']
response['selfLink'] = urllib.unquote_plus(request.base_url) + '/' + response['name']

return response
@@ -77,7 +72,7 @@ def listnodebiancloudimages(authorization):
@app.route('/compute/v1/projects/<projectid>/global/images', methods=['GET'])
@authentication.required
def listimages(projectid, authorization):
args = {'templatefilter': 'executable', 'command':'listTemplates'}
args = {'templatefilter': 'executable', 'command': 'listTemplates'}
items = controllers.describe_items(
authorization, args, 'template',
_cloudstack_template_to_gce, **{})
@@ -90,7 +85,7 @@ def listimages(projectid, authorization):
@authentication.required
def getimage(projectid, authorization, image):
func_route = url_for('getimage', projectid=projectid, image=image)
args = {'templatefilter': 'executable', 'command':'listTemplates'}
args = {'templatefilter': 'executable', 'command': 'listTemplates'}
return controllers.get_item_with_name_or_error(
authorization, image, args, 'template', func_route,
_cloudstack_template_to_gce, **{})
_cloudstack_template_to_gce, **{})
@@ -52,7 +52,7 @@ def _deploy_virtual_machine(authorization, args, projectid):
if 'network' in args:
network = networks.get_network_by_name(
authorization=authorization,
securitygroup=args['network']
network=args['network']
)
converted_args['securitygroupids'] = network['id']

@@ -116,8 +116,8 @@ def _cloudstack_virtual_machine_to_gce(cloudstack_response, projectid, zone, **k
@app.route('/compute/v1/projects/<projectid>/aggregated/instances', methods=['GET'])
@authentication.required
def aggregatedlistinstances(authorization, projectid):
args = {'command':'listVirtualMachines'}
kwargs = {'projectid':projectid}
args = {'command': 'listVirtualMachines'}
kwargs = {'projectid': projectid}
items = controllers.describe_items_aggregated(
authorization, args, 'virtualmachine', 'instances',
_cloudstack_virtual_machine_to_gce, **kwargs)
@@ -134,8 +134,8 @@ def aggregatedlistinstances(authorization, projectid):
@app.route('/compute/v1/projects/<projectid>/zones/<zone>/instances', methods=['GET'])
@authentication.required
def listinstances(authorization, projectid, zone):
args = {'command':'listVirtualMachines'}
kwargs = {'projectid':projectid, 'zone':zone}
args = {'command': 'listVirtualMachines'}
kwargs = {'projectid': projectid, 'zone': zone}
items = controllers.describe_items(
authorization, args, 'virtualmachine',
_cloudstack_virtual_machine_to_gce, **kwargs)
@@ -194,7 +194,7 @@ def addinstance(authorization, projectid, zone):
@app.route('/compute/v1/projects/<projectid>/zones/<zone>/instances/<instance>', methods=['DELETE'])
@authentication.required
def deleteinstance(projectid, authorization, zone, instance):
args = {'command':'listVirtualMachines'}
args = {'command': 'listVirtualMachines'}
virtual_machine = controllers.get_item_with_name(authorization, instance, args, 'virtualmachine')
if virtual_machine is None:
func_route = url_for('deleteinstance', projectid=projectid, zone=zone, instance=instance)
@@ -218,12 +218,13 @@ def deleteinstance(projectid, authorization, zone, instance):

return helpers.create_response(data=populated_response)


@app.route('/compute/v1/projects/<projectid>/zones/<zone>/instances/<instance>', methods=['GET'])
@authentication.required
def getinstance(projectid, authorization, zone, instance):
func_route = url_for('getinstance', projectid=projectid, zone=zone, instance=instance)
args = {'command':'listVirtualMachines'}
kwargs = {'projectid':projectid, 'zone':zone}
args = {'command': 'listVirtualMachines'}
kwargs = {'projectid': projectid, 'zone': zone}
return controllers.get_item_with_name_or_error(
authorization, instance, args, 'virtualmachine', func_route,
_cloudstack_virtual_machine_to_gce, **kwargs)
_cloudstack_virtual_machine_to_gce, **kwargs)
@@ -22,11 +22,11 @@
from gstack import authentication
from gstack import helpers
from gstack import controllers
from gstack.controllers import errors, zones
from flask import request, url_for


def get_machinetype_by_name(authorization, machinetype):
args = {'command':'listServiceOfferings'}
args = {'command': 'listServiceOfferings'}
return controllers.get_item_with_name(authorization, machinetype, args, 'serviceoffering')


@@ -54,8 +54,8 @@ def _cloudstack_service_offering_to_gce(cloudstack_response, projectid, zone):
@app.route('/compute/v1/projects/<projectid>/aggregated/machineTypes', methods=['GET'])
@authentication.required
def aggregatedlistmachinetypes(projectid, authorization):
args = {'command':'listServiceOfferings'}
kwargs = {'projectid':projectid}
args = {'command': 'listServiceOfferings'}
kwargs = {'projectid': projectid}
items = controllers.describe_items_aggregated(
authorization, args, 'serviceoffering', 'machineTypes',
_cloudstack_service_offering_to_gce, **kwargs)
@@ -72,8 +72,8 @@ def aggregatedlistmachinetypes(projectid, authorization):
@app.route('/compute/v1/projects/<projectid>/zones/<zone>/machineTypes', methods=['GET'])
@authentication.required
def listmachinetype(projectid, authorization, zone):
args = {'command':'listServiceOfferings'}
kwargs = {'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)
@@ -92,8 +92,8 @@ def listmachinetype(projectid, authorization, zone):
@authentication.required
def getmachinetype(projectid, authorization, zone, machinetype):
func_route = url_for('getmachinetype', projectid=projectid, zone=zone, machinetype=machinetype)
args = {'command':'listServiceOfferings'}
kwargs = {'projectid':projectid, 'zone':zone}
args = {'command': 'listServiceOfferings'}
kwargs = {'projectid': projectid, 'zone': zone}
return controllers.get_item_with_name_or_error(
authorization, machinetype, args, 'serviceoffering', func_route,
_cloudstack_service_offering_to_gce, **kwargs)
@@ -26,10 +26,12 @@
from gstack.services import requester
from gstack.controllers import errors


def get_network_by_name(authorization, network):
args = {'command':'SecurityGroups'}
args = {'command': 'SecurityGroups'}
return controllers.get_item_with_name(authorization, network, args, 'securitygroup')


def _add_network(authorization, args=None):
command = 'createSecurityGroup'
if not args:
@@ -46,7 +48,7 @@ def _add_network(authorization, args=None):


def _delete_network(authorization, projectid, network):
args = {'command':'SecurityGroups'}
args = {'command': 'SecurityGroups'}
network_response = controllers.get_item_with_name(authorization, network, args, 'securitygroup')
if not network_response:
return None
@@ -92,7 +94,7 @@ def _create_populated_network_response(projectid, networks=None):
@app.route('/compute/v1/projects/<projectid>/global/networks', methods=['GET'])
@authentication.required
def listnetworks(projectid, authorization):
args = {'command':'listSecurityGroups'}
args = {'command': 'listSecurityGroups'}
kwargs = {}
items = controllers.describe_items(
authorization, args, 'securitygroup',
@@ -109,7 +111,7 @@ def listnetworks(projectid, authorization):
@authentication.required
def getnetwork(projectid, authorization, network):
func_route = url_for('getnetwork', projectid=projectid, network=network)
args = {'command':'listSecurityGroups'}
args = {'command': 'listSecurityGroups'}
kwargs = {}
return controllers.get_item_with_name_or_error(
authorization, network, args, 'securitygroup', func_route,
@@ -28,8 +28,9 @@
import urllib
import collections


def _get_account_by_name(authorization, projectid):
args = {'command':'listAccounts'}
args = {'command': 'listAccounts'}
return controllers.get_item_with_name(authorization, projectid, args, 'account')


@@ -133,7 +134,6 @@ def _cloudstack_project_to_gce(cloudstack_response, metadata=None):
@authentication.required
def getproject(authorization, projectid):
project = _get_account_by_name(authorization, projectid)
print project

if project:
metadata = {}
@@ -22,7 +22,6 @@
from gstack import helpers
from gstack import controllers
from gstack import authentication
from gstack.controllers import errors
from flask import request, url_for


@@ -39,7 +38,7 @@ def _cloudstack_account_to_gce(cloudstack_response):
@app.route('/compute/v1/projects/<projectid>/regions', methods=['GET'])
@authentication.required
def listregions(projectid, authorization):
args = {'command':'listAccounts'}
args = {'command': 'listAccounts'}
kwargs = {}
items = controllers.describe_items(
authorization, args, 'region',
@@ -58,7 +57,7 @@ def listregions(projectid, authorization):
@authentication.required
def getregion(projectid, authorization, region):
func_route = url_for('getregion', projectid=projectid, region=region)
args = {'command':'listAccounts'}
args = {'command': 'listAccounts'}
return controllers.get_item_with_name_or_error(
authorization, region, args, 'region', func_route,
_cloudstack_account_to_gce, **{})

0 comments on commit f6f5e4e

Please sign in to comment.