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'
|
||||
@@ -1,13 +0,0 @@
|
||||
drop table IF EXISTS machine;
|
||||
CREATE TABLE IF NOT EXISTS machine (
|
||||
id integer NOT NULL PRIMARY KEY,
|
||||
namespace varchar(100) NOT null,
|
||||
name varchar(100) NOT null,
|
||||
hour_behaviour_id integer NOT null,
|
||||
day_behaviour_id integer NOT null,
|
||||
replicas integer NOT null
|
||||
);
|
||||
|
||||
INSERT into machine (id, namespace, name, hour_behaviour_id, day_behaviour_id,replicas) VALUES (1, 'echo', 'echo-server', 0, 1,1);
|
||||
INSERT into machine (id, namespace, name, hour_behaviour_id, day_behaviour_id,replicas) VALUES (2, 'wiki', 'wikijs', 1, 1,2);
|
||||
INSERT into machine (id, namespace, name, hour_behaviour_id, day_behaviour_id,replicas) VALUES (3, 'book', 'bookstack-db', 2, 1,1);
|
||||
@@ -1,16 +0,0 @@
|
||||
create table scenario_day_of_week
|
||||
(
|
||||
id_scenario integer NOT NULL PRIMARY KEY,
|
||||
name_scenario varchar(255) null,
|
||||
state_Monday BOOLEAN null,
|
||||
state_Tuesday BOOLEAN null,
|
||||
state_Wednesday BOOLEAN null,
|
||||
state_Thursday BOOLEAN null,
|
||||
state_Friday BOOLEAN null,
|
||||
state_Saturday BOOLEAN null,
|
||||
state_Sunday BOOLEAN null
|
||||
);
|
||||
|
||||
|
||||
INSERT INTO scenario_day_of_week (id_scenario, name_scenario, state_Monday, state_Tuesday, state_Wednesday, state_Thursday, state_Friday, state_Saturday, state_Sunday) VALUES (0, 'always off', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE);
|
||||
INSERT INTO scenario_day_of_week (id_scenario, name_scenario, state_Monday, state_Tuesday, state_Wednesday, state_Thursday, state_Friday, state_Saturday, state_Sunday) VALUES (1, 'always on', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
|
||||
@@ -1,33 +0,0 @@
|
||||
create table scenario_hour
|
||||
(
|
||||
id_scenario integer NOT NULL PRIMARY KEY,
|
||||
name_scenario varchar(255) null,
|
||||
state_at_0 BOOLEAN null,
|
||||
state_at_1 BOOLEAN null,
|
||||
state_at_2 BOOLEAN null,
|
||||
state_at_3 BOOLEAN null,
|
||||
state_at_4 BOOLEAN null,
|
||||
state_at_5 BOOLEAN null,
|
||||
state_at_6 BOOLEAN null,
|
||||
state_at_7 BOOLEAN null,
|
||||
state_at_8 BOOLEAN null,
|
||||
state_at_9 BOOLEAN null,
|
||||
state_at_10 BOOLEAN null,
|
||||
state_at_11 BOOLEAN null,
|
||||
state_at_12 BOOLEAN null,
|
||||
state_at_13 BOOLEAN null,
|
||||
state_at_14 BOOLEAN null,
|
||||
state_at_15 BOOLEAN null,
|
||||
state_at_16 BOOLEAN null,
|
||||
state_at_17 BOOLEAN null,
|
||||
state_at_18 BOOLEAN null,
|
||||
state_at_19 BOOLEAN null,
|
||||
state_at_20 BOOLEAN null,
|
||||
state_at_21 BOOLEAN null,
|
||||
state_at_22 BOOLEAN null,
|
||||
state_at_23 BOOLEAN null
|
||||
);
|
||||
|
||||
INSERT INTO scenario_hour (id_scenario, name_scenario, state_at_0, state_at_1, state_at_2, state_at_3, state_at_4, state_at_5, state_at_6, state_at_7, state_at_8, state_at_9, state_at_10, state_at_11, state_at_12, state_at_13, state_at_14, state_at_15, state_at_16, state_at_17, state_at_18, state_at_19, state_at_20, state_at_21, state_at_22, state_at_23) VALUES (0, 'always off uk', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE);
|
||||
INSERT INTO scenario_hour (id_scenario, name_scenario, state_at_0, state_at_1, state_at_2, state_at_3, state_at_4, state_at_5, state_at_6, state_at_7, state_at_8, state_at_9, state_at_10, state_at_11, state_at_12, state_at_13, state_at_14, state_at_15, state_at_16, state_at_17, state_at_18, state_at_19, state_at_20, state_at_21, state_at_22, state_at_23) VALUES (1, 'always on uk', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
|
||||
INSERT INTO scenario_hour (id_scenario, name_scenario, state_at_0, state_at_1, state_at_2, state_at_3, state_at_4, state_at_5, state_at_6, state_at_7, state_at_8, state_at_9, state_at_10, state_at_11, state_at_12, state_at_13, state_at_14, state_at_15, state_at_16, state_at_17, state_at_18, state_at_19, state_at_20, state_at_21, state_at_22, state_at_23) VALUES (2, 'awake hours uk', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user