views to add or delete ingress for terraform
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
This commit is contained in:
@@ -2,10 +2,12 @@ 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
|
||||
|
||||
from .utils import import_namespace,retrieve_and_apply
|
||||
from apps.kubernetes_connection.utils import scale_up,scale_down
|
||||
from .models import Deployment_Data
|
||||
from .models import Deployment_Data,Ingress_Data
|
||||
|
||||
def hello(request):
|
||||
list_schedule = ['schedule1','schedule2']
|
||||
@@ -32,3 +34,37 @@ def scale_down_gui(request,namespace_name,deploy_name):
|
||||
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'})
|
||||
|
||||
@csrf_exempt
|
||||
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)})
|
||||
|
||||
@csrf_exempt
|
||||
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)})
|
||||
|
||||
Reference in New Issue
Block a user