Compare commits
4
Commits
a4a704305a
...
83e2ba5be2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83e2ba5be2 | ||
|
|
7cc8891533 | ||
|
|
8a0cd24d69 | ||
|
|
1cb49c3127 |
@@ -20,8 +20,7 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: django-python
|
- name: django-python
|
||||||
# image: localhost:31795/django-python
|
image: gitea.tryton.geeraert.eu/pi-ux-ce/django-python:latest
|
||||||
image: gitea.tryton.geeraert.eu/pi-ux-ce/django-python:1.0.0
|
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8000
|
- containerPort: 8000
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -121,3 +121,4 @@ STATIC_URL = 'static/'
|
|||||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
#
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ from random_simpsons import apps as random_simpsons
|
|||||||
from paperless_django import apps as paperless_django
|
from paperless_django import apps as paperless_django
|
||||||
from onenote import apps as onenote
|
from onenote import apps as onenote
|
||||||
from dashboard import apps as dashboard
|
from dashboard import apps as dashboard
|
||||||
|
from kubernetes_connection import apps as kubernetes_connection
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# path('admin/', admin.site.urls),
|
# path('admin/', admin.site.urls),
|
||||||
@@ -41,6 +42,12 @@ urlpatterns = [
|
|||||||
path('dashboard/hello/', dashboard.hello),
|
path('dashboard/hello/', dashboard.hello),
|
||||||
|
|
||||||
|
|
||||||
|
################## kubernetes_connection#####
|
||||||
|
path('kubernetes_connection/hello/', kubernetes_connection.hello),
|
||||||
|
path('kubernetes_connection/nodes/', kubernetes_connection.nodes),
|
||||||
|
path('kubernetes_connection/backup_job/', kubernetes_connection.backup_job),
|
||||||
|
path('kubernetes_connection/backup_job_yaml/', kubernetes_connection.backup_job_yaml),
|
||||||
|
|
||||||
# path('bookstack/', docker_connection.apps.hello),
|
# path('bookstack/', docker_connection.apps.hello),
|
||||||
# path('test/', docker_connection.apps.http_call_test),
|
# path('test/', docker_connection.apps.http_call_test),
|
||||||
# path('proxmox/', docker_connection.apps.proxmox),
|
# path('proxmox/', docker_connection.apps.proxmox),
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from django.shortcuts import render
|
||||||
|
from django.shortcuts import redirect
|
||||||
|
|
||||||
|
from django.core.files import File
|
||||||
|
from kubernetes import client, config
|
||||||
|
|
||||||
|
#from django.template.loader import render_to_string
|
||||||
|
import time
|
||||||
|
import random
|
||||||
|
import mimetypes
|
||||||
|
import ruamel.yaml
|
||||||
|
import yaml
|
||||||
|
def hello(request):
|
||||||
|
return HttpResponse('<h1>Hello k8s!</h1>')
|
||||||
|
|
||||||
|
|
||||||
|
def nodes(request):
|
||||||
|
config.load_kube_config(config_file='/code/kubeconfig')
|
||||||
|
v1 = client.CoreV1Api()
|
||||||
|
# v1.list_node()
|
||||||
|
pod_manifest = {
|
||||||
|
'apiVersion': 'v1',
|
||||||
|
'kind': 'Pod',
|
||||||
|
'metadata': {
|
||||||
|
'labels': {
|
||||||
|
'bot': 'current-bot'
|
||||||
|
},
|
||||||
|
'name': 'podname',
|
||||||
|
'namespace': 'echo-server'
|
||||||
|
|
||||||
|
},
|
||||||
|
'spec': {
|
||||||
|
|
||||||
|
'containers': [{
|
||||||
|
'image': 'gitea.tryton.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
||||||
|
# 'pod-running-timeout': '5m0s',
|
||||||
|
'name': 'testpython',
|
||||||
|
'env': [
|
||||||
|
{'name': 'env_variable', 'value': 'env_value'},
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
'restartPolicy': 'Always',
|
||||||
|
# 'serviceAccountName': 'bots-service-account'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# print(f'POD MANIFEST:\n{pod_manifest}')
|
||||||
|
api_response = v1.create_namespaced_pod(body=pod_manifest,namespace='echo-server')
|
||||||
|
return HttpResponse(api_response)
|
||||||
|
|
||||||
|
def backup_job(request):
|
||||||
|
config.load_kube_config(config_file='/code/kubeconfig')
|
||||||
|
v1 = client.CoreV1Api()
|
||||||
|
#v1 = client.BatchV1Api()
|
||||||
|
# v1.list_node()
|
||||||
|
pod_manifest_job = {
|
||||||
|
'apiVersion': 'batch/v1',
|
||||||
|
'kind': 'Job',
|
||||||
|
'metadata': {
|
||||||
|
'name': 'bitwarden-backup-django',
|
||||||
|
'namespace': 'bwbackup'
|
||||||
|
|
||||||
|
},
|
||||||
|
'spec': {
|
||||||
|
'template': {
|
||||||
|
'spec': {
|
||||||
|
|
||||||
|
'containers': [{
|
||||||
|
'image': 'gitea.tryton.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
||||||
|
'name': 'testpython',
|
||||||
|
'command': ['/bin/sh -c /config/export_bitwarden.sh'],
|
||||||
|
'env': [
|
||||||
|
{'name': 'env_variable', 'value': 'env_value'},
|
||||||
|
],
|
||||||
|
'volumeMounts': [
|
||||||
|
{'name': 'scripts', 'configMap': [{'name':'bitwarden-export-scripts'},]},
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
'restartPolicy': 'Always',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
api_response = v1.create_namespaced_job(body=pod_manifest_job)
|
||||||
|
return HttpResponse(api_response)
|
||||||
|
|
||||||
|
|
||||||
|
#help with yaml import
|
||||||
|
#https://github.com/kubernetes-client/python/issues/589
|
||||||
|
|
||||||
|
def backup_job_yaml(request):
|
||||||
|
config.load_kube_config(config_file='/code/kubeconfig')
|
||||||
|
# v1 = client.CoreV1Api()
|
||||||
|
v1 = client.BatchV1Api()
|
||||||
|
|
||||||
|
# v1.list_node()
|
||||||
|
# pod_manifest_job = {
|
||||||
|
|
||||||
|
with open('/code/pod.yaml') as fo:
|
||||||
|
# yaml = YAML(typ='rt')
|
||||||
|
#yaml.load(...)
|
||||||
|
|
||||||
|
# job = ruamel.yaml.load(fo)
|
||||||
|
job = yaml.safe_load(fo)
|
||||||
|
|
||||||
|
v1.create_namespaced_job(
|
||||||
|
job['metadata']['namespace'], job, pretty=True
|
||||||
|
|
||||||
|
# _request_timeout=(settings.CONNECTION_TIMEOUT_SECONDS, settings.READ_TIMEOUT_SECONDS
|
||||||
|
|
||||||
|
)
|
||||||
|
return HttpResponse(job['metadata']['namespace'])
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<h1>Hello template!</h1>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
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>')
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user