profile + docker class
This commit is contained in:
parent
4dddb42eaa
commit
0229e8fff7
25
MUOR/MUOR/DockerManager.py
Normal file
25
MUOR/MUOR/DockerManager.py
Normal 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
|
@ -5,3 +5,14 @@ from django.db import models
|
|||||||
class Session(models.Model):
|
class Session(models.Model):
|
||||||
user = models.ForeignKey(User, primary_key=True, on_delete=models.CASCADE)
|
user = models.ForeignKey(User, primary_key=True, on_delete=models.CASCADE)
|
||||||
port = models.PositiveIntegerField(null=False, unique=True)
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
4
MUOR/docker_deamon_run.py
Normal file
4
MUOR/docker_deamon_run.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import docker
|
||||||
|
|
||||||
|
|
||||||
|
client = docker.from_env()
|
@ -1,2 +1,3 @@
|
|||||||
Django
|
Django
|
||||||
django-crispy-forms
|
django-crispy-forms
|
||||||
|
docker
|
Loading…
Reference in New Issue
Block a user