Compare commits
93
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ff4f98841 | ||
|
|
0a8c337b1e | ||
|
|
2dac0d1f53 | ||
|
|
73b627214d | ||
|
|
c79168453b | ||
|
|
299f72abca | ||
|
|
058125f0b1 | ||
|
|
130b0af8d8 | ||
|
|
6f7542ef27 | ||
|
|
919d1a3a28 | ||
|
|
3c4c32e72d | ||
|
|
3294e70b3f | ||
|
|
5908d8d282 | ||
|
|
32f8251a90 | ||
|
|
a3fec86eae | ||
|
|
672edccd70 | ||
|
|
f188e25453 | ||
|
|
d4a72ebf5d | ||
|
|
4492db4185 | ||
|
|
015edcd63d | ||
|
|
aaad6b2b7e | ||
|
|
3b6eccba80 | ||
|
|
44b730dbfc | ||
|
|
ea4ebb0de0 | ||
|
|
3b3e82f16a | ||
|
|
1430afe600 | ||
|
|
e3f01da175 | ||
|
|
7a5c7b6de9 | ||
|
|
c880172aa5 | ||
|
|
6b631fb3e3 | ||
|
|
712f3d50b5 | ||
|
|
f6875b498b | ||
|
|
2e728d4698 | ||
|
|
98a969fa04 | ||
|
|
154717aca7 | ||
|
|
cc0eb74090 | ||
|
|
e2f49a5b1f | ||
|
|
c8ceaab950 | ||
|
|
3fbf333d3d | ||
|
|
3cb09b34da | ||
|
|
1d9d723ce9 | ||
|
|
cf06bfd1bd | ||
|
|
df7340e578 | ||
|
|
7a02fb89f4 | ||
|
|
bfdf8b3b2a | ||
|
|
1ae2917263 | ||
|
|
1fea1c9e23 | ||
|
|
fa804dbed1 | ||
|
|
3b28145d0a | ||
|
|
e9bf6ba7b5 | ||
|
|
cc3394d5eb | ||
|
|
90156a4733 | ||
|
|
314a6f1bed | ||
|
|
eab0ddd697 | ||
|
|
3c1960f015 | ||
|
|
3ff4dd1fae | ||
|
|
dbeaf4c58c | ||
|
|
0f49484a43 | ||
|
|
b540c7b7e8 | ||
|
|
1012ea31ad | ||
|
|
a00baa490f | ||
|
|
bc9e331c68 | ||
|
|
57f58b0c9a | ||
|
|
496a6bd940 | ||
|
|
2bbdad3e47 | ||
|
|
91e0c992ec | ||
|
|
860de928ba | ||
|
|
9d82d61993 | ||
|
|
294af1945d | ||
|
|
430172911e | ||
|
|
38e00d6ac6 | ||
|
|
75004d16f9 | ||
|
|
47e6d6630d | ||
|
|
d9366b665b | ||
|
|
951bf0a807 | ||
|
|
4145db089f | ||
|
|
a2f6d43398 | ||
|
|
5e41927b8d | ||
|
|
ea9459f013 | ||
|
|
c2e34305eb | ||
|
|
a79a9623b6 | ||
|
|
cac74471aa | ||
|
|
189f81d95b | ||
|
|
1a9ea98202 | ||
|
|
b834ff10bf | ||
|
|
7804dd5993 | ||
|
|
56ccc83903 | ||
|
|
1629715732 | ||
|
|
d3a835e3fb | ||
|
|
145e55df92 | ||
|
|
533567b31d | ||
|
|
b438956e96 | ||
|
|
90cb797d2e |
@@ -15,9 +15,9 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
RUNNER_TOOL_CACHE: /toolcache
|
RUNNER_TOOL_CACHE: /toolcache
|
||||||
DEBUG: True
|
DEBUG: True
|
||||||
ALLOWED_HOSTS: "django.tryton.geeraert.eu"
|
ALLOWED_HOSTS: "django.geeraert.eu"
|
||||||
container:
|
container:
|
||||||
image: gitea.tryton.geeraert.eu/pi-ux-ce/custom-runner-debian-slim:1.0.6
|
image: gitea.geeraert.eu/pi-ux-ce/custom-runner-debian-slim:1.0.6
|
||||||
volumes:
|
volumes:
|
||||||
- act-toolcache:/opt/hostedtoolcache # this is where Runner store their cache default
|
- act-toolcache:/opt/hostedtoolcache # this is where Runner store their cache default
|
||||||
runs-on: host-runner
|
runs-on: host-runner
|
||||||
@@ -59,7 +59,7 @@ jobs:
|
|||||||
- name: Login to gitea
|
- name: Login to gitea
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: gitea.tryton.geeraert.eu
|
registry: gitea.geeraert.eu
|
||||||
username: ${{ secrets.USERNAME_GITEA }}
|
username: ${{ secrets.USERNAME_GITEA }}
|
||||||
password: ${{ secrets.PASSWORD_GITEA }}
|
password: ${{ secrets.PASSWORD_GITEA }}
|
||||||
|
|
||||||
@@ -67,16 +67,16 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
docker build \
|
docker build \
|
||||||
-f infra/production/dockerfile \
|
-f infra/production/dockerfile \
|
||||||
--build-arg ALLOWED_HOSTS='django.tryton.geeraert.eu' \
|
--build-arg ALLOWED_HOSTS='django.geeraert.eu' \
|
||||||
--build-arg DEBUG='True' \
|
--build-arg DEBUG='True' \
|
||||||
-t gitea.tryton.geeraert.eu/pi-ux-ce/django-python:latest \
|
-t gitea.geeraert.eu/pi-ux-ce/django-python:latest \
|
||||||
-t gitea.tryton.geeraert.eu/pi-ux-ce/django-python:${{ env.next_version }} \
|
-t gitea.geeraert.eu/pi-ux-ce/django-python:${{ env.next_version }} \
|
||||||
.
|
.
|
||||||
|
|
||||||
- name: Push image
|
- name: Push image
|
||||||
run: |
|
run: |
|
||||||
docker push gitea.tryton.geeraert.eu/pi-ux-ce/django-python:latest
|
docker push gitea.geeraert.eu/pi-ux-ce/django-python:latest
|
||||||
docker push gitea.tryton.geeraert.eu/pi-ux-ce/django-python:${{ env.next_version }}
|
docker push gitea.geeraert.eu/pi-ux-ce/django-python:${{ env.next_version }}
|
||||||
|
|
||||||
- name: Rollout Django to force pulling the new image
|
- name: Rollout Django to force pulling the new image
|
||||||
uses: actions-hub/kubectl@master
|
uses: actions-hub/kubectl@master
|
||||||
@@ -91,7 +91,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
curl -X PUT -H "Content-Type: application/json" \
|
curl -X PUT -H "Content-Type: application/json" \
|
||||||
--user ${{ secrets.USERNAME_GITEA }}:${{ secrets.PASSWORD_GITEA }} \
|
--user ${{ secrets.USERNAME_GITEA }}:${{ secrets.PASSWORD_GITEA }} \
|
||||||
https://gitea.tryton.geeraert.eu/api/v1/repos/pi-ux-ce/${{ github.event.repository.name }}/actions/variables/VERSION \
|
https://gitea.geeraert.eu/api/v1/repos/pi-ux-ce/${{ github.event.repository.name }}/actions/variables/VERSION \
|
||||||
-d "{\"Value\":\"$next_version\"}"
|
-d "{\"Value\":\"$next_version\"}"
|
||||||
|
|
||||||
- name: backup git for future use
|
- name: backup git for future use
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ jobs:
|
|||||||
- name: Login to gitea
|
- name: Login to gitea
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: gitea.tryton.geeraert.eu
|
registry: gitea.geeraert.eu
|
||||||
username: ${{ secrets.USERNAME_GITEA }}
|
username: ${{ secrets.USERNAME_GITEA }}
|
||||||
password: ${{ secrets.PASSWORD_GITEA }}
|
password: ${{ secrets.PASSWORD_GITEA }}
|
||||||
|
|
||||||
@@ -44,23 +44,23 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
docker build \
|
docker build \
|
||||||
-f infra/testing/dockerfile \
|
-f infra/testing/dockerfile \
|
||||||
--build-arg ALLOWED_HOSTS='django-testing.tryton.geeraert.eu' \
|
--build-arg ALLOWED_HOSTS='django-testing.geeraert.eu' \
|
||||||
--build-arg DEBUG='True' \
|
--build-arg DEBUG='True' \
|
||||||
--build-arg CACHE_BUST=${{ env.next_version }} \
|
--build-arg CACHE_BUST=${{ env.next_version }} \
|
||||||
-t gitea.tryton.geeraert.eu/pi-ux-ce/django-testing:latest \
|
-t gitea.geeraert.eu/pi-ux-ce/django-testing:latest \
|
||||||
-t gitea.tryton.geeraert.eu/pi-ux-ce/django-testing:${{ env.next_version }} \
|
-t gitea.geeraert.eu/pi-ux-ce/django-testing:${{ env.next_version }} \
|
||||||
.
|
.
|
||||||
|
|
||||||
- name: Push image
|
- name: Push image
|
||||||
run: |
|
run: |
|
||||||
docker push gitea.tryton.geeraert.eu/pi-ux-ce/django-testing:latest
|
docker push gitea.geeraert.eu/pi-ux-ce/django-testing:latest
|
||||||
docker push gitea.tryton.geeraert.eu/pi-ux-ce/django-testing:${{ env.next_version }}
|
docker push gitea.geeraert.eu/pi-ux-ce/django-testing:${{ env.next_version }}
|
||||||
|
|
||||||
- name: update version in the variable
|
- name: update version in the variable
|
||||||
run: |
|
run: |
|
||||||
curl -X PUT -H "Content-Type: application/json" \
|
curl -X PUT -H "Content-Type: application/json" \
|
||||||
--user ${{ secrets.USERNAME_GITEA }}:${{ secrets.PASSWORD_GITEA }} \
|
--user ${{ secrets.USERNAME_GITEA }}:${{ secrets.PASSWORD_GITEA }} \
|
||||||
https://gitea.tryton.geeraert.eu/api/v1/repos/pi-ux-ce/${{ github.event.repository.name }}/actions/variables/VERSION_TESTING \
|
https://gitea.geeraert.eu/api/v1/repos/pi-ux-ce/${{ github.event.repository.name }}/actions/variables/VERSION_TESTING \
|
||||||
-d "{\"Value\":\"$next_version\"}"
|
-d "{\"Value\":\"$next_version\"}"
|
||||||
|
|
||||||
- name: Rollout Django to force pulling the new image
|
- name: Rollout Django to force pulling the new image
|
||||||
|
|||||||
@@ -72,14 +72,14 @@ export bitwarden_organization_id=""
|
|||||||
|
|
||||||
```
|
```
|
||||||
cd existing_repo
|
cd existing_repo
|
||||||
git remote add origin https://gitlab.tryton.geeraert.eu/pierre/django_kube.git
|
git remote add origin https://gitea.geeraert.eu/pi-ux-ce/Django_kube.git
|
||||||
git branch -M main
|
git branch -M main
|
||||||
git push -uf origin main
|
git push -uf origin main
|
||||||
```
|
```
|
||||||
|
|
||||||
## Integrate with your tools
|
## Integrate with your tools
|
||||||
|
|
||||||
- [ ] [Set up project integrations](https://gitlab.tryton.geeraert.eu/pierre/django_kube/-/settings/integrations)
|
- [ ] [Set up project integrations](https://gitlab.geeraert.eu/pierre/django_kube/-/settings/integrations)
|
||||||
|
|
||||||
## Collaborate with your team
|
## Collaborate with your team
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,24 @@ class betaserieUtils():
|
|||||||
|
|
||||||
return show_id
|
return show_id
|
||||||
|
|
||||||
|
def poster_serie(self,serie_name,verbose=False):
|
||||||
|
#
|
||||||
|
# Usage
|
||||||
|
# poster_url = beta.poster_serie("The simpsons")
|
||||||
|
# poster_url = beta.poster_serie("The simpsons",verbose=True)
|
||||||
|
#
|
||||||
|
url = "https://api.betaseries.com/shows/search?title="+serie_name
|
||||||
|
|
||||||
|
response = requests.request("GET", url, headers=self.headers, data=self.payload)
|
||||||
|
if verbose:
|
||||||
|
print("Url request: "+str(url))
|
||||||
|
print(response.text)
|
||||||
|
|
||||||
|
poster_url = response.json()['shows'][0]['images']['show']
|
||||||
|
|
||||||
|
return poster_url
|
||||||
|
|
||||||
|
|
||||||
def identify_episode(self,show_id,episode_number,verbose=False):
|
def identify_episode(self,show_id,episode_number,verbose=False):
|
||||||
#
|
#
|
||||||
# Usage
|
# Usage
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ class bitwardenUtils():
|
|||||||
client = BitwardenClient(
|
client = BitwardenClient(
|
||||||
client_settings_from_dict(
|
client_settings_from_dict(
|
||||||
{
|
{
|
||||||
"apiUrl": os.getenv("API_URL", "https://bitwarden.tryton.geeraert.eu/api"),
|
"apiUrl": os.getenv("API_URL", "https://bitwarden.geeraert.eu/api"),
|
||||||
"deviceType": DeviceType.SDK,
|
"deviceType": DeviceType.SDK,
|
||||||
"identityUrl": os.getenv("IDENTITY_URL", "https://bitwarden.tryton.geeraert.eu/identity"),
|
"identityUrl": os.getenv("IDENTITY_URL", "https://bitwarden.geeraert.eu/identity"),
|
||||||
"userAgent": "Python",
|
"userAgent": "Python",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
from django.contrib import admin,messages
|
from django.contrib import admin,messages
|
||||||
from django.utils.translation import ngettext
|
from django.utils.translation import ngettext
|
||||||
from .models import Deployment_Data,Schedule_Day_Data,Schedule_Week_Data,Namespace_Data
|
from .models import Deployment_Data,Schedule_Day_Data,Schedule_Week_Data,Namespace_Data,Ingress_Data
|
||||||
from .utils import import_namespace,import_deployment,generate_default_day_schedule,generate_default_week_schedule
|
from .utils import import_namespace,import_deployment,generate_default_day_schedule,generate_default_week_schedule,Check_server_supposed_XXX,retrieve_and_apply
|
||||||
from apps.kubernetes_connection.utils import scale_up,scale_down
|
from apps.kubernetes_connection.utils import scale_up,scale_down
|
||||||
|
from admin_extra_buttons.api import button
|
||||||
|
from core.admin import UniversalModelAdmin
|
||||||
|
|
||||||
DB = 'cloudmanager_db'
|
|
||||||
|
|
||||||
|
|
||||||
@admin.action(description="scale up")
|
@admin.action(description="scale up")
|
||||||
@@ -38,20 +39,17 @@ def scale_down_deploy(modeladmin, request, queryset):
|
|||||||
messages.SUCCESS,
|
messages.SUCCESS,
|
||||||
)
|
)
|
||||||
|
|
||||||
@admin.action(description="create default schedule")
|
@admin.action(description="Expected False")
|
||||||
def generate_default_day_schedule_admin(modeladmin, request, queryset):
|
def Check_server_supposed_False(modeladmin, request, queryset):
|
||||||
generate_default_day_schedule()
|
servers_supposed_false = Check_server_supposed_XXX(False)
|
||||||
generate_default_week_schedule()
|
for server in servers_supposed_false:
|
||||||
|
messages.add_message(request, messages.INFO, server)
|
||||||
|
|
||||||
@admin.action(description="import namespace")
|
|
||||||
def import_namespace_admin(modeladmin, request, queryset):
|
|
||||||
import_namespace()
|
|
||||||
|
|
||||||
@admin.action(description="import deployment")
|
|
||||||
def import_deployment_admin(modeladmin, request, queryset):
|
|
||||||
import_deployment()
|
|
||||||
|
|
||||||
|
@admin.action(description="Expected True")
|
||||||
|
def Check_server_supposed_true(modeladmin, request, queryset):
|
||||||
|
servers_supposed_false = Check_server_supposed_XXX(True)
|
||||||
|
for server in servers_supposed_false:
|
||||||
|
messages.add_message(request, messages.INFO, server)
|
||||||
|
|
||||||
|
|
||||||
class ActiveAtHourFilter(admin.SimpleListFilter):
|
class ActiveAtHourFilter(admin.SimpleListFilter):
|
||||||
@@ -68,45 +66,58 @@ class ActiveAtHourFilter(admin.SimpleListFilter):
|
|||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
class MultiDBModelAdmin(admin.ModelAdmin):
|
|
||||||
"""Base class that pins all admin operations to DB."""
|
|
||||||
db = DB
|
|
||||||
|
|
||||||
def get_queryset(self, request):
|
|
||||||
return super().get_queryset(request).using(self.db)
|
|
||||||
|
|
||||||
def save_model(self, request, obj, form, change):
|
|
||||||
obj.save(using=self.db)
|
|
||||||
|
|
||||||
def delete_model(self, request, obj):
|
|
||||||
obj.delete(using=self.db)
|
|
||||||
|
|
||||||
def delete_queryset(self, request, queryset):
|
|
||||||
queryset.using(self.db).delete()
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Deployment_Data)
|
@admin.register(Deployment_Data)
|
||||||
class DeploymentDataAdmin(MultiDBModelAdmin):
|
class DeploymentDataAdmin(UniversalModelAdmin):
|
||||||
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 = [scale_up_deploy,scale_down_deploy,import_deployment_admin,generate_default_day_schedule_admin]
|
actions = [Check_server_supposed_False,Check_server_supposed_true,scale_up_deploy,scale_down_deploy]
|
||||||
|
ordering = ('name',)
|
||||||
|
@button()
|
||||||
|
def retrieve_and_apply(self, request):
|
||||||
|
# your business logic here
|
||||||
|
retrieve_and_apply()
|
||||||
|
self.message_user(request, 'Operation started')
|
||||||
|
|
||||||
|
@button()
|
||||||
|
def import_deployment(self, request):
|
||||||
|
# your business logic here
|
||||||
|
import_deployment()
|
||||||
|
self.message_user(request, 'Deployments imported')
|
||||||
|
|
||||||
@admin.register(Schedule_Day_Data)
|
@admin.register(Schedule_Day_Data)
|
||||||
class ScheduleDayAdmin(MultiDBModelAdmin):
|
class ScheduleDayAdmin(UniversalModelAdmin):
|
||||||
list_display = ['name_schedule'] + [f'state_at_{h}' for h in range(24)]
|
list_display = ['name_schedule'] + [f'state_at_{h}' for h in range(24)]
|
||||||
actions = [import_deployment_admin,generate_default_day_schedule_admin]
|
@button()
|
||||||
|
def generate_default_day_schedule_admin(self, request):
|
||||||
|
generate_default_day_schedule()
|
||||||
|
generate_default_week_schedule()
|
||||||
|
self.message_user(request, 'Created default schedules')
|
||||||
|
|
||||||
@admin.register(Schedule_Week_Data)
|
@admin.register(Schedule_Week_Data)
|
||||||
class ScheduleWeekAdmin(MultiDBModelAdmin):
|
class ScheduleWeekAdmin(UniversalModelAdmin):
|
||||||
list_display = (
|
list_display = (
|
||||||
'name_schedule',
|
'name_schedule',
|
||||||
'state_Monday', 'state_Tuesday', 'state_Wednesday',
|
'state_Monday', 'state_Tuesday', 'state_Wednesday',
|
||||||
'state_Thursday', 'state_Friday', 'state_Saturday', 'state_Sunday',
|
'state_Thursday', 'state_Friday', 'state_Saturday', 'state_Sunday',
|
||||||
)
|
)
|
||||||
actions = [import_deployment_admin,generate_default_day_schedule_admin]
|
@button()
|
||||||
|
def generate_default_day_schedule_admin(self, request):
|
||||||
|
generate_default_day_schedule()
|
||||||
|
generate_default_week_schedule()
|
||||||
|
self.message_user(request, 'Created default schedules')
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Namespace_Data)
|
@admin.register(Namespace_Data)
|
||||||
class NamespaceAdmin(MultiDBModelAdmin):
|
class NamespaceAdmin(UniversalModelAdmin):
|
||||||
list_display = ('namespace',)
|
list_display = ('namespace',)
|
||||||
actions = [import_namespace_admin]
|
|
||||||
|
|
||||||
|
@button()
|
||||||
|
def import_namespace(self, request):
|
||||||
|
# your business logic here
|
||||||
|
import_namespace()
|
||||||
|
self.message_user(request, 'Namespaces imported')
|
||||||
|
|
||||||
|
@admin.register(Ingress_Data)
|
||||||
|
class IngressAdmin(UniversalModelAdmin):
|
||||||
|
list_display = ('url','namespace')
|
||||||
@@ -1,37 +1,6 @@
|
|||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class CloudmanagerConfig(AppConfig):
|
class CloudmanagerConfig(AppConfig):
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
name = 'apps.cloudmanager'
|
name = 'apps.cloudmanager'
|
||||||
label = '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]]
|
|
||||||
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})
|
|
||||||
|
|
||||||
|
|||||||
@@ -154,10 +154,6 @@ def main(request):
|
|||||||
#print(Is_the_server_already_wanted_state(112, "stopped"))
|
#print(Is_the_server_already_wanted_state(112, "stopped"))
|
||||||
return HttpResponse('<h1>CMM executed!</h1>')
|
return HttpResponse('<h1>CMM executed!</h1>')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
TO DO:
|
TO DO:
|
||||||
EXTRACT TYPE OF MACHINE
|
EXTRACT TYPE OF MACHINE
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-09 12:48
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='deployment_data',
|
||||||
|
name='actual_replica',
|
||||||
|
field=models.IntegerField(default=1),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -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'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-21 16:14
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0012_alter_deployment_data_do_not_touch_until'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Ingress_Data',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('url', models.CharField(max_length=100)),
|
||||||
|
('namespace', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='cloudmanager.namespace_data')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-21 21:06
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cloudmanager', '0013_ingress_data'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='ingress_data',
|
||||||
|
name='namespace',
|
||||||
|
field=models.CharField(blank=True, max_length=100, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -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)
|
||||||
@@ -54,6 +52,8 @@ class Deployment_Data(models.Model):
|
|||||||
schedule_week = models.ForeignKey(Schedule_Week_Data,null=True, blank=True, on_delete=models.SET_NULL)
|
schedule_week = models.ForeignKey(Schedule_Week_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)
|
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()
|
||||||
|
do_not_touch_until = models.DateTimeField('do_not_touch_until', default=timezone.now)
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'machine'
|
db_table = 'machine'
|
||||||
|
|
||||||
@@ -62,3 +62,9 @@ class Namespace_Data(models.Model):
|
|||||||
#deployments = models.ForeignKey(Schedule_Week_Data,null=True, blank=True, on_delete=models.SET_NULL)
|
#deployments = models.ForeignKey(Schedule_Week_Data,null=True, blank=True, on_delete=models.SET_NULL)
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'namespace'
|
db_table = 'namespace'
|
||||||
|
def __str__(self):
|
||||||
|
return self.namespace
|
||||||
|
|
||||||
|
class Ingress_Data(models.Model):
|
||||||
|
url = models.CharField(max_length=100)
|
||||||
|
namespace = models.CharField(max_length=100,null=True, blank=True)
|
||||||
|
|||||||
@@ -15,25 +15,19 @@ Including another URLconf
|
|||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
from apps.cloudmanager import apps as cloudmanager_apps
|
|
||||||
from apps.cloudmanager import views as cloudmanager_views
|
from .views import hello,import_namespace_view,retrieve_and_apply_view,scale_up_gui,scale_down_gui,add_ingress,delete_ingress
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
################### cloudmanager ###################
|
################### cloudmanager ###################
|
||||||
path('', cloudmanager_apps.redirect),
|
path('', hello, name='hello'),
|
||||||
path('hello', cloudmanager_apps.hello, name='hello'),
|
path('import_namespace', import_namespace_view, name='import_namespace'),
|
||||||
path('coucou', cloudmanager_views.coucou, name='coucou'),
|
path('retrieve_and_apply_view', retrieve_and_apply_view, name='retrieve_and_apply_view'),
|
||||||
path('display', cloudmanager_views.display, name='display'),
|
path('scale_up/<str:namespace_name>/<str:deploy_name>', scale_up_gui),
|
||||||
#path('/run-action/', cloudmanager_views.trigger_my_action, name='run_my_action_url'),
|
path('scale_down/<str:namespace_name>/<str:deploy_name>', scale_down_gui),
|
||||||
#path('change-schedule/', cloudmanager_views.change_schedule, name='change_schedule'),
|
path('add_ingress', add_ingress),
|
||||||
#path('/main/', db_interaction.main),
|
path('delete_ingress', delete_ingress),
|
||||||
|
|
||||||
################### onenote ###################
|
|
||||||
path('dashboard/', dashboardapp.hello),
|
|
||||||
path('view/about', dashboardview.about),
|
|
||||||
path('view/home', dashboardview.home),
|
|
||||||
path('view/success', dashboardview.success),
|
|
||||||
path('scale_up/<str:namespace_name>/<str:deploy_name>', dashboardview.scale_up),
|
|
||||||
path('scale_down/<str:namespace_name>/<str:deploy_name>', dashboardview.scale_down),
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,23 +1,144 @@
|
|||||||
from apps.kubernetes_connection.utils import get_namespace,get_deployments
|
from django.utils import timezone
|
||||||
from .models import Schedule_Day_Data,Schedule_Week_Data,Namespace_Data,Deployment_Data
|
import datetime
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def import_namespace():
|
def import_namespace():
|
||||||
namespaces_list = get_namespace()
|
namespaces_list = get_namespace()
|
||||||
for namespace in namespaces_list:
|
for namespace in namespaces_list:
|
||||||
Namespace_Data.objects.get_or_create(namespace=namespace)
|
if namespace[0]!="kube-system":
|
||||||
|
Namespace_Data.objects.get_or_create(namespace=namespace)
|
||||||
|
|
||||||
def import_deployment(Deployment_Data):
|
def import_deployment():
|
||||||
deployment_list = get_deployments()
|
deployment_list = get_deployments()
|
||||||
|
Schedule_Day_Always_off,Schedule_Day_Always_on = generate_default_day_schedule()
|
||||||
|
Schedule_Week_Always_off,Schedule_Week_Always_on = generate_default_week_schedule()
|
||||||
|
|
||||||
for deployment in deployment_list:
|
for deployment in deployment_list:
|
||||||
Deployment_Data.objects.get_or_create(namespace=deployment[0],name=deployment[1],defaults={"replicas":deployment[2],"schedule_week":"Always_on"})
|
#if the replicas is originally 0 , it means it is disabled so put the schedule as always off
|
||||||
|
if deployment[2] == 0:
|
||||||
|
schedule_object = Schedule_Day_Always_off
|
||||||
|
else:
|
||||||
|
schedule_object = Schedule_Day_Always_on
|
||||||
|
if deployment[0]!="kube-system":
|
||||||
|
Deployment_Data.objects.get_or_create(namespace=deployment[0],name=deployment[1],defaults={"replicas":deployment[2],"actual_replica":deployment[2],"schedule_day":schedule_object,"schedule_week":Schedule_Week_Always_on})
|
||||||
|
|
||||||
|
|
||||||
def generate_default_day_schedule():
|
def generate_default_day_schedule():
|
||||||
Schedule_Day_Data.objects.update_or_create(name_schedule="Always_off",defaults={"state_at_0" : False ,"state_at_1" : False ,"state_at_2" : False ,"state_at_3" : False ,"state_at_4" : False ,"state_at_5" : False ,"state_at_6" : False ,"state_at_7" : False ,"state_at_8" : False ,"state_at_9" : False ,"state_at_10" : False ,"state_at_11" : False ,"state_at_12" : False ,"state_at_13" : False ,"state_at_14" : False ,"state_at_15" : False ,"state_at_16" : False ,"state_at_17" : False ,"state_at_18" : False ,"state_at_19" : False ,"state_at_20" : False ,"state_at_21" : False ,"state_at_22" : False ,"state_at_23" : False})
|
Always_off,status = Schedule_Day_Data.objects.update_or_create(name_schedule="Always_off",defaults={"state_at_0" : False ,"state_at_1" : False ,"state_at_2" : False ,"state_at_3" : False ,"state_at_4" : False ,"state_at_5" : False ,"state_at_6" : False ,"state_at_7" : False ,"state_at_8" : False ,"state_at_9" : False ,"state_at_10" : False ,"state_at_11" : False ,"state_at_12" : False ,"state_at_13" : False ,"state_at_14" : False ,"state_at_15" : False ,"state_at_16" : False ,"state_at_17" : False ,"state_at_18" : False ,"state_at_19" : False ,"state_at_20" : False ,"state_at_21" : False ,"state_at_22" : False ,"state_at_23" : False})
|
||||||
Schedule_Day_Data.objects.update_or_create(name_schedule="Always_on",defaults={"state_at_0" : True ,"state_at_1" : True ,"state_at_2" : True ,"state_at_3" : True ,"state_at_4" : True ,"state_at_5" : True ,"state_at_6" : True ,"state_at_7" : True ,"state_at_8" : True ,"state_at_9" : True ,"state_at_10" : True ,"state_at_11" : True ,"state_at_12" : True ,"state_at_13" : True ,"state_at_14" : True ,"state_at_15" : True ,"state_at_16" : True ,"state_at_17" : True ,"state_at_18" : True ,"state_at_19" : True ,"state_at_20" : True ,"state_at_21" : True ,"state_at_22" : True ,"state_at_23" : True})
|
Always_on,status = Schedule_Day_Data.objects.update_or_create(name_schedule="Always_on",defaults={"state_at_0" : True ,"state_at_1" : True ,"state_at_2" : True ,"state_at_3" : True ,"state_at_4" : True ,"state_at_5" : True ,"state_at_6" : True ,"state_at_7" : True ,"state_at_8" : True ,"state_at_9" : True ,"state_at_10" : True ,"state_at_11" : True ,"state_at_12" : True ,"state_at_13" : True ,"state_at_14" : True ,"state_at_15" : True ,"state_at_16" : True ,"state_at_17" : True ,"state_at_18" : True ,"state_at_19" : True ,"state_at_20" : True ,"state_at_21" : True ,"state_at_22" : True ,"state_at_23" : True})
|
||||||
|
return Always_off,Always_on
|
||||||
|
|
||||||
def generate_default_week_schedule():
|
def generate_default_week_schedule():
|
||||||
Schedule_Week_Data.objects.update_or_create(name_schedule="Always_on",defaults={"state_Monday" : True , "state_Tuesday" : True , "state_Wednesday" : True , "state_Thursday" : True , "state_Friday" : True , "state_Saturday" : True , "state_Sunday" : True})
|
Always_off,status = Schedule_Week_Data.objects.update_or_create(name_schedule="Always_off",defaults={"state_Monday" : False , "state_Tuesday" : False , "state_Wednesday" : False , "state_Thursday" : False , "state_Friday" : False , "state_Saturday" : False , "state_Sunday" : False})
|
||||||
Schedule_Week_Data.objects.update_or_create(name_schedule="Always_off",defaults={"state_Monday" : False , "state_Tuesday" : False , "state_Wednesday" : False , "state_Thursday" : False , "state_Friday" : False , "state_Saturday" : False , "state_Sunday" : False})
|
Always_on,status = Schedule_Week_Data.objects.update_or_create(name_schedule="Always_on",defaults={"state_Monday" : True , "state_Tuesday" : True , "state_Wednesday" : True , "state_Thursday" : True , "state_Friday" : True , "state_Saturday" : True , "state_Sunday" : True})
|
||||||
|
return Always_off,Always_on
|
||||||
|
|
||||||
|
def Give_current_weekday():
|
||||||
|
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday','Saturday', 'Sunday']
|
||||||
|
weekday = days[datetime.datetime.today().weekday()]
|
||||||
|
return weekday
|
||||||
|
|
||||||
|
def Give_current_hour():
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
return now.hour
|
||||||
|
|
||||||
|
def get_current_replicas():
|
||||||
|
deployments_list = get_deployments()
|
||||||
|
for deployment in deployments_list:
|
||||||
|
if deployment[0]!="kube-system":
|
||||||
|
object,created = Deployment_Data.objects.update_or_create(namespace=deployment[0],name=deployment[1],defaults={"actual_replica":deployment[2]})
|
||||||
|
if created:
|
||||||
|
print("THIS DEPLOY: name: "+str(server[1])+" namespace: "+str(server[0])+" replicas: "+str(server[2])+" IS NEW !!!!!")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def Check_server_supposed_XXX(expected_status,verbose=False):
|
||||||
|
#just for testing
|
||||||
|
#expected_status = True
|
||||||
|
|
||||||
|
# Get week schedule
|
||||||
|
|
||||||
|
argument_week="state_"+str(Give_current_weekday())
|
||||||
|
query_week = {argument_week : expected_status}
|
||||||
|
|
||||||
|
schedules_week = Schedule_Week_Data.objects.filter(**query_week)
|
||||||
|
|
||||||
|
# Get day schedule
|
||||||
|
|
||||||
|
argument_day="state_at_"+str(Give_current_hour())
|
||||||
|
query_day = {argument_day : expected_status}
|
||||||
|
|
||||||
|
schedules_day = Schedule_Day_Data.objects.filter(**query_day)
|
||||||
|
|
||||||
|
if expected_status:
|
||||||
|
deployments = Deployment_Data.objects.filter(schedule_week__in=schedules_week, schedule_day__in=schedules_day)
|
||||||
|
else:
|
||||||
|
deployments = Deployment_Data.objects.filter(schedule_week__in=schedules_week) | Deployment_Data.objects.filter(schedule_day__in=schedules_day)
|
||||||
|
|
||||||
|
deployments_list = []
|
||||||
|
for deployment in deployments:
|
||||||
|
display_list = []
|
||||||
|
name = deployment.name
|
||||||
|
display_list.append(name)
|
||||||
|
if verbose : print("name: "+str(name))
|
||||||
|
namespace = deployment.namespace
|
||||||
|
display_list.append(namespace)
|
||||||
|
if verbose : print("namespace: "+str(namespace))
|
||||||
|
replicas = deployment.replicas
|
||||||
|
display_list.append(replicas)
|
||||||
|
if verbose : print("replicas: "+str(replicas))
|
||||||
|
#Adding the whole object as well for future use
|
||||||
|
display_list.append(deployment)
|
||||||
|
deployments_list.append(display_list)
|
||||||
|
|
||||||
|
return deployments_list
|
||||||
|
|
||||||
|
|
||||||
|
def retrieve_and_apply(verbose=False):
|
||||||
|
output = ""
|
||||||
|
output += str(Give_current_hour())
|
||||||
|
output += str("\n")
|
||||||
|
|
||||||
|
|
||||||
|
#Get current replica to compare with the replicas created at the start
|
||||||
|
get_current_replicas()
|
||||||
|
|
||||||
|
print("------------------------------------------")
|
||||||
|
print("-----------------UP-----------------------")
|
||||||
|
print("------------------------------------------")
|
||||||
|
servers_supposed_true = Check_server_supposed_XXX(True)
|
||||||
|
for server in servers_supposed_true:
|
||||||
|
#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 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:
|
||||||
|
echo = "Starting -> name: "+str(server[1])+" namespace: "+str(server[0])+" replicas: "+str(server[2])
|
||||||
|
output += str(echo)
|
||||||
|
output += "\n"
|
||||||
|
print(echo)
|
||||||
|
|
||||||
|
scale_up(namespace_name=server[1],deploy_name=server[0],replicas=server[2])
|
||||||
|
|
||||||
|
print("------------------------------------------")
|
||||||
|
print("----------------DOWN----------------------")
|
||||||
|
print("------------------------------------------")
|
||||||
|
servers_supposed_false = Check_server_supposed_XXX(False)
|
||||||
|
for server in servers_supposed_false:
|
||||||
|
#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 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:
|
||||||
|
|
||||||
|
echo = "Shutting down -> name: "+str(server[1])+" namespace: "+str(server[0])+" replicas: "+str(server[2])
|
||||||
|
output += str(echo)
|
||||||
|
output += str("\n")
|
||||||
|
print(echo)
|
||||||
|
scale_down(namespace_name=server[1],deploy_name=server[0])
|
||||||
|
print("------------------------------------------")
|
||||||
|
return output
|
||||||
@@ -1,25 +1,77 @@
|
|||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
from django.shortcuts import render
|
||||||
|
from datetime import timedelta
|
||||||
|
from django.utils import timezone
|
||||||
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
from django.http import JsonResponse
|
||||||
|
|
||||||
# IMPORT AT THE TOP HERE: This is completely safe!
|
from apps.import_aggregator.import_rest_framework import api_view, authentication_classes, permission_classes,TokenAuthentication,IsAuthenticated,Response,status
|
||||||
from apps.cloudmanager.models import Deployment_Data,Schedule_Week_Data
|
|
||||||
|
|
||||||
def coucou(request):
|
from .utils import import_namespace,retrieve_and_apply
|
||||||
# 1. Prepare the data inside the function
|
from apps.kubernetes_connection.utils import scale_up,scale_down
|
||||||
data = CmmData(
|
from .models import Deployment_Data,Ingress_Data
|
||||||
name="test",
|
|
||||||
namespace="testspace",
|
|
||||||
schedule_hour="1",
|
|
||||||
schedule_day="deux",
|
|
||||||
replicas=3
|
|
||||||
)
|
|
||||||
|
|
||||||
# 2. This line actually pushes the data into your cloudmanager_db!
|
def hello(request):
|
||||||
data.save()
|
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})
|
||||||
|
|
||||||
return HttpResponse('<h1>Hello cmm! Data saved successfully!</h1>')
|
def import_namespace_view(request):
|
||||||
|
import_namespace()
|
||||||
|
return HttpResponse('<h1>Namespace imported!</h1>')
|
||||||
|
|
||||||
def display(request):
|
|
||||||
data = CmmData.objects.all()
|
def retrieve_and_apply_view(request):
|
||||||
print(data[0].namespace)
|
output = retrieve_and_apply()
|
||||||
return HttpResponse(data)
|
return HttpResponse('<h1>'+output+'</h1>')
|
||||||
|
|
||||||
|
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)
|
||||||
|
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):
|
||||||
|
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'})
|
||||||
|
|
||||||
|
|
||||||
|
@api_view(['POST'])
|
||||||
|
@authentication_classes([TokenAuthentication])
|
||||||
|
@permission_classes([IsAuthenticated])
|
||||||
|
def add_ingress(request):
|
||||||
|
url = request.POST.get('url')
|
||||||
|
namespace = request.POST.get('namespace')
|
||||||
|
print("URL: "+str(url))
|
||||||
|
print("NS: "+str(namespace))
|
||||||
|
|
||||||
|
try:
|
||||||
|
Ingress_Data.objects.update_or_create(url=url,namespace=namespace)
|
||||||
|
except Exception as exception:
|
||||||
|
return JsonResponse({"status": "error","reason":str(exception)})
|
||||||
|
|
||||||
|
return JsonResponse({"status": "added","url":str(url),"namespace":str(namespace)})
|
||||||
|
|
||||||
|
@api_view(['POST'])
|
||||||
|
@authentication_classes([TokenAuthentication])
|
||||||
|
@permission_classes([IsAuthenticated])
|
||||||
|
def delete_ingress(request):
|
||||||
|
url = request.POST.get('url')
|
||||||
|
namespace = request.POST.get('namespace')
|
||||||
|
print("URL: "+str(url))
|
||||||
|
print("NS: "+str(namespace))
|
||||||
|
|
||||||
|
try:
|
||||||
|
ingress_object = Ingress_Data.objects.filter(url=url,namespace=namespace)
|
||||||
|
except Exception as exception:
|
||||||
|
return JsonResponse({"status": "error","reason":str(exception)})
|
||||||
|
|
||||||
|
try:
|
||||||
|
ingress_object.delete()
|
||||||
|
except Exception as exception:
|
||||||
|
return JsonResponse({"status": "error","reason":str(exception)})
|
||||||
|
|
||||||
|
return JsonResponse({"status": "deleted","url":str(url),"namespace":str(namespace)})
|
||||||
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
# Register your models here.
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
from django.apps import AppConfig
|
|
||||||
from django.http import HttpResponse
|
|
||||||
from django.shortcuts import render
|
|
||||||
import requests
|
|
||||||
from proxmoxer import ProxmoxAPI
|
|
||||||
import docker
|
|
||||||
|
|
||||||
class BackofficeConfig(AppConfig):
|
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
|
||||||
name = 'backoffice'
|
|
||||||
|
|
||||||
def hello(request):
|
|
||||||
return HttpResponse('<h1>Start bookstack!</h1>')
|
|
||||||
|
|
||||||
def http_call_test(request):
|
|
||||||
url = 'http://portainer.zeus.geeraert.eu/api/auth/'
|
|
||||||
myobj = {'Username': 'admin','Password':'Xtm78*CX3mJ54g'}
|
|
||||||
|
|
||||||
x = requests.post(url, json = myobj)
|
|
||||||
|
|
||||||
print(x.text)
|
|
||||||
return HttpResponse(x.text)
|
|
||||||
|
|
||||||
def proxmox(request):
|
|
||||||
proxmox = ProxmoxAPI("proxmox.zeus.geeraert.eu", user="root@pam", password="dinner_sl@v3", verify_ssl=False)
|
|
||||||
return HttpResponse(proxmox)
|
|
||||||
|
|
||||||
def docker_call(request,action,id_docker):
|
|
||||||
print(action)
|
|
||||||
print(id_docker)
|
|
||||||
client = docker.from_env()
|
|
||||||
if action == "start":
|
|
||||||
print("nous allons start")
|
|
||||||
client.containers.get(id_docker).start()
|
|
||||||
if action == "stop":
|
|
||||||
print("nous allons stop")
|
|
||||||
client.containers.get(id_docker).stop()
|
|
||||||
|
|
||||||
return HttpResponse(client.containers.get(id_docker).status)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
from django.db import models
|
|
||||||
|
|
||||||
# Create your models here.
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
from django.shortcuts import render
|
|
||||||
|
|
||||||
# Create your views here.
|
|
||||||
from django.http import HttpResponse
|
|
||||||
from django.shortcuts import render
|
|
||||||
|
|
||||||
def hello(request):
|
|
||||||
return HttpResponse('<h1>Hello Django!</h1>')
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
from rest_framework.decorators import api_view, authentication_classes, permission_classes
|
||||||
|
from rest_framework.authentication import TokenAuthentication
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework import status
|
||||||
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from import_export.admin import ImportExportModelAdmin
|
|
||||||
from import_export import resources
|
from import_export import resources
|
||||||
from import_export.fields import Field
|
from import_export.fields import Field
|
||||||
from .models import JobData
|
from .models import JobData
|
||||||
from django.utils.text import Truncator
|
from django.utils.text import Truncator
|
||||||
|
from core.admin import UniversalModelAdmin
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ class JobResource(resources.ModelResource):
|
|||||||
|
|
||||||
|
|
||||||
@admin.register(JobData)
|
@admin.register(JobData)
|
||||||
class JobAdmin(ImportExportModelAdmin):
|
class JobAdmin(UniversalModelAdmin):
|
||||||
list_display = ('job_position','company','URL','status','date_saved','date_applied','type','resume','location','short_description','salary','contact','source')
|
list_display = ('job_position','company','URL','status','date_saved','date_applied','type','resume','location','short_description','salary','contact','source')
|
||||||
#fields = ['job_position','company','URL','status','date_saved','date_applied','type','resume','cover_letter','location','job_description','salary ','contact','source']
|
#fields = ['job_position','company','URL','status','date_saved','date_applied','type','resume','cover_letter','location','job_description','salary ','contact','source']
|
||||||
resource_classes = [JobResource]
|
resource_classes = [JobResource]
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ def nodes(request):
|
|||||||
'spec': {
|
'spec': {
|
||||||
|
|
||||||
'containers': [{
|
'containers': [{
|
||||||
'image': 'gitea.tryton.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
'image': 'gitea.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
||||||
# 'pod-running-timeout': '5m0s',
|
# 'pod-running-timeout': '5m0s',
|
||||||
'name': 'testpython',
|
'name': 'testpython',
|
||||||
'env': [
|
'env': [
|
||||||
@@ -96,7 +96,7 @@ def backup_job(request):
|
|||||||
'spec': {
|
'spec': {
|
||||||
|
|
||||||
'containers': [{
|
'containers': [{
|
||||||
'image': 'gitea.tryton.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
'image': 'gitea.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
||||||
'name': 'testpython',
|
'name': 'testpython',
|
||||||
'command': ['/bin/sh -c /config/export_bitwarden.sh'],
|
'command': ['/bin/sh -c /config/export_bitwarden.sh'],
|
||||||
'env': [
|
'env': [
|
||||||
@@ -124,8 +124,8 @@ def backup_job_yaml(request,sync_target):
|
|||||||
v1 = client.BatchV1Api()
|
v1 = client.BatchV1Api()
|
||||||
|
|
||||||
yaml_location = {
|
yaml_location = {
|
||||||
"synology" : "https://gitea.tryton.geeraert.eu/pi-ux-ce/Backup_kube/raw/branch/main/Infrequent_access/synology_pod.yaml",
|
"synology" : "https://gitea.geeraert.eu/pi-ux-ce/Backup_kube/raw/branch/main/Infrequent_access/synology_pod.yaml",
|
||||||
"openmediavault":"https://gitea.tryton.geeraert.eu/pi-ux-ce/Backup_kube/raw/branch/main/Infrequent_access/openmediavault_pod.yaml"
|
"openmediavault":"https://gitea.geeraert.eu/pi-ux-ce/Backup_kube/raw/branch/main/Infrequent_access/openmediavault_pod.yaml"
|
||||||
}
|
}
|
||||||
print(yaml_location[sync_target])
|
print(yaml_location[sync_target])
|
||||||
url_to_select=yaml_location[sync_target]
|
url_to_select=yaml_location[sync_target]
|
||||||
|
|||||||
@@ -32,27 +32,27 @@ def import_Deployments():
|
|||||||
test.items[2].spec.template.spec.containers[0].name # name the third deploy within the namespace
|
test.items[2].spec.template.spec.containers[0].name # name the third deploy within the namespace
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def get_namespace():
|
def get_namespace(verbose=False):
|
||||||
config.load_kube_config(config_file='/kubeconfig/config')
|
config.load_kube_config(config_file='/kubeconfig/config')
|
||||||
core = client.CoreV1Api()
|
core = client.CoreV1Api()
|
||||||
namespace = core.list_namespace()
|
namespace = core.list_namespace()
|
||||||
namespace_list = []
|
namespace_list = []
|
||||||
for i in range(0,len(namespace.items)):
|
for i in range(0,len(namespace.items)):
|
||||||
print(namespace.items[i].metadata.name)
|
if verbose : print(namespace.items[i].metadata.name)
|
||||||
namespace_list.append(namespace.items[i].metadata.name)
|
namespace_list.append(namespace.items[i].metadata.name)
|
||||||
return namespace_list
|
return namespace_list
|
||||||
|
|
||||||
def get_deployments():
|
def get_deployments(verbose=False):
|
||||||
config.load_kube_config(config_file='/kubeconfig/config')
|
config.load_kube_config(config_file='/kubeconfig/config')
|
||||||
api = client.AppsV1Api()
|
api = client.AppsV1Api()
|
||||||
namespaces_list = get_namespace()
|
namespaces_list = get_namespace()
|
||||||
deployments_list = []
|
deployments_list = []
|
||||||
for namespace in namespaces_list:
|
for namespace in namespaces_list:
|
||||||
print(namespace)
|
if verbose : print(namespace)
|
||||||
deployments = api.list_namespaced_deployment(namespace)
|
deployments = api.list_namespaced_deployment(namespace)
|
||||||
for deployment_index in range(0,len(deployments.items)):
|
for deployment_index in range(0,len(deployments.items)):
|
||||||
deployment = deployments.items[deployment_index].metadata.name
|
deployment = deployments.items[deployment_index].metadata.name
|
||||||
replicas = deployments.items[deployment_index].spec.replicas
|
replicas = deployments.items[deployment_index].spec.replicas
|
||||||
print(" "+str(deployment)+" -- Replicas: "+str(replicas))
|
if verbose : print(" "+str(deployment)+" -- Replicas: "+str(replicas))
|
||||||
deployments_list.append([namespace,deployment,replicas])
|
deployments_list.append([namespace,deployment,replicas])
|
||||||
return deployments_list
|
return deployments_list
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from import_export.admin import ImportExportModelAdmin
|
|
||||||
from import_export import resources
|
from import_export import resources
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
from .models import podcastData
|
from .models import podcastData
|
||||||
|
from core.admin import UniversalModelAdmin
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
@admin.register(podcastData)
|
@admin.register(podcastData)
|
||||||
class JobAdmin(ImportExportModelAdmin):
|
class PodcastAdmin(UniversalModelAdmin):
|
||||||
list_display = ('podcast_name','clickable_links','enabled')
|
list_display = ('podcast_name','clickable_links','enabled')
|
||||||
|
|
||||||
def clickable_links(self, obj):
|
link_field = 'podcast_url'
|
||||||
return format_html('<a href="{}">{}</a>', obj.podcast_url,obj.podcast_url)
|
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
from django.contrib import admin,messages
|
from django.contrib import admin,messages
|
||||||
from django.utils.translation import ngettext
|
from django.utils.translation import ngettext
|
||||||
from django.utils.html import format_html
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from djangoql.admin import DjangoQLSearchMixin
|
|
||||||
from prompt_toolkit.shortcuts import print_container
|
from prompt_toolkit.shortcuts import print_container
|
||||||
from import_export.admin import ImportExportModelAdmin
|
|
||||||
from import_export import resources
|
from import_export import resources
|
||||||
from .models import SimpsonsData,simpsons_data_object,urlData
|
from .models import SimpsonsData,urlData
|
||||||
from .utils import mark_episode_watched,unwatch_all_episodes,generate_new_urls_for_episode
|
from .utils import mark_episode_watched,unwatch_all_episodes,generate_new_urls_for_episode
|
||||||
|
from core.admin import UniversalModelAdmin
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
@@ -65,18 +63,14 @@ def generate_new_urls(modeladmin, request, queryset):
|
|||||||
|
|
||||||
|
|
||||||
@admin.register(SimpsonsData)
|
@admin.register(SimpsonsData)
|
||||||
class EpisodeAdmin(DjangoQLSearchMixin,ImportExportModelAdmin):
|
class EpisodeAdmin(UniversalModelAdmin):
|
||||||
list_display = [field.name for field in SimpsonsData._meta.fields if field.name != 'id']
|
list_display = [field.name for field in SimpsonsData._meta.fields if field.name != 'id']
|
||||||
|
list_display += ['clickable_links']
|
||||||
list_filter = ['seen','modified_at']
|
list_filter = ['seen','modified_at']
|
||||||
#list_filter = ['seen']
|
#list_filter = ['seen']
|
||||||
fields = ['season', 'episode', 'url', 'seen']
|
fields = ['season', 'episode', 'url', 'seen']
|
||||||
actions = [make_seen,make_unseen,unseen_betaserie,generate_new_urls]
|
actions = [make_seen,make_unseen,unseen_betaserie,generate_new_urls]
|
||||||
search_fields = ['season', 'episode', 'url', 'seen']
|
search_fields = ['season', 'episode', 'url', 'seen']
|
||||||
djangoql_completion_enabled_by_default = False
|
|
||||||
|
|
||||||
def clickable_links(self, obj):
|
|
||||||
return format_html('<a href="{}">{}</a>', obj.url,obj.url)
|
|
||||||
|
|
||||||
|
|
||||||
def get_queryset(self, request):
|
def get_queryset(self, request):
|
||||||
return super().get_queryset(request).using(DB)
|
return super().get_queryset(request).using(DB)
|
||||||
@@ -91,7 +85,7 @@ class EpisodeAdmin(DjangoQLSearchMixin,ImportExportModelAdmin):
|
|||||||
queryset.using(DB).delete()
|
queryset.using(DB).delete()
|
||||||
|
|
||||||
@admin.register(urlData)
|
@admin.register(urlData)
|
||||||
class urldataAdmin(ImportExportModelAdmin):
|
class urldataAdmin(UniversalModelAdmin):
|
||||||
list_display = ('url_example', 'prefix', 'infix', 'suffix','addedDate')
|
list_display = ('url_example', 'prefix', 'infix', 'suffix','addedDate')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-17 21:26
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('simpsons', '0008_alter_simpsonsdata_modified_at_alter_urldata_infix_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='simpsonsdata',
|
||||||
|
name='modified_at',
|
||||||
|
field=models.DateTimeField(default=datetime.datetime(1969, 12, 31, 23, 0, tzinfo=datetime.timezone.utc)),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,11 +1,25 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
from import_export.admin import ImportExportModelAdmin
|
|
||||||
from .models import StreamingSiteTestingData,StreamingRedirectData
|
from .models import StreamingSiteTestingData,StreamingRedirectData
|
||||||
from .utils import full_testing
|
from .utils import full_testing
|
||||||
|
from apps.website_redirection.utils import redirect_method
|
||||||
from urllib.parse import urlsplit, urlunsplit
|
from urllib.parse import urlsplit, urlunsplit
|
||||||
|
from core.admin import UniversalModelAdmin
|
||||||
|
|
||||||
|
|
||||||
|
@admin.action(description="Add this show to streaming")
|
||||||
|
def re_redirect(modeladmin, request, queryset):
|
||||||
|
output_generated = ""
|
||||||
|
for query in queryset.values():
|
||||||
|
print(query)
|
||||||
|
key = "streaming"
|
||||||
|
value = query.get('url_display')
|
||||||
|
output_generated = output_generated + redirect_method(key,value)+";"
|
||||||
|
|
||||||
|
modeladmin.message_user(
|
||||||
|
request,
|
||||||
|
output_generated
|
||||||
|
)
|
||||||
|
|
||||||
@admin.action(description="check the URLs")
|
@admin.action(description="check the URLs")
|
||||||
def check(modeladmin, request, queryset):
|
def check(modeladmin, request, queryset):
|
||||||
@@ -34,14 +48,11 @@ def urlcleaning(modeladmin, request, queryset):
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
@admin.register(StreamingSiteTestingData)
|
@admin.register(StreamingSiteTestingData)
|
||||||
class streamingAdmin(ImportExportModelAdmin):
|
class streamingAdmin(UniversalModelAdmin):
|
||||||
list_display = ['clickable_links','result_colored','newstatus']
|
list_display = ['clickable_links','result_colored','newstatus']
|
||||||
fields = ['url']
|
fields = ['url']
|
||||||
actions = [check,urlcleaning]
|
actions = [check,urlcleaning]
|
||||||
|
|
||||||
def clickable_links(self, obj):
|
|
||||||
return format_html('<a href="{}">{}</a>', obj.url,obj.url)
|
|
||||||
|
|
||||||
def result_colored(self, obj):
|
def result_colored(self, obj):
|
||||||
colors = {
|
colors = {
|
||||||
'REACHABLE': 'green',
|
'REACHABLE': 'green',
|
||||||
@@ -60,9 +71,12 @@ class streamingAdmin(ImportExportModelAdmin):
|
|||||||
#return obj.status
|
#return obj.status
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(StreamingRedirectData)
|
@admin.register(StreamingRedirectData)
|
||||||
class StreamingRedirectAdmin(ImportExportModelAdmin):
|
class StreamingRedirectAdmin(UniversalModelAdmin):
|
||||||
list_display = ['name','season','episode','randomViewing','clickable_links','addedDate','alias']
|
list_display = ['name','image_tag','season','episode','randomViewing','clickable_links','addedDate','alias']
|
||||||
|
actions = [re_redirect]
|
||||||
|
|
||||||
#fields = ['name','season','episode','url_example','prefix','infix','suffix','alias','randomViewing','seasonInformation']
|
#fields = ['name','season','episode','url_example','prefix','infix','suffix','alias','randomViewing','seasonInformation']
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(
|
(
|
||||||
@@ -77,8 +91,10 @@ class StreamingRedirectAdmin(ImportExportModelAdmin):
|
|||||||
(
|
(
|
||||||
'Information', {
|
'Information', {
|
||||||
"classes": ["collapse"],
|
"classes": ["collapse"],
|
||||||
'fields': ('seasonInformation','alias','betaserieShowId','maximumNumberSeason')
|
'fields': ('seasonInformation','alias','betaserieShowId','maximumNumberSeason','poster_url')
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
def clickable_links(self, obj):
|
link_field = 'url_display'
|
||||||
return format_html('<a href="{}">{}</a>', obj.url_display,obj.url_display)
|
|
||||||
|
def image_tag(self,obj):
|
||||||
|
return format_html('<img src="{0}" style="width: 355px; height:200px;" />'.format(obj.poster_url))
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.30 on 2026-09-17 21:26
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('streaming', '0014_remove_streamingredirectdata_url_example_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='streamingredirectdata',
|
||||||
|
name='poster_url',
|
||||||
|
field=models.CharField(blank=True, help_text='poster URL', max_length=1000, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -21,7 +21,7 @@ class StreamingRedirectData(models.Model):
|
|||||||
name = models.CharField(primary_key=True,max_length=1000, help_text="Name of the show")
|
name = models.CharField(primary_key=True,max_length=1000, help_text="Name of the show")
|
||||||
season = models.IntegerField(null=False,default=1)
|
season = models.IntegerField(null=False,default=1)
|
||||||
episode = models.IntegerField(null=False,default=0)
|
episode = models.IntegerField(null=False,default=0)
|
||||||
url_display = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5",blank=True, null=True)
|
url_display = models.CharField(max_length=1000, help_text="https://streaming.geeraert.eu/office",blank=True, null=True)
|
||||||
prefix = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=",blank=True, null=True)
|
prefix = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=",blank=True, null=True)
|
||||||
infix = models.CharField(max_length=1000, help_text="&episode=",blank=True, null=True)
|
infix = models.CharField(max_length=1000, help_text="&episode=",blank=True, null=True)
|
||||||
suffix = models.CharField(max_length=1000, help_text="" ,blank=True, null=True)
|
suffix = models.CharField(max_length=1000, help_text="" ,blank=True, null=True)
|
||||||
@@ -31,28 +31,27 @@ class StreamingRedirectData(models.Model):
|
|||||||
betaserieShowId = models.IntegerField(null=True,blank=True)
|
betaserieShowId = models.IntegerField(null=True,blank=True)
|
||||||
maximumNumberSeason = models.IntegerField(null=True,blank=True)
|
maximumNumberSeason = models.IntegerField(null=True,blank=True)
|
||||||
randomViewing = models.BooleanField(default=False)
|
randomViewing = models.BooleanField(default=False)
|
||||||
|
poster_url = models.CharField(max_length=1000, help_text="poster URL",blank=True, null=True)
|
||||||
|
|
||||||
def sanitize(self, name):
|
def sanitize(self, name):
|
||||||
return name.replace(" ", "")
|
return name.replace(" ", "").lower()
|
||||||
|
|
||||||
def season_information(self, serie_name):
|
def season_information(self, serie_name):
|
||||||
betaserie = betaserieUtils()
|
betaserie = betaserieUtils()
|
||||||
print(serie_name)
|
|
||||||
print(betaserie.identify_serie(serie_name,True))
|
|
||||||
return betaserie.series_information(betaserie.identify_serie(serie_name))[0]
|
return betaserie.series_information(betaserie.identify_serie(serie_name))[0]
|
||||||
|
|
||||||
def maximum_Number_Season(self, serie_name):
|
def maximum_Number_Season(self, serie_name):
|
||||||
betaserie = betaserieUtils()
|
betaserie = betaserieUtils()
|
||||||
print(serie_name)
|
|
||||||
print(betaserie.identify_serie(serie_name))
|
|
||||||
return betaserie.series_information(betaserie.identify_serie(serie_name))[1]
|
return betaserie.series_information(betaserie.identify_serie(serie_name))[1]
|
||||||
|
|
||||||
def betaserie_show_id(self,serie_name):
|
def betaserie_show_id(self,serie_name):
|
||||||
betaserie = betaserieUtils()
|
betaserie = betaserieUtils()
|
||||||
print(serie_name)
|
|
||||||
print(betaserie.identify_serie(serie_name))
|
|
||||||
return betaserie.identify_serie(serie_name)
|
return betaserie.identify_serie(serie_name)
|
||||||
|
|
||||||
|
def betaserie_poster_url(self,serie_name):
|
||||||
|
betaserie = betaserieUtils()
|
||||||
|
return betaserie.poster_serie(serie_name)
|
||||||
|
|
||||||
def url_display_set(self,alias):
|
def url_display_set(self,alias):
|
||||||
if ENVIRONMENT == "PRODUCTION":
|
if ENVIRONMENT == "PRODUCTION":
|
||||||
url = "https://streaming.geeraert.eu/"
|
url = "https://streaming.geeraert.eu/"
|
||||||
@@ -73,6 +72,8 @@ class StreamingRedirectData(models.Model):
|
|||||||
self.maximumNumberSeason = self.maximum_Number_Season(self.name)
|
self.maximumNumberSeason = self.maximum_Number_Season(self.name)
|
||||||
if not self.url_display:
|
if not self.url_display:
|
||||||
self.url_display = self.url_display_set(self.alias)
|
self.url_display = self.url_display_set(self.alias)
|
||||||
|
if not self.poster_url:
|
||||||
|
self.poster_url = self.betaserie_poster_url(self.name)
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ def hello(request):
|
|||||||
|
|
||||||
|
|
||||||
def streamingRedirect(request,alias):
|
def streamingRedirect(request,alias):
|
||||||
|
#sanitize
|
||||||
|
alias = alias.lower()
|
||||||
|
|
||||||
streaming_object = StreamingRedirectData.objects.filter(alias=alias)
|
streaming_object = StreamingRedirectData.objects.filter(alias=alias)
|
||||||
|
|
||||||
episode = streaming_object.values('episode')[0]['episode']
|
episode = streaming_object.values('episode')[0]['episode']
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from import_export.admin import ImportExportModelAdmin
|
|
||||||
from .models import TelegramData
|
from .models import TelegramData
|
||||||
from .utils import telegramUtils
|
from .utils import telegramUtils
|
||||||
|
from core.admin import UniversalModelAdmin
|
||||||
|
|
||||||
@admin.action(description="Clear all expired messages")
|
@admin.action(description="Clear all expired messages")
|
||||||
def messages_cleaning(modeladmin, request, queryset):
|
def messages_cleaning(modeladmin, request, queryset):
|
||||||
@@ -10,7 +10,7 @@ def messages_cleaning(modeladmin, request, queryset):
|
|||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
@admin.register(TelegramData)
|
@admin.register(TelegramData)
|
||||||
class JobAdmin(ImportExportModelAdmin):
|
class JobAdmin(UniversalModelAdmin):
|
||||||
list_display = ('message_id','chat_id','description','creation_date','expiration_date')
|
list_display = ('message_id','chat_id','description','creation_date','expiration_date')
|
||||||
actions = [messages_cleaning]
|
actions = [messages_cleaning]
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import historicalData,redirectData
|
from .models import historicalData,redirectData
|
||||||
from .utils import redirect_method
|
from .utils import redirect_method
|
||||||
from import_export.admin import ImportExportModelAdmin
|
from core.admin import UniversalModelAdmin
|
||||||
from django.utils.html import format_html
|
|
||||||
|
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
@@ -21,16 +19,13 @@ def re_redirect(modeladmin, request, queryset):
|
|||||||
output_generated
|
output_generated
|
||||||
)
|
)
|
||||||
@admin.register(historicalData)
|
@admin.register(historicalData)
|
||||||
class historicalAdmin(ImportExportModelAdmin):
|
class historicalAdmin(UniversalModelAdmin):
|
||||||
list_input = (field.name for field in historicalData._meta.fields if field.name != 'id' or field.name != 'url')
|
list_input = (field.name for field in historicalData._meta.fields if field.name != 'id' or field.name != 'url')
|
||||||
list_display = ["clickable_links"]
|
list_display = ["clickable_links"]
|
||||||
list_display.extend(list_input)
|
list_display.extend(list_input)
|
||||||
actions = [re_redirect]
|
actions = [re_redirect]
|
||||||
|
|
||||||
|
|
||||||
def clickable_links(self, obj):
|
|
||||||
return format_html('<a href="{}">{}</a>', obj.url,obj.url)
|
|
||||||
|
|
||||||
@admin.register(redirectData)
|
@admin.register(redirectData)
|
||||||
class redirectAdmin(ImportExportModelAdmin):
|
class redirectAdmin(UniversalModelAdmin):
|
||||||
list_display = [field.name for field in redirectData._meta.fields if field.name != 'id']
|
list_display = [field.name for field in redirectData._meta.fields if field.name != 'id']
|
||||||
|
list_display += ['clickable_links']
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import redis
|
#import redis
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.utils.html import format_html
|
|
||||||
|
|
||||||
class historicalData(models.Model):
|
class historicalData(models.Model):
|
||||||
url = models.CharField(max_length=1000)
|
url = models.CharField(max_length=1000)
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
from import_export.admin import ImportExportModelAdmin
|
||||||
|
from admin_extra_buttons.api import ExtraButtonsMixin
|
||||||
|
from django.contrib import admin
|
||||||
|
from djangoql.admin import DjangoQLSearchMixin
|
||||||
|
from django.utils.html import format_html
|
||||||
|
|
||||||
|
class UniversalModelAdmin(DjangoQLSearchMixin,ImportExportModelAdmin,ExtraButtonsMixin,admin.ModelAdmin):
|
||||||
|
djangoql_completion_enabled_by_default = True
|
||||||
|
|
||||||
|
#Add search fields if you want to have the toggle on/off
|
||||||
|
# example:
|
||||||
|
# search_fields = ['season', 'episode', 'url', 'seen']
|
||||||
|
|
||||||
|
link_field = 'url'
|
||||||
|
|
||||||
|
|
||||||
|
def clickable_links(self, obj):
|
||||||
|
url = getattr(obj, self.link_field, None)
|
||||||
|
return format_html('<a href="{}">{}</a>', url,url)
|
||||||
|
|
||||||
@@ -53,6 +53,10 @@ INSTALLED_APPS = [
|
|||||||
'apps.streaming.apps.StreamingConfig',
|
'apps.streaming.apps.StreamingConfig',
|
||||||
'import_export',
|
'import_export',
|
||||||
'djangoql',
|
'djangoql',
|
||||||
|
'admin_extra_buttons',
|
||||||
|
'rest_framework',
|
||||||
|
'rest_framework.authtoken',
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
@@ -198,7 +202,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'en-us'
|
||||||
|
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'Europe/London'
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
@@ -251,3 +255,4 @@ PROXIES = {
|
|||||||
"http" : PROXY_URL,
|
"http" : PROXY_URL,
|
||||||
"https" : PROXY_URL
|
"https" : PROXY_URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -1,7 +1,7 @@
|
|||||||
FROM python:3.12
|
FROM python:3.12
|
||||||
|
|
||||||
ENV PYTHONUNBUFFERED 1
|
ENV PYTHONUNBUFFERED 1
|
||||||
#ENV ALLOWED_HOSTS 'django.tryton.geeraert.eu'
|
#ENV ALLOWED_HOSTS 'django.geeraert.eu'
|
||||||
#ENV DEBUG 'True'
|
#ENV DEBUG 'True'
|
||||||
|
|
||||||
ARG ALLOWED_HOSTS
|
ARG ALLOWED_HOSTS
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ FROM python:3.12
|
|||||||
MAINTAINER pi-ux-ce
|
MAINTAINER pi-ux-ce
|
||||||
|
|
||||||
ENV PYTHONUNBUFFERED 1
|
ENV PYTHONUNBUFFERED 1
|
||||||
ENV ALLOWED_HOSTS 'django-testing.tryton.geeraert.eu'
|
ENV ALLOWED_HOSTS 'django-testing.geeraert.eu'
|
||||||
ENV DEBUG 'True'
|
ENV DEBUG 'True'
|
||||||
|
|
||||||
WORKDIR /code/
|
WORKDIR /code/
|
||||||
@@ -20,7 +20,7 @@ RUN apt-get update && \
|
|||||||
# image silently keeps stale code.
|
# image silently keeps stale code.
|
||||||
ARG CACHE_BUST=1
|
ARG CACHE_BUST=1
|
||||||
RUN echo "cache bust: ${CACHE_BUST}" && \
|
RUN echo "cache bust: ${CACHE_BUST}" && \
|
||||||
git clone --depth 1 -b testing https://gitea.tryton.geeraert.eu/pi-ux-ce/Django_kube.git .
|
git clone --depth 1 -b testing https://gitea.geeraert.eu/pi-ux-ce/Django_kube.git .
|
||||||
|
|
||||||
RUN pip install --cache-dir=/opt/hostedtoolcache/pip --upgrade pip
|
RUN pip install --cache-dir=/opt/hostedtoolcache/pip --upgrade pip
|
||||||
RUN pip list --cache-dir=/opt/hostedtoolcache/pip --outdated
|
RUN pip list --cache-dir=/opt/hostedtoolcache/pip --outdated
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,5 @@
|
|||||||
django
|
django
|
||||||
psycopg2
|
psycopg2
|
||||||
#xrequests
|
|
||||||
kubernetes
|
kubernetes
|
||||||
ruamel.yaml
|
ruamel.yaml
|
||||||
pyyaml
|
pyyaml
|
||||||
@@ -17,3 +16,5 @@ bitwarden_sdk
|
|||||||
xmltodict
|
xmltodict
|
||||||
whitenoise
|
whitenoise
|
||||||
djangoql
|
djangoql
|
||||||
|
django-admin-extra-buttons
|
||||||
|
djangorestframework
|
||||||
|
|||||||
Reference in New Issue
Block a user