This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 13:59
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0003_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -55,7 +55,7 @@ class Deployment_Data(models.Model):
|
|||||||
schedule_day = models.ForeignKey(Schedule_Day_Data,null=True, blank=True, on_delete=models.SET_NULL)
|
schedule_day = models.ForeignKey(Schedule_Day_Data,null=True, blank=True, on_delete=models.SET_NULL)
|
||||||
replicas = models.IntegerField()
|
replicas = models.IntegerField()
|
||||||
actual_replica = models.IntegerField()
|
actual_replica = models.IntegerField()
|
||||||
do_not_touch_until = models.DateField('do_not_touch_until', blank=True, null=True, auto_now_add=True)
|
do_not_touch_until = models.DateTimeField('do_not_touch_until', blank=True, null=True, auto_now_add=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'machine'
|
db_table = 'machine'
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ from .views import coucou,display,hello,import_namespace_view,retrieve_and_apply
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
################### cloudmanager ###################
|
################### cloudmanager ###################
|
||||||
path('', hello, name='hello'),
|
path('', hello, name='hello'),
|
||||||
path('coucou', coucou, name='coucou'),
|
|
||||||
path('display', display, name='display'),
|
|
||||||
path('import_namespace', import_namespace_view, name='import_namespace'),
|
path('import_namespace', import_namespace_view, name='import_namespace'),
|
||||||
path('retrieve_and_apply_view', retrieve_and_apply_view, name='retrieve_and_apply_view'),
|
path('retrieve_and_apply_view', retrieve_and_apply_view, name='retrieve_and_apply_view'),
|
||||||
path('scale_up/<str:namespace_name>/<str:deploy_name>', scale_up_gui),
|
path('scale_up/<str:namespace_name>/<str:deploy_name>', scale_up_gui),
|
||||||
|
|||||||
@@ -1,31 +1,11 @@
|
|||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
from datetime import timedelta
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
# 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
|
from .utils import import_namespace,retrieve_and_apply
|
||||||
from apps.kubernetes_connection.utils import scale_up,scale_down
|
from apps.kubernetes_connection.utils import scale_up,scale_down
|
||||||
|
from .models import Deployment_Data
|
||||||
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('<h1>Hello cmm! Data saved successfully!</h1>')
|
|
||||||
|
|
||||||
def display(request):
|
|
||||||
data = CmmData.objects.all()
|
|
||||||
print(data[0].namespace)
|
|
||||||
return HttpResponse(data)
|
|
||||||
|
|
||||||
def hello(request):
|
def hello(request):
|
||||||
list_schedule = ['schedule1','schedule2']
|
list_schedule = ['schedule1','schedule2']
|
||||||
@@ -41,27 +21,14 @@ def retrieve_and_apply_view(request):
|
|||||||
output = retrieve_and_apply()
|
output = retrieve_and_apply()
|
||||||
return HttpResponse('<h1>'+output+'</h1>')
|
return HttpResponse('<h1>'+output+'</h1>')
|
||||||
|
|
||||||
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})
|
|
||||||
|
|
||||||
def scale_up_gui(request,namespace_name,deploy_name,replicas=1):
|
def scale_up_gui(request,namespace_name,deploy_name,replicas=1):
|
||||||
|
Deployment_Data.objects.filter(namespace=namespace_name,name=deploy_name).update(do_not_touch_until=timezone.now() + timedelta(hours=1))
|
||||||
scale_up(namespace_name=namespace_name,deploy_name=deploy_name,replicas=replicas)
|
scale_up(namespace_name=namespace_name,deploy_name=deploy_name,replicas=replicas)
|
||||||
return render(request, 'dashboard/start.html', {'namespace':namespace_name,'deployment': deploy_name, 'url': 'https://namespace.com'})
|
return render(request, 'dashboard/start.html', {'namespace':namespace_name,'deployment': deploy_name, 'url': 'https://namespace.com'})
|
||||||
|
|
||||||
|
|
||||||
def scale_down_gui(request,namespace_name,deploy_name):
|
def scale_down_gui(request,namespace_name,deploy_name):
|
||||||
|
Deployment_Data.objects.filter(namespace=namespace_name,name=deploy_name).update(do_not_touch_until=timezone.now() + timedelta(hours=1))
|
||||||
scale_down(namespace_name=namespace_name,deploy_name=deploy_name)
|
scale_down(namespace_name=namespace_name,deploy_name=deploy_name)
|
||||||
return render(request, 'dashboard/shutdown.html',
|
return render(request, 'dashboard/shutdown.html',
|
||||||
{'namespace': namespace_name, 'deployment': deploy_name, 'url': 'https://namespace.com'})
|
{'namespace': namespace_name, 'deployment': deploy_name, 'url': 'https://namespace.com'})
|
||||||
|
|||||||
Reference in New Issue
Block a user