Commit 65ada8e0 authored by Stefano Alberto Russo's avatar Stefano Alberto Russo
Browse files

Added the Container object including adding custom containers, and prepared...

Added the Container object including adding custom containers, and prepared for the Compute object. Partially refactored the task view. Minor fixes.
parent 681b1942
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
from django.contrib import admin

from .models import Profile, LoginToken, Task
from .models import Profile, LoginToken, Task, Container

admin.site.register(Profile)
admin.site.register(LoginToken)
admin.site.register(Task)
admin.site.register(Container)
+39 −3
Original line number Diff line number Diff line
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from ...models import Profile
from ...models import Profile, Container

class Command(BaseCommand):
    help = 'Adds the admin superuser with \'a\' password.'

    def handle(self, *args, **options):

        # Admin
        try:
            User.objects.get(username='admin')
            print('Not creating admin user as it already exist')
@@ -15,6 +16,7 @@ class Command(BaseCommand):
            admin = User.objects.create_superuser('admin', 'admin@example.com', 'admin')
            Profile.objects.create(user=admin)
        
        # Testuser
        try:
            User.objects.get(username='testuser')
            print('Not creating test user as it already exist')
@@ -23,3 +25,37 @@ class Command(BaseCommand):
            testuser = User.objects.create_user('testuser', 'testuser@rosetta.platform', 'testpass')
            Profile.objects.create(user=testuser, authtoken='129aac94-284a-4476-953c-ffa4349b4a50')

        # public containers
        public_containers = Container.objects.filter(user=None)
        if public_containers:
            print('Not creating public containers as they already exist')
        else:
            print('Creating public containers...')
            
            # MetaDesktop Docker
            Container.objects.create(user          = None,
                                     image         = 'rosetta/metadesktop',
                                     type          = 'docker',
                                     registry      = 'docker_local',
                                     service_ports = '8590')

            # Astrocook
            Container.objects.create(user          = None,
                                     image         = 'sarusso/astrocook:b2b819e',
                                     type          = 'docker',
                                     registry      = 'docker_local',
                                     service_ports = '8590')













+17 −1
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ class Task(models.Model):
    tid       = models.CharField('Task ID', max_length=64, blank=False, null=False)
    uuid      = models.CharField('Task UUID', max_length=36, blank=False, null=False)
    name      = models.CharField('Task name', max_length=36, blank=False, null=False)
    container = models.CharField('Task container', max_length=36, blank=False, null=False)
    status    = models.CharField('Task status', max_length=36, blank=True, null=True)
    created   = models.DateTimeField('Created on', default=timezone.now)
    compute   = models.CharField('Task compute', max_length=36, blank=True, null=True)
@@ -64,6 +63,9 @@ class Task(models.Model):
    ip        = models.CharField('Task ip address', max_length=36, blank=True, null=True)
    tunnel_port = models.IntegerField('Task tunnel port', blank=True, null=True)

    # Links
    container    = models.ForeignKey('Container', on_delete=models.CASCADE, related_name='+')

    def save(self, *args, **kwargs):
        
        try:
@@ -106,7 +108,21 @@ class Task(models.Model):
        return self.uuid.split('-')[0]


#=========================
#  Containers
#=========================
class Container(models.Model):

    #uuid           = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    user           = models.ForeignKey(User, related_name='+', on_delete=models.CASCADE, null=True)
    # If a container has no user, it will be available to anyone. Can be created, edited and deleted only by admins.
    image         = models.CharField('Container image', max_length=255, blank=False, null=False)
    type          = models.CharField('Container type', max_length=36, blank=False, null=False)
    registry      = models.CharField('Container registry', max_length=255, blank=False, null=False)
    service_ports = models.CharField('Container service ports', max_length=36, blank=True, null=True)
    #private       = models.BooleanField('Container is private and needs auth to be pulled from the registry')

    def __str__(self):
        return str('Container of type "{}" with image "{}" from registry "{}" of user "{}"'.format(self.type, self.image, self.registry, self.user))

+103 −0
Original line number Diff line number Diff line
{% load static %} 
{% include "header.html" %}
{% include "navigation.html" with main_path='/main/' %}

<br/>
<br/>

<div class="container">
  <div class="dashboard">
    <div class="span8 offset2">
      <h1>Add container</h1> 
      <hr>

      {% if not data.added %}

          <h3>Configure the new container.</h3> 
          
          <br/>
          
          <form action="#" method="POST">
          {% csrf_token %}

          <table class="dashboard" style="max-width:430px">
    
           <tr>
            <td><b>Type</b></td><td>
              <select name="container_type" >
              <option value="docker" selected>Docker</option>
              <option value="singularity">Singularity</option>
              </select>
            </td>
           </tr>

           <tr>
            <td><b>Registry</b></td><td>
              <select name="container_registry" >
              <option value="docker_local" selected>Local</option>
              <option value="docker_hub">Docker Hub</option>
              <option value="singularityhub">Singularity Hub</option>
              </select>
            </td>
           </tr>

           <tr>
            <td><b>Container image</b></td>
            <td>
             <input type="text" name="container_image" value="" placeholder="" size="23" required />
            </td>
           </tr>

           <tr>
            <td><b>Service port(s)</b></td>
            <td>
             <input type="text" name="container_service_ports" value="" placeholder="" size="5" required />
            </td>
           </tr>

           <tr>
           <td colspan=2 align=center style="padding:20px">
           <input type="submit" value="Add">
           </td>
           </tr>
          </table>
          </form>

          <br/>          
          <br/>
          <br/>
          <br/>
          <br/>
          <br/>
          <br/>
          <br/>
          <br/>
          



 
      {% else %}
        Ok, Container added. Go back to your <a href="/tasks">tasks list</a>.
        

      {% endif %} 
  
      <br/>
      <br/>
      <br/>
      <br/>
      <br/>
      <br/>
      
    </div>
  </div>
</div>

{% include "footer.html" %}





+88 −0
Original line number Diff line number Diff line
{% load static %} 
{% include "header.html" %}
{% include "navigation.html" with main_path='/main/' %}

<br/>
<br/>

<div class="container">
  <div class="dashboard">
    <div class="span8 offset2">
      <h1>Containers List</h1>
      <hr/>

             
      {% for container in data.platform_containers %}
      <table class="dashboard">

       <tr>
        <td><b>Container image</b></td>
        <td>{{ container.image }} (platform)</td>
       </tr>

       <tr>
        <td><b>Container type</b></td>
        <td>{{ container.type }}</td>
       </tr>

       <tr>
        <td><b>Container registry</b></td>
        <td>{{ container.registry }}</td>
       </tr>

       <tr>
        <td><b>Container service ports</b></td>
        <td>{{ container.service_ports}}</td>
       </tr>

      </table>
      <br />
      {% endfor %}


      {% for container in data.user_containers %}
      <table class="dashboard">

       <tr>
        <td><b>Container image</b></td>
        <td>{{ container.image }} (user)</td>
       </tr>

       <tr>
        <td><b>Container type</b></td>
        <td>{{ container.type }}</td>
       </tr>

       <tr>
        <td><b>Container registry</b></td>
        <td>{{ container.registry }}</td>
       </tr>

       <tr>
        <td><b>Container service ports</b></td>
        <td>{{ container.service_ports}}</td>
       </tr>

      </table>
      <br />
      {% endfor %}    
      
      <br />
      <a href="/create_container">Add new...</a>
      <br/>
      <br/>
      <br/>
      <br/>
      <br/>
      <br/>
      
    </div>
  </div>
</div>

{% include "footer.html" %}




Loading