This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@@ -1,3 +1,4 @@
|
||||
from django.apps import AppConfig
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
@@ -6,6 +7,14 @@ import psycopg2
|
||||
from apps.cloudmanager.db_interaction import DB_generation,Check_server_supposed_XXX,Give_current_weekday,Give_current_hour
|
||||
|
||||
|
||||
class CloudmanagerConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'apps.cloudmanager'
|
||||
label = 'cloudmanager'
|
||||
|
||||
def coucou(request):
|
||||
return HttpResponse('<h1>Hello cmm!</h1>')
|
||||
|
||||
def hello(request):
|
||||
list_schedule = ['schedule1','schedule2']
|
||||
list_servers_up = [['wiki', 'wikijs', 2], ['book', 'bookstack-db', 1]]
|
||||
@@ -17,11 +26,11 @@ def redirect(request):
|
||||
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})
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
# Generated by Django 4.2.29 on 2026-06-11 19:35
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CmmData',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('namespace', models.CharField(max_length=100)),
|
||||
('schedule_day', models.CharField(max_length=100)),
|
||||
('schedule_hour', models.CharField(max_length=100)),
|
||||
('replicas', models.IntegerField()),
|
||||
],
|
||||
options={
|
||||
'db_table': 'cloudmanager',
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,12 @@
|
||||
from django.db import models
|
||||
|
||||
class CmmData(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
namespace = models.CharField(max_length=100)
|
||||
schedule_day = models.CharField(max_length=100)
|
||||
schedule_hour = models.CharField(max_length=100)
|
||||
replicas = models.IntegerField()
|
||||
|
||||
|
||||
class Meta:
|
||||
db_table = 'cloudmanager'
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -1,33 +1,24 @@
|
||||
from django.http import HttpResponse
|
||||
from django.views.decorators.http import require_POST
|
||||
#from django.contrib.auth.decorators import login_required # optional but recommended
|
||||
|
||||
def trigger_my_action(request):
|
||||
# 1. Run your Django module/function
|
||||
result = "1"
|
||||
print('here')
|
||||
# 2. Return ONLY the HTML fragment you want to show on the page
|
||||
# This will replace the content inside the "hx-target" div
|
||||
return HttpResponse("Done!")
|
||||
# IMPORT AT THE TOP HERE: This is completely safe!
|
||||
from apps.cloudmanager.models import CmmData
|
||||
|
||||
def coucou(request):
|
||||
# 1. Prepare the data inside the function
|
||||
data = CmmData(
|
||||
name="test",
|
||||
namespace="testspace",
|
||||
schedule_hour="1",
|
||||
schedule_day="deux",
|
||||
replicas=3
|
||||
)
|
||||
|
||||
#@login_required
|
||||
@require_POST
|
||||
def change_schedule(request):
|
||||
# HTMX sends these via standard POST data
|
||||
schedule_id = request.POST.get('schedule_id')
|
||||
server_name = request.POST.get('server_name')
|
||||
# 2. This line actually pushes the data into your cloudmanager_db!
|
||||
data.save()
|
||||
|
||||
if not schedule_id or not server_name:
|
||||
return HttpResponse("<span style='color: red;'>Missing parameters.</span>", status=400)
|
||||
return HttpResponse('<h1>Hello cmm! Data saved successfully!</h1>')
|
||||
|
||||
try:
|
||||
# --- Your Core Logic Here ---
|
||||
# e.g., Server.objects.filter(name=server_name).update(schedule_id=schedule_id)
|
||||
print(f"Updating {server_name} to schedule profile {schedule_id}")
|
||||
|
||||
# Return a success message that will instantly inject into the server's status div
|
||||
return HttpResponse("<span style='color: green;'>✓ Updated successfully!</span>")
|
||||
|
||||
except Exception as e:
|
||||
return HttpResponse(f"<span style='color: red;'>Error: {str(e)}</span>", status=500)
|
||||
def display(request):
|
||||
data = CmmData.objects.all()
|
||||
print(data[0].namespace)
|
||||
return HttpResponse(data)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
import os
|
||||
import psycopg2
|
||||
from apps.cloudmanager.db_interaction import DB_generation,Check_server_supposed_XXX,Give_current_weekday,Give_current_hour
|
||||
|
||||
|
||||
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 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})
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
from django.http import HttpResponse
|
||||
from django.views.decorators.http import require_POST
|
||||
#from django.contrib.auth.decorators import login_required # optional but recommended
|
||||
|
||||
def trigger_my_action(request):
|
||||
# 1. Run your Django module/function
|
||||
result = "1"
|
||||
print('here')
|
||||
# 2. Return ONLY the HTML fragment you want to show on the page
|
||||
# This will replace the content inside the "hx-target" div
|
||||
return HttpResponse("Done!")
|
||||
|
||||
|
||||
#@login_required
|
||||
@require_POST
|
||||
def change_schedule(request):
|
||||
# HTMX sends these via standard POST data
|
||||
schedule_id = request.POST.get('schedule_id')
|
||||
server_name = request.POST.get('server_name')
|
||||
|
||||
if not schedule_id or not server_name:
|
||||
return HttpResponse("<span style='color: red;'>Missing parameters.</span>", status=400)
|
||||
|
||||
try:
|
||||
# --- Your Core Logic Here ---
|
||||
# e.g., Server.objects.filter(name=server_name).update(schedule_id=schedule_id)
|
||||
print(f"Updating {server_name} to schedule profile {schedule_id}")
|
||||
|
||||
# Return a success message that will instantly inject into the server's status div
|
||||
return HttpResponse("<span style='color: green;'>✓ Updated successfully!</span>")
|
||||
|
||||
except Exception as e:
|
||||
return HttpResponse(f"<span style='color: red;'>Error: {str(e)}</span>", status=500)
|
||||
@@ -11,6 +11,11 @@ import psycopg2
|
||||
import random
|
||||
import mimetypes
|
||||
|
||||
class RandomSimpsonsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'apps.random_simpsons'
|
||||
label = 'simpsons'
|
||||
|
||||
def DB_generation(host_in,port_in,user_in,password_in,db_in):
|
||||
#db = pymysql.connect(host=host_in, port=port_in, user=user_in, passwd=password_in,db=db_in)
|
||||
db = psycopg2.connect(host=host_in, port=port_in, user=user_in, password=password_in,database=db_in)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# Generated by Django 4.2.29 on 2026-06-11 19:50
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='SimpsonsData',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('season', models.IntegerField()),
|
||||
('episode', models.IntegerField()),
|
||||
('url', models.CharField(max_length=100)),
|
||||
('seen', models.CharField(max_length=100)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'simpsons',
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.29 on 2026-06-11 20:31
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('simpsons', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='simpsonsdata',
|
||||
name='seen',
|
||||
field=models.BooleanField(),
|
||||
),
|
||||
]
|
||||
@@ -1,3 +1,10 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
class SimpsonsData(models.Model):
|
||||
season = models.IntegerField()
|
||||
episode = models.IntegerField()
|
||||
url = models.CharField(max_length=100)
|
||||
seen = models.BooleanField()
|
||||
|
||||
class Meta:
|
||||
db_table = 'simpsons'
|
||||
Reference in New Issue
Block a user