Merge pull request 'profile + docker class' (#4) from RANDOMSEC-20 into master

Reviewed-on: #4
This commit is contained in:
Marek Kamiński 2022-01-27 21:16:10 +01:00
commit 9ed3608b9e
4 changed files with 42 additions and 1 deletions

View File

@ -0,0 +1,25 @@
import docker
from models import Profile
import hashlib
class DockerManager:
def __init__(self):
self.client = docker.from_env()
def create_new_volume(self, username):
# Hashing username to get volume name
hashed_username = hashlib.sha256(bytes(username, 'utf-8')).hexdigest()
# Creating volume in docker
volume = self.client.volumes.create(name=hashed_username, driver='local')
return hashed_username
def turn_on_container(self, volume_id):
pass
def turn_off_container(self,volume_id):
pass

View File

@ -5,3 +5,14 @@ from django.db import models
class Session(models.Model):
user = models.ForeignKey(User, primary_key=True, on_delete=models.CASCADE)
port = models.PositiveIntegerField(null=False, unique=True)
class Profile(models.Model):
user = models.ForeignKey(User, primary_key=True, on_delete=models.CASCADE)
volume = models.CharField(max_length=64)

View File

@ -0,0 +1,4 @@
import docker
client = docker.from_env()

View File

@ -1,2 +1,3 @@
Django
django-crispy-forms
django-crispy-forms
docker