def test(endpoint, username, password): cfi = CloudFoundryInterface("http://" + endpoint, username, password, True) cfi.login() a = cfi b = cfi.apps #c = cfi.apps() r = cfi._get_or_exception('/v2/stacks/39a6edda-ab09-41dd-8bb5-eb8ca5f7f8d4', True) print(dir(cfi.apps[cfi.apps.keys()[0]]))
def apps(): configstuff = utils.configstuff() logger.info("Got request for apps") cfi = CloudFoundryInterface('https://api.run.pivotal.io', username=configstuff['cf_user'], password=configstuff['cf_pass']) #connect to CF cfi.login() #login app_list = [cf_app.name for cf_app in cfi.apps.itervalues()] #get the list of apps (this technique is called a list comprehension, BTW) applications = {'applications': sorted(app_list)} #sort it to be nice. return jsonify(applications) #send a JSON list of applications.
def scale_app(appname, target): configstuff = utils.configstuff() logger.info("Got request to scale app \'{}\' to {}".format(appname, target)) cfi = CloudFoundryInterface('https://api.run.pivotal.io', username=configstuff['cf_user'], password=configstuff['cf_pass']) #again, connect to CF cfi.login() #and login app_list = [cf_app.name for cf_app in cfi.apps.itervalues()] # make sure the app we got was in the list of apps. if appname not in app_list: return jsonify({'status': 'failure'}) else: cfi.scale_app(cfi.get_app_by_name(appname),target) #and if it is, scale it as requested. return jsonify({"status":"success"})