98 lines
3.5 KiB
Python
98 lines
3.5 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
|
|
|
|
app.register_blueprint(routes)
|
|
|
|
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
|
|
|
|
def get_tiller_namespaces():
|
|
command = "/usr/local/bin/kubectl get deploy --all-namespaces -l name=tiller -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
|
|
|
|
def get_deployments(namespace):
|
|
command = "/usr/local/bin/kubectl -n " + namespace + " get deploy -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
|
|
|
|
def get_charts(tiller_ns, namespace):
|
|
command = "/usr/local/bin/helm --tiller-namespace " + tiller_ns + " list --output json" #helm2
|
|
#command = "/usr/local/bin/helm -n " + namespace + " list -ojson" #helm3
|
|
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
|
|
|
|
def get_chartdata(tiller_ns, namespace, chart):
|
|
command = "/usr/local/bin/helm --tiller-namespace " + tiller_ns + " history " + chart + " --output json" #helm2
|
|
#command = "/usr/local/bin/helm -n " + namespace + " history " + chart + " -ojson" #helm3
|
|
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)
|
|
for revision in data:
|
|
revision['chartName'] = chart
|
|
revision["namespace"] = namespace
|
|
revision["tiller_ns"] = tiller_ns
|
|
return data
|
|
|
|
def chartRollback(revision, chart, tiller_ns):
|
|
command = "/usr/local/bin/helm --tiller-namespace " + tiller_ns + " rollback " + chart + " " + revision # helm2
|
|
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}")
|
|
return output
|
|
|
|
if __name__ == "__main__":
|
|
app.run(host='0.0.0.0', port=3000, debug=True)
|