Skip to content
Permalink
Browse files
Allow for dynamic config file creation
  • Loading branch information
brogand93 committed May 29, 2014
1 parent 433cab4 commit fd7ab61c5f44c2c8bd3e56a79896681be7120610
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 77 deletions.
@@ -35,21 +35,23 @@ def _load_config_file():

return config_file

app = Flask(__name__)
db = SQLAlchemy(app)
publickey_storage = {}

def configure_app():
config_file = _load_config_file()
app.config.from_pyfile(config_file)
app.config['DATA'] = os.path.abspath(os.path.dirname(__file__)) + '/data'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
os.path.join(app.config['DATA'], 'app.db')

basedir = os.path.abspath(os.path.dirname(__file__))

config_file = _load_config_file()
app.config.from_pyfile(config_file)

app.config['DATA'] = os.path.abspath(os.path.dirname(__file__)) + '/data'
app = Flask(__name__)

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
os.path.join(app.config['DATA'], 'app.db')
db = SQLAlchemy(app)
publickey_storage = {}

from gstack.controllers import *


basedir = os.path.abspath(os.path.dirname(__file__))

db.create_all()
@@ -17,12 +17,13 @@
# specific language governing permissions and limitations
# under the License.

from gstack import app
from gstack import app, configure_app

from OpenSSL import SSL


def main():
configure_app()
context = SSL.Context(SSL.SSLv23_METHOD)
context.use_privatekey_file(app.config['DATA'] + '/server.key')
context.use_certificate_file(app.config['DATA'] + '/server.crt')
@@ -81,7 +81,7 @@ def _cloudstack_volume_to_gce(cloudstack_response, projectid, zone):
return response


@app.route('/' + app.config['PATH'] + '<projectid>/aggregated/disks', methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/aggregated/disks', methods=['GET'])
@authentication.required
def aggregatedlistdisks(projectid, authorization):
disk_list = _get_disks(authorization=authorization)
@@ -133,7 +133,7 @@ def aggregatedlistdisks(projectid, authorization):
return helper.create_response(data=populated_response)


@app.route('/' + app.config['PATH'] + '<projectid>/zones/<zone>/disks', methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/zones/<zone>/disks', methods=['GET'])
@authentication.required
def listdisks(projectid, authorization, zone):
disk = None
@@ -184,7 +184,7 @@ def listdisks(projectid, authorization, zone):
return helper.create_response(data=populated_response)


@app.route('/' + app.config['PATH'] + '<projectid>/zones/<zone>/disks/<disk>', methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/zones/<zone>/disks/<disk>', methods=['GET'])
@authentication.required
def getdisk(projectid, authorization, zone, disk):
response = get_disk_by_name(
@@ -56,7 +56,7 @@ def _cloudstack_securitygroup_to_gce(response_item):
})


@app.route('/' + app.config['PATH'] + '<projectid>/global/firewalls',
@app.route('/compute/v1/projects/<projectid>/global/firewalls',
methods=['GET'])
@authentication.required
def listsecuritygroups(projectid, authorization):
@@ -99,9 +99,7 @@ def listsecuritygroups(projectid, authorization):
return res


@app.route('/' + app.config['PATH'] +
'<projectid>/global/firewalls/<firewall>',
methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/global/firewalls/<firewall>', methods=['GET'])
@authentication.required
def getsecuritygroup(projectid, authorization, firewall):
command = 'listSecurityGroups'
@@ -138,9 +136,7 @@ def getsecuritygroup(projectid, authorization, firewall):
return res


@app.route(
'/' + app.config['PATH'] + '<projectid>/global/firewalls/<firewall>',
methods=['DELETE'])
@app.route('/compute/v1/projects/<projectid>/global/firewalls/<firewall>', methods=['DELETE'])
@authentication.required
def deletesecuritygroup(projectid, authorization, firewall):
command = 'deleteSecurityGroup'
@@ -169,9 +165,7 @@ def deletesecuritygroup(projectid, authorization, firewall):
return res


@app.route(
'/' + app.config['PATH'] + '<projectid>/global/firewalls',
methods=['POST'])
@app.route('/compute/v1/projects/<projectid>/global/firewalls', methods=['POST'])
@authentication.required
def createsecuritygroup(projectid, authorization):
command = 'createSecurityGroup'
@@ -94,24 +94,21 @@ def _cloudstack_template_to_gce(cloudstack_response, selfLink=None):
return response


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


@app.route(
'/' + app.config['PATH'] + 'debian-cloud/global/images', methods=['GET'])
@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)


@app.route(
'/' + app.config['PATH'] + '<projectid>/global/images', methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/global/images', methods=['GET'])
@authentication.required
def listimages(projectid, authorization):
image_list = _get_templates(
@@ -129,11 +126,7 @@ def listimages(projectid, authorization):
return helper.create_response(data=populated_response)


@app.route(
'/' +
app.config['PATH'] +
'<projectid>/global/images/<image>',
methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/global/images/<image>', methods=['GET'])
@authentication.required
def getimage(projectid, authorization, image):
response = get_template_by_name(
@@ -164,7 +164,7 @@ def _get_virtual_machine_by_name(authorization, instance):
return None


@app.route('/' + app.config['PATH'] + '<projectid>/aggregated/instances', methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/aggregated/instances', methods=['GET'])
@authentication.required
def aggregatedlistinstances(authorization, projectid):
zone_list = zones.get_zone_names(authorization=authorization)
@@ -215,7 +215,7 @@ def aggregatedlistinstances(authorization, projectid):
return helper.create_response(data=populated_response)


@app.route('/' + app.config['PATH'] + '<projectid>/zones/<zone>/instances', methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/zones/<zone>/instances', methods=['GET'])
@authentication.required
def listinstances(authorization, projectid, zone):
instance = None
@@ -262,7 +262,7 @@ def listinstances(authorization, projectid, zone):
return helper.create_response(data=populated_response)


@app.route('/' + app.config['PATH'] + '<projectid>/zones/<zone>/instances/<instance>', methods=['GET'])
@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(
@@ -286,7 +286,7 @@ def getinstance(projectid, authorization, zone, instance):
return errors.resource_not_found(function_route)


@app.route('/' + app.config['PATH'] + '<projectid>/zones/<zone>/instances', methods=['POST'])
@app.route('/compute/v1/projects/<projectid>/zones/<zone>/instances', methods=['POST'])
@authentication.required
def addinstance(authorization, projectid, zone):
data = json.loads(request.data)
@@ -329,7 +329,7 @@ def addinstance(authorization, projectid, zone):
return helper.create_response(data=populated_response)


@app.route('/' + app.config['PATH'] + '<projectid>/zones/<zone>/instances/<instance>', methods=['DELETE'])
@app.route('/compute/v1/projects/<projectid>/zones/<zone>/instances/<instance>', methods=['DELETE'])
@authentication.required
def deleteinstance(projectid, authorization, zone, instance):
deletion_result = _destroy_virtual_machine(authorization, instance)
@@ -76,11 +76,7 @@ def _cloudstack_machinetype_to_gce(cloudstack_response, projectid, zone):
return response


@app.route(
'/' +
app.config['PATH'] +
'<projectid>/aggregated/machineTypes',
methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/aggregated/machineTypes', methods=['GET'])
@authentication.required
def aggregatedlistmachinetypes(projectid, authorization):
machine_types = _get_machinetypes(authorization)
@@ -114,11 +110,7 @@ def aggregatedlistmachinetypes(projectid, authorization):
return helper.create_response(data=populated_response)


@app.route(
'/' +
app.config['PATH'] +
'<projectid>/zones/<zone>/machineTypes',
methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/zones/<zone>/machineTypes', methods=['GET'])
@authentication.required
def listmachinetype(projectid, authorization, zone):
machinetype = None
@@ -170,11 +162,7 @@ def listmachinetype(projectid, authorization, zone):
return helper.create_response(data=populated_response)


@app.route(
'/' +
app.config['PATH'] +
'<projectid>/zones/<zone>/machineTypes/<machinetype>',
methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/zones/<zone>/machineTypes/<machinetype>', methods=['GET'])
@authentication.required
def getmachinetype(projectid, authorization, zone, machinetype):
response = get_machinetype_by_name(
@@ -124,7 +124,7 @@ def _create_populated_network_response(projectid, networks=None):


@app.route(
'/' + app.config['PATH'] + '<projectid>/global/networks', methods=['GET'])
'/compute/v1/projects/<projectid>/global/networks', methods=['GET'])
@authentication.required
def listnetworks(projectid, authorization):
securitygroup_list = _get_networks(
@@ -145,11 +145,7 @@ def listnetworks(projectid, authorization):
return helper.create_response(data=populated_response)


@app.route(
'/' +
app.config['PATH'] +
'<projectid>/global/networks/<network>',
methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/global/networks/<network>', methods=['GET'])
@authentication.required
def getnetwork(projectid, authorization, network):
response = get_network_by_name(
@@ -169,8 +165,7 @@ def getnetwork(projectid, authorization, network):
return errors.resource_not_found(func_route)


@app.route(
'/' + app.config['PATH'] + '<projectid>/global/networks', methods=['POST'])
@app.route('/compute/v1/projects/<projectid>/global/networks', methods=['POST'])
@authentication.required
def addnetwork(authorization, projectid):
data = json.loads(request.data)
@@ -212,11 +207,7 @@ def addnetwork(authorization, projectid):
return helper.create_response(data=populated_response)


@app.route(
'/' +
app.config['PATH'] +
'<projectid>/global/networks/<network>',
methods=['DELETE'])
@app.route('/compute/v1/projects/<projectid>/global/networks/<network>', methods=['DELETE'])
@authentication.required
def deletenetwork(projectid, authorization, network):
_delete_network(authorization, projectid, network)
@@ -183,7 +183,7 @@ def create_response(authorization, projectid, operationid):
return populated_response


@app.route('/' + app.config['PATH'] + '<projectid>/global/operations/<operationid>', methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/global/operations/<operationid>', methods=['GET'])
@authentication.required
def getoperations(authorization, operationid, projectid):
return helper.create_response(create_response(
@@ -156,7 +156,7 @@ def _cloudstack_project_to_gce(cloudstack_response, metadata=None):
return response


@app.route('/' + app.config['PATH'] + '<projectid>', methods=['GET'])
@app.route('//compute/v1/projects/<projectid>', methods=['GET'])
@authentication.required
def getproject(authorization, projectid):
project = _get_account_by_name(authorization, projectid)
@@ -178,7 +178,7 @@ def getproject(authorization, projectid):
return res


@app.route('/' + app.config['PATH'] + '<projectid>/setCommonInstanceMetadata', methods=['POST'])
@app.route('//compute/v1/projects/<projectid>/setCommonInstanceMetadata', methods=['POST'])
@authentication.required
def setglobalmetadata(projectid, authorization):
data = json.loads(request.data)
@@ -48,7 +48,7 @@ def _cloudstack_region_to_gce(response_item):
return response


@app.route('/' + app.config['PATH'] + '<projectid>/regions', methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/regions', methods=['GET'])
@authentication.required
def listregions(projectid, authorization):
cloudstack_response = _get_regions(authorization)
@@ -68,8 +68,7 @@ def listregions(projectid, authorization):
return helper.create_response(data=populated_response)


@app.route(
'/' + app.config['PATH'] + '<projectid>/regions/<region>', methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/regions/<region>', methods=['GET'])
@authentication.required
def getregion(projectid, authorization, region):
cloudstack_response = _get_regions(
@@ -80,7 +80,7 @@ def _cloudstack_zone_to_gce(response_item):
})


@app.route('/' + app.config['PATH'] + '<projectid>/zones', methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/zones', methods=['GET'])
@authentication.required
def listzones(projectid, authorization):
zone_list = _get_zones(authorization)
@@ -100,7 +100,7 @@ def listzones(projectid, authorization):
return helper.create_response(data=populated_response)


@app.route('/' + app.config['PATH'] + '<projectid>/zones/<zone>', methods=['GET'])
@app.route('/compute/v1/projects/<projectid>/zones/<zone>', methods=['GET'])
@authentication.required
def getzone(projectid, authorization, zone):
response = get_zone_by_name(
@@ -59,7 +59,7 @@ def read(fname):
zip_safe=False,
entry_points="""
[console_scripts]
gstack-configure = gstack.configure:main
gstack = gstack.appserver:main
gstack-configure = gstack.configure:main
""",
)

0 comments on commit fd7ab61

Please sign in to comment.