decorator container start-up
This commit is contained in:
parent
f87290b6b5
commit
341339ca8b
@ -1,7 +1,8 @@
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from DockerManager import DockerManager
|
||||
from models import Profile
|
||||
from models import Profile, Session
|
||||
from django.contrib.auth.signals import user_logged_in
|
||||
|
||||
|
||||
@receiver(post_save, sender=Profile)
|
||||
@ -15,4 +16,21 @@ def profile_saved(sender, instance, **kwargs):
|
||||
instance.save()
|
||||
|
||||
|
||||
@receiver(user_logged_in)
|
||||
def profile_start_up(sender, instance, request, **kwargs):
|
||||
if instance.session is None:
|
||||
# Create session
|
||||
session = Session()
|
||||
session.user = instance
|
||||
session.sessionid = request.COOKIE.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)
|
||||
session.container_id = container_id
|
||||
session.save()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user