def openstack_check(): # check openstack is setup response = OpenStack().check() return jsonify(response)
def configure_openstack(): # quote strip def dequote(string): if string.startswith('"') and string.endswith('"'): string = string[1:-1] return string # check configuration settings = Status().check_settings() # get the form form = OpenStackForm(request.form) # try to select one and only record openstack = db.session.query(OpenStack).first() # create new entry if configuration doesn't exist if not openstack: openstack = OpenStack() if request.method == 'POST': # clear settings cache Status().flush() # handle a file upload try: file = request.files['file'] except: file = False if file and allowed_file(file.filename): keyvals = {} for line in file: keyval = dict(re.findall(r'(\S+)=(".*?"|\S+)', line)) if len(keyval) > 0: keyvals.update(keyval) # set values from extracted lines above - needs SQL injection protection? openstack.authurl = "%s" % dequote(keyvals['OS_AUTH_URL']) openstack.tenantname = "%s" % dequote(keyvals['OS_TENANT_NAME']) openstack.tenantid = "%s" % dequote(keyvals['OS_TENANT_ID']) openstack.osusername = "******" % dequote(keyvals['OS_USERNAME']) openstack.ospassword = "******" # update entry openstack.update(openstack) elif file: # file type not allowed flash("File type not allowed or empty. Try again.", "file-error") else: # user is manually updating form if form.validate_on_submit(): # populate with form and update form.populate_obj(openstack) openstack.update(openstack) flash("OpenStack settings updated!", "success") return redirect(url_for(".configure_openstack")) else: flash( "There were form errors. Please check your entries and try again.", "error") # get existing form data openstack = db.session.query(OpenStack).first() # if notice, show message return render_template('configure/openstack.html', settings=settings, form=form, openstack=openstack)