50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
from django.apps import AppConfig
|
|
from django.http import HttpResponse
|
|
from django.shortcuts import render
|
|
from django.shortcuts import redirect
|
|
from jinja2 import Environment, FileSystemLoader
|
|
from django.core.files import File
|
|
from kubernetes import client, config
|
|
|
|
import time
|
|
import random
|
|
import mimetypes
|
|
import ruamel.yaml
|
|
import yaml
|
|
import urllib.request
|
|
|
|
def hello(request):
|
|
return HttpResponse('<h1>Hello stash!</h1>')
|
|
def form(request):
|
|
return render(request, 'stash_form.html',{})
|
|
|
|
def handle_survey_form(request):
|
|
config.load_kube_config(config_file='/kubeconfig/config')
|
|
v1 = client.BatchV1Api()
|
|
name = request.GET.get('name')
|
|
url = request.GET.get('url')
|
|
external_galleries = request.GET.get('external_galleries')
|
|
|
|
with open('django_code/stash_management/templates/template.stash-pornpics-dowloader.job.yml', 'r') as file:
|
|
#get the manifest in a variable template_manifest from the manifest file
|
|
template_manifest = yaml.safe_load(file)
|
|
|
|
#edit the container name
|
|
template_manifest['metadata']['name'] ="stash-pornpics-dowloader"+name
|
|
template_manifest['spec']['template']['spec']['containers'][0]['name'] ="stash-pornpics-dowloader-"+name
|
|
|
|
#edit the command based on the input
|
|
command=['bash', '/config/download.sh', '--http_proxy', 'http://gluetun-svc.gluetun.svc:8888', '--BASE_URL', url, '--pornstars', name,'--external_gallery', external_galleries]
|
|
template_manifest['spec']['template']['spec']['containers'][0]['command']=command
|
|
|
|
|
|
#execute based on the value
|
|
api_response = v1.create_namespaced_job(body=template_manifest,namespace='stash')
|
|
|
|
return HttpResponse(api_response)
|
|
|
|
|
|
|
|
|
|
|