Skip to content

Instantly share code, notes, and snippets.

@sebgoa
Created April 15, 2013 14:37
Show Gist options
  • Save sebgoa/5388565 to your computer and use it in GitHub Desktop.
Save sebgoa/5388565 to your computer and use it in GitHub Desktop.
A flask application that creates a wrapper on CloudStack API. Illustrates the GET calls and query parameters. Dependent on requester.py from https://git-wip-us.apache.org/repos/asf?p=cloudstack.git;a=blob;f=tools/cli/cloudmonkey/requester.py
#!/usr/bin/env python
# encoding: utf-8
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import sys
import os
import json
import requester
from flask import Flask, url_for, render_template, request
app = Flask(__name__)
apikey='plgWJfZK4gyS3mOMTVmjUVg-X-jlWlnfaUJ9GAbBbf9EdM-kAYMmAiLqzzq1ElZLYq_u38zCm0bewzGUdP66mg'
secretkey='VDaACYb0LV9eNjTetIOElcVQkvJck_J_QljX_FcHRj87ZKiy0z0ty0ZsYBkoXkY9b7eq1EhwJaw7FF3akA3KBQ'
path='/client/api'
host='localhost'
port='8080'
protocol='http'
@app.route('/hello')
def helloworld():
return 'hello \n'
@app.route('/list')
def list():
print request.query_string
res={}
for key in request.args.iterkeys():
res[key]=request.args.get(key)
print res
response, error = requester.make_request('listUsers',res,None,host,port,apikey,secretkey,protocol,path)
return response
@app.route('/delete')
def delete():
print request.query_string
res={}
for key in request.args.iterkeys():
res[key]=request.args.get(key)
print res
response, error = requester.make_request('deleteUser',res,None,host,port,apikey,secretkey,protocol,path)
return response
@app.route('/create')
def create():
print request.query_string
res={}
for key in request.args.iterkeys():
res[key]=request.args.get(key)
print res
response, error = requester.make_request('createUser',res,None,host,port,apikey,secretkey,protocol,path)
return response
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment