Merge pull request 'freeze period in place' (#45) from testing into main
Dockerfile runner / Explore-Gitea-Actions (push) Successful in 42s
Dockerfile runner / Explore-Gitea-Actions (push) Successful in 42s
Reviewed-on: http://gitea.geeraert.eu/pi-ux-ce/Django_kube/pulls/45
This commit was merged in pull request #45.
This commit is contained in:
@@ -90,6 +90,7 @@ class DeploymentDataAdmin(ImportExportModelAdmin,ExtraButtonsMixin, MultiDBModel
|
|||||||
list_display = ('name', 'namespace', 'schedule_week', 'schedule_day', 'replicas')
|
list_display = ('name', 'namespace', 'schedule_week', 'schedule_day', 'replicas')
|
||||||
list_filter = (ActiveAtHourFilter,)
|
list_filter = (ActiveAtHourFilter,)
|
||||||
actions = [Check_server_supposed_False,Check_server_supposed_true,scale_up_deploy,scale_down_deploy]
|
actions = [Check_server_supposed_False,Check_server_supposed_true,scale_up_deploy,scale_down_deploy]
|
||||||
|
ordering = ('name',)
|
||||||
@button()
|
@button()
|
||||||
def retrieve_and_apply(self, request):
|
def retrieve_and_apply(self, request):
|
||||||
# your business logic here
|
# your business logic here
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.29 on 2026-09-13 15:38
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0002_deployment_data_actual_replica'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateField(blank=True, null=True, verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+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'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 14:14
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0004_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 14, 29, 566084, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 14:14
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0005_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 14, 33, 642627, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 14:35
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0006_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 35, 47, 473312, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 14:35
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0007_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 35, 51, 657797, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 14:43
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0008_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 43, 26, 985719, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 14:43
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0009_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 43, 31, 55115, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 14:46
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0010_alter_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'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-14 15:13
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0011_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='do_not_touch_until',
|
||||||
|
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='do_not_touch_until'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Schedule_Week_Data(models.Model):
|
class Schedule_Week_Data(models.Model):
|
||||||
name_schedule = models.CharField(max_length=100,unique=True)
|
name_schedule = models.CharField(max_length=100,unique=True)
|
||||||
@@ -55,6 +53,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.DateTimeField('do_not_touch_until', default=timezone.now)
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'machine'
|
db_table = 'machine'
|
||||||
|
|
||||||
|
|||||||
@@ -16,15 +16,14 @@ Including another URLconf
|
|||||||
"""
|
"""
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from .views import coucou,display,hello,import_namespace_view,retrieve_and_apply_view
|
from .views import hello,import_namespace_view,retrieve_and_apply_view,scale_up_gui,scale_down_gui
|
||||||
|
|
||||||
|
|
||||||
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_down/<str:namespace_name>/<str:deploy_name>', scale_down_gui),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import datetime
|
from django.utils import timezone
|
||||||
|
import datetime
|
||||||
from apps.kubernetes_connection.utils import get_namespace,get_deployments,scale_up,scale_down
|
from apps.kubernetes_connection.utils import get_namespace,get_deployments,scale_up,scale_down
|
||||||
from apps.cloudmanager.models import Schedule_Day_Data,Schedule_Week_Data,Namespace_Data,Deployment_Data
|
from apps.cloudmanager.models import Schedule_Day_Data,Schedule_Week_Data,Namespace_Data,Deployment_Data
|
||||||
|
|
||||||
@@ -113,6 +113,8 @@ def retrieve_and_apply(verbose=False):
|
|||||||
#check if the expected replica (server[2]) match the current replica of the deployment (server[3].actual_replica)
|
#check if the expected replica (server[2]) match the current replica of the deployment (server[3].actual_replica)
|
||||||
if server[3].actual_replica == server[2]:
|
if server[3].actual_replica == server[2]:
|
||||||
if verbose : print("name: "+str(server[1])+" namespace: "+str(server[0])+" already UP")
|
if verbose : print("name: "+str(server[1])+" namespace: "+str(server[0])+" already UP")
|
||||||
|
elif server[3].do_not_touch_until > timezone.now():
|
||||||
|
if verbose : print("name: "+str(server[1])+" namespace: "+str(server[0])+" is in freeze period")
|
||||||
else:
|
else:
|
||||||
echo = "Starting -> name: "+str(server[1])+" namespace: "+str(server[0])+" replicas: "+str(server[2])
|
echo = "Starting -> name: "+str(server[1])+" namespace: "+str(server[0])+" replicas: "+str(server[2])
|
||||||
output += str(echo)
|
output += str(echo)
|
||||||
@@ -129,6 +131,8 @@ def retrieve_and_apply(verbose=False):
|
|||||||
#check if the current replica of the deployment (server[3].actual_replica) is already 0 meaning the server is already down
|
#check if the current replica of the deployment (server[3].actual_replica) is already 0 meaning the server is already down
|
||||||
if server[3].actual_replica == 0:
|
if server[3].actual_replica == 0:
|
||||||
if verbose : print("name: "+str(server[1])+" namespace: "+str(server[0])+" already DOWN")
|
if verbose : print("name: "+str(server[1])+" namespace: "+str(server[0])+" already DOWN")
|
||||||
|
elif server[3].do_not_touch_until > timezone.now():
|
||||||
|
if verbose : print("name: "+str(server[1])+" namespace: "+str(server[0])+" is in freeze period")
|
||||||
else:
|
else:
|
||||||
|
|
||||||
echo = "Shutting down -> name: "+str(server[1])+" namespace: "+str(server[0])+" replicas: "+str(server[2])
|
echo = "Shutting down -> name: "+str(server[1])+" namespace: "+str(server[0])+" replicas: "+str(server[2])
|
||||||
|
|||||||
@@ -1,30 +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
|
||||||
def coucou(request):
|
from .models import Deployment_Data
|
||||||
# 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']
|
||||||
@@ -40,18 +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):
|
def scale_up_gui(request,namespace_name,deploy_name,replicas=1):
|
||||||
db_host = os.environ.get('DB_HOST')
|
Deployment_Data.objects.filter(namespace=namespace_name,name=deploy_name).update(do_not_touch_until=timezone.now() + timedelta(hours=1))
|
||||||
db_port = os.environ.get('DB_PORT')
|
scale_up(namespace_name=namespace_name,deploy_name=deploy_name,replicas=replicas)
|
||||||
db_user = os.environ.get('DB_USERNAME')
|
return render(request, 'dashboard/start.html', {'namespace':namespace_name,'deployment': deploy_name, 'url': 'https://namespace.com'})
|
||||||
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_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)
|
||||||
|
return render(request, 'dashboard/shutdown.html',
|
||||||
|
{'namespace': namespace_name, 'deployment': deploy_name, 'url': 'https://namespace.com'})
|
||||||
|
|||||||
Reference in New Issue
Block a user