docker - kinda works

This commit is contained in:
makram89 2022-01-28 00:00:44 +01:00
parent e8b9824873
commit e1441af9a3
2 changed files with 12 additions and 10 deletions

View File

@ -1,5 +1,4 @@
import docker
from models import Profile
import hashlib

View File

@ -1,7 +1,7 @@
from django.db.models.signals import post_save
from django.dispatch import receiver
from DockerManager import DockerManager
from models import Profile, Session
from .DockerManager import DockerManager
from .models import Profile, Session
from django.contrib.auth.signals import user_logged_in, user_logged_out
@ -17,27 +17,30 @@ def profile_saved(sender, instance, **kwargs):
@receiver(user_logged_in)
def profile_start_up(sender, instance, request, **kwargs):
if instance.session is None:
def profile_start_up(sender, user, request, **kwargs):
try:
user.session
except Profile.session.RelatedObjectDoesNotExist:
# Create session
session = Session()
session.user = instance
session.sessionid = request.COOKIE.get('sessionid')
session.user = user
session.sessionid = request.COOKIES.get('sessionid')
# TODO metoda wybierania portów
port = 6969
session.port = port
# Create container
docker_manager = DockerManager()
container_id = docker_manager.turn_on_container(instance.volume, port)
container_id = docker_manager.turn_on_container(user.volume, port)
session.container_id = container_id
session.save()
@receiver(user_logged_out)
def profile_logged_out(sender, instance, request, **kwargs):
def profile_logged_out(sender, user, request, **kwargs):
# Obtaining container_id
session = Session.objects.get(id=instance.user_id)
session = Session.objects.get(id=user.user_id)
container_id = session.container_id
# Turn off and delete container