def hostname(name): valid, available = check_hostname(starrs, name) if not valid: return 'invalid' if not available: return 'taken' else: return 'ok'
def hostname(name): valid, available = check_hostname(starrs, name) if app.config['USE_STARRS'] else (True, True) if not valid: return 'invalid' if not available: return 'taken' else: return 'ok'
def create(): user = User(session['userinfo']['preferred_username']) proxmox = connect_proxmox() if user.active or user.rtp: if request.method == 'GET': stored_isos = get_isos(proxmox, app.config['PROXMOX_ISO_STORAGE']) pools = get_pools(proxmox, db) templates = get_templates(db) return render_template( 'create.html', user=user, usage=user.usage, limits=user.limits, percents=user.usage_percent, isos=stored_isos, pools=pools, templates=templates, ) elif request.method == 'POST': name = request.form['name'].lower() cores = request.form['cores'] memory = request.form['mem'] template = request.form['template'] disk = request.form['disk'] iso = request.form['iso'] ssh_key = request.form['ssh_key'] if iso != 'none': iso = '{}:iso/{}'.format(app.config['PROXMOX_ISO_STORAGE'], iso) if not user.rtp: if template == 'none': usage_check = user.check_usage(0, 0, disk) else: usage_check = user.check_usage(cores, memory, disk) username = user.name else: usage_check = None username = request.form['user'] if usage_check: return usage_check else: valid, available = check_hostname(starrs, name) if valid and available: if template == 'none': q.enqueue( create_vm_task, username, name, cores, memory, disk, iso, job_timeout=300, ) else: q.enqueue( setup_template_task, template, name, username, ssh_key, cores, memory, job_timeout=600, ) return '', 200 return '', 200 return None else: return '', 403