flask-python-helm/main.py
2020-09-11 23:04:48 +08:00

43 lines
1.3 KiB
Python

# encoding=utf-8
import os
import json
from app import app
from flask import Flask, flash, render_template, request, redirect, url_for
from flask_wtf import FlaskForm
from flask_bootstrap import Bootstrap
from wtforms import StringField, PasswordField, BooleanField
from wtforms.fields.html5 import DateField
from wtforms.validators import InputRequired, Email, Length
from routes import *
from logging import error, info
from subprocess import STDOUT, CalledProcessError, check_output
from itertools import islice
import json
def get_namespaces():
command = "/usr/local/bin/kubectl get ns -ojson"
info(f"Running command: {command}")
try:
output = check_output(command.split(" "), stderr=STDOUT).decode("utf-8")
except CalledProcessError as err:
error(err.output.decode("utf-8"))
raise err
info(f"Output from command:\n{output}")
data = json.loads(output)
return data
@app.route('/', methods=['GET', 'POST'])
def namespacesForm():
form = deploySelectForm()
namespaces = get_namespaces()
print('Here we are')
if form.validate_on_submit():
return redirect(url_for('/'))
# return '<h1>Something went wrong there</h1>'
return render_template('index.html', namespaces=namespaces, form=form)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=3000, debug=True)