profile + docker class

This commit is contained in:
makram89 2022-01-27 21:15:13 +01:00
parent 4dddb42eaa
commit 0229e8fff7
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