docker - kinda works
This commit is contained in:
parent
e8b9824873
commit
e1441af9a3
@ -1,5 +1,4 @@
|
||||
import docker
|
||||
from models import Profile
|
||||
import hashlib
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user