from django.http import HttpResponse
from django.shortcuts import render
# IMPORT AT THE TOP HERE: This is completely safe!
from .models import Deployment_Data,Schedule_Week_Data
from .db_interaction import DB_generation,Check_server_supposed_XXX,Give_current_weekday,Give_current_hour
from .utils import import_namespace,retrieve_and_apply
def coucou(request):
# 1. Prepare the data inside the function
data = CmmData(
name="test",
namespace="testspace",
schedule_hour="1",
schedule_day="deux",
replicas=3
)
# 2. This line actually pushes the data into your cloudmanager_db!
data.save()
return HttpResponse('
Hello cmm! Data saved successfully!
')
def display(request):
data = CmmData.objects.all()
print(data[0].namespace)
return HttpResponse(data)
def hello(request):
list_schedule = ['schedule1','schedule2']
list_servers_up = [['wiki', 'wikijs', 2], ['book', 'bookstack-db', 1]]
return render(request, 'cloudmanager/index.html', {'list_schedule':list_schedule,'list_servers_up':list_servers_up})
def import_namespace_view(request):
import_namespace()
return HttpResponse('Namespace imported!
')
def retrieve_and_apply_view(request):
output = retrieve_and_apply()
return HttpResponse(''+output+'
')
def redirect(request):
db_host = os.environ.get('DB_HOST')
db_port = os.environ.get('DB_PORT')
db_user = os.environ.get('DB_USERNAME')
db_password = os.environ.get('DB_PASSWORD')
db_name = os.environ.get('CUSTOM_DB_DATABASE',os.environ.get('DB_DATABASE'))
generated_db = DB_generation(db_host, db_port, db_user, db_password,db_name)
##operation:
## Server(s) supposed to be UP
list_servers_up = Check_server_supposed_XXX(generated_db, "up", Give_current_hour(),Give_current_weekday())
print(list_servers_up)
return render(request, 'cloudmanager/cmm_blank_page.html', {'list_servers_up':list_servers_up})