Commit 2db0bd2a by Belákovics Ádám

Demo features and Pipfile update

parent 261dd9e0
...@@ -5,17 +5,16 @@ verify_ssl = true ...@@ -5,17 +5,16 @@ verify_ssl = true
[dev-packages] [dev-packages]
httpie = "*" httpie = "*"
autopep8 = "*"
django-rest-swagger = "*" django-rest-swagger = "*"
[packages] [packages]
django = "*" django = "*"
django-rest-framework = "*"
djangorestframework = "*" djangorestframework = "*"
djoser = "*" djoser = "*"
django-cors-headers = "*" django-cors-headers = "*"
openstack = "*"
openstacksdk = "*" openstacksdk = "*"
python-novaclient = "*"
keystoneauth1 = "*"
[requires] [requires]
python_version = "3.6" python_version = "3.6"
# Generated by Django 2.2.1 on 2019-05-13 12:02
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Disk',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, help_text='Name of the disk', max_length=100, verbose_name='name')),
('remote_ID', models.CharField(help_text='ID, which helps access the disk', max_length=40, unique=True, verbose_name='remote_ID')),
],
),
]
...@@ -3,7 +3,7 @@ from image.serializers import DiskSerializer ...@@ -3,7 +3,7 @@ from image.serializers import DiskSerializer
from django.shortcuts import render from django.shortcuts import render
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.response import Response from rest_framework.response import Response
from implementation.image.OpenstackImageManager import OpenstackImageManager from interface_openstack.implementation.image.OpenstackImageManager import OpenstackImageManager
import openstack import openstack
conn = openstack.connect(cloud='openstack') conn = openstack.connect(cloud='openstack')
...@@ -12,7 +12,7 @@ class DiskList(APIView): ...@@ -12,7 +12,7 @@ class DiskList(APIView):
def get(self, request, format=None): def get(self, request, format=None):
#OpenStack #OpenStack
interface = OpenstackImageManager(conn) interface = OpenstackImageManager(conn)
return Response([disk.toJSON() for disk in interface.list()]) return Response([disk.__dict__ for disk in interface.list()])
#Create response #Create response
disks = Disk.object.all() disks = Disk.object.all()
......
# Generated by Django 2.2.1 on 2019-05-13 12:02
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('instance', '0003_auto_20190510_1307'),
]
operations = [
migrations.AddField(
model_name='instance',
name='remoteId',
field=models.CharField(default=0, help_text='ID of the instance on the backend', max_length=100),
preserve_default=False,
),
]
# Generated by Django 2.2.1 on 2019-05-13 12:03
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('instance', '0004_instance_remoteid'),
]
operations = [
migrations.RenameField(
model_name='instance',
old_name='remoteId',
new_name='remote_id',
),
]
...@@ -13,6 +13,8 @@ LEASE_TYPES = tuple([(val["name"], val["verbose_name"]) ...@@ -13,6 +13,8 @@ LEASE_TYPES = tuple([(val["name"], val["verbose_name"])
class Instance(models.Model): class Instance(models.Model):
name = models.CharField(max_length=100, name = models.CharField(max_length=100,
help_text="Human readable name of instance") help_text="Human readable name of instance")
remote_id = models.CharField(max_length=100,
help_text="ID of the instance on the backend")
description = models.TextField(blank=True, description = models.TextField(blank=True,
help_text="The description of the instance") help_text="The description of the instance")
access_method = models.CharField(max_length=10, choices=ACCESS_METHODS, access_method = models.CharField(max_length=10, choices=ACCESS_METHODS,
......
...@@ -4,25 +4,7 @@ from .models import Instance ...@@ -4,25 +4,7 @@ from .models import Instance
class InstanceSerializer(serializers.ModelSerializer): class InstanceSerializer(serializers.ModelSerializer):
num_cores = serializers.SerializerMethodField(
help_text="Number of virtual CPU cores")
priority = serializers.SerializerMethodField(
help_text="CPU priority")
max_ram_size = serializers.SerializerMethodField(
help_text="Maximum RAM size")
class Meta: class Meta:
model = Instance model = Instance
fields = "__all__" fields = "__all__"
def get_num_cores(self, obj):
# get it from the cloud manager
return 4
def get_priority(self, obj):
# get it from the cloud manager
return 1
def get_max_ram_size(self, obj):
# get it from the cloud manager
return 4096
...@@ -4,9 +4,11 @@ from django.http import Http404 ...@@ -4,9 +4,11 @@ from django.http import Http404
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework import status from rest_framework import status
from implementation.vm.instance import OSVirtualMachineManager from interface_openstack.implementation.vm.instance import OSVirtualMachineManager
import openstack import openstack
import datetime
conn = openstack.connect(cloud='openstack') conn = openstack.connect(cloud='openstack')
...@@ -14,22 +16,29 @@ conn = openstack.connect(cloud='openstack') ...@@ -14,22 +16,29 @@ conn = openstack.connect(cloud='openstack')
class InstanceList(APIView): class InstanceList(APIView):
def get(self, request, format=None): def get(self, request, format=None):
instances = Instance.objects.all() instances = Instance.objects.all()
# refresh OpenStack Attribs return Response(InstanceSerializer(instances, many=True).data)
interface = OSVirtualMachineManager(conn)
return Response([vm for vm in interface.list_all_vm()])
# create response
serializer = InstanceSerializer(instances, many=True)
return Response(serializer.data)
def post(self, request, format=None): def post(self, request, format=None):
data = request.data data = request.data
newId = 0
interface = OSVirtualMachineManager(conn) interface = OSVirtualMachineManager(conn)
imageId = "da51253f-867c-472d-8ce0-81e7b7126d60" imageId = "da51253f-867c-472d-8ce0-81e7b7126d60"
flavorId = {"name": 1} flavorId = '1'
networks = [{"uuid": "c03d0d4b-413e-4cc6-9ebe-c0b5ca0dac3a"}] networks = [{"uuid": "c03d0d4b-413e-4cc6-9ebe-c0b5ca0dac3a"}]
interface.create_vm_from_template("Integration test vm 1", imageId, flavorId, networks) newBackendInstance = interface.create_vm_from_template("Integration test vm 2", imageId, flavorId, networks)
return Response(newId) newInstance = Instance(
name="Integration test",
remote_id=newBackendInstance.id,
description="Bütyök bála kapitány",
access_method="ssh",
system="cirros",
password="12345678",
lease="project",
time_of_suspend=datetime.datetime.now(),
time_of_delete=datetime.datetime.now(),
deleted=False
)
newInstance.save()
return Response(newInstance.pk)
class InstanceDetail(APIView): class InstanceDetail(APIView):
...@@ -45,8 +54,15 @@ class InstanceDetail(APIView): ...@@ -45,8 +54,15 @@ class InstanceDetail(APIView):
def get(self, request, pk, format=None): def get(self, request, pk, format=None):
instance = self.get_object(pk) instance = self.get_object(pk)
serializer = InstanceSerializer(instance) instanceDict = InstanceSerializer(instance).data
return Response(serializer.data)
interface = OSVirtualMachineManager(conn)
remoteInstance = interface.get_vm(instance.remote_id)
remoteInstanceDict = remoteInstance.__dict__
merged_dict = {**instanceDict, **remoteInstanceDict}
return Response(merged_dict)
def put(self, request, pk, format=None): def put(self, request, pk, format=None):
instance = self.get_object(pk) instance = self.get_object(pk)
......
from instance.models import Instance
from instance.serializers import InstanceSerializer
from django.http import Http404
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from implementation.vm.instance import OSVirtualMachineManager
import openstack
conn = openstack.connect(cloud='openstack')
class InstanceList(APIView):
def get(self, request, format=None):
instances = Instance.objects.all()
# refresh OpenStack Attribs
interface = OSVirtualMachineManager(conn)
return Response([vm for vm in interface.list_all_vm()])
# create response
serializer = InstanceSerializer(instances, many=True)
return Response(serializer.data)
def post(self, request, format=None):
data = request.data
newId = 0
interface = OSVirtualMachineManager(conn)
imageId = "da51253f-867c-472d-8ce0-81e7b7126d60"
flavorId = {"name": 1}
networks = [{"uuid": "c03d0d4b-413e-4cc6-9ebe-c0b5ca0dac3a"}]
interface.create_vm_from_template("Integration test vm 1", imageId, flavorId, networks)
return Response(newId)
class InstanceDetail(APIView):
"""
Retrieve, update or delete a snippet instance.
"""
def get_object(self, pk):
try:
return Instance.objects.get(pk=pk)
except Instance.DoesNotExist:
raise Http404
def get(self, request, pk, format=None):
instance = self.get_object(pk)
serializer = InstanceSerializer(instance)
return Response(serializer.data)
def put(self, request, pk, format=None):
instance = self.get_object(pk)
serializer = InstanceSerializer(instance, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def delete(self, request, pk, format=None):
instance = self.get_object(pk)
instance.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment