docker - kinda works
This commit is contained in:
parent
e8b9824873
commit
e1441af9a3
@ -1,5 +1,4 @@
|
|||||||
import docker
|
import docker
|
||||||
from models import Profile
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from DockerManager import DockerManager
|
from .DockerManager import DockerManager
|
||||||
from models import Profile, Session
|
from .models import Profile, Session
|
||||||
from django.contrib.auth.signals import user_logged_in, user_logged_out
|
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)
|
@receiver(user_logged_in)
|
||||||
def profile_start_up(sender, instance, request, **kwargs):
|
def profile_start_up(sender, user, request, **kwargs):
|
||||||
if instance.session is None:
|
try:
|
||||||
|
user.session
|
||||||
|
|
||||||
|
except Profile.session.RelatedObjectDoesNotExist:
|
||||||
# Create session
|
# Create session
|
||||||
session = Session()
|
session = Session()
|
||||||
session.user = instance
|
session.user = user
|
||||||
session.sessionid = request.COOKIE.get('sessionid')
|
session.sessionid = request.COOKIES.get('sessionid')
|
||||||
# TODO metoda wybierania portów
|
# TODO metoda wybierania portów
|
||||||
port = 6969
|
port = 6969
|
||||||
session.port = port
|
session.port = port
|
||||||
|
|
||||||
# Create container
|
# Create container
|
||||||
docker_manager = DockerManager()
|
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.container_id = container_id
|
||||||
session.save()
|
session.save()
|
||||||
|
|
||||||
|
|
||||||
@receiver(user_logged_out)
|
@receiver(user_logged_out)
|
||||||
def profile_logged_out(sender, instance, request, **kwargs):
|
def profile_logged_out(sender, user, request, **kwargs):
|
||||||
# Obtaining container_id
|
# Obtaining container_id
|
||||||
session = Session.objects.get(id=instance.user_id)
|
session = Session.objects.get(id=user.user_id)
|
||||||
container_id = session.container_id
|
container_id = session.container_id
|
||||||
|
|
||||||
# Turn off and delete container
|
# Turn off and delete container
|
||||||
|
Loading…
Reference in New Issue
Block a user