Commit 324b4ce8 by Karsa Zoltán István

add interface ipv4, mac, ipv6

parent 8179e8f6
...@@ -7,10 +7,15 @@ from firewall.models import Vlan ...@@ -7,10 +7,15 @@ from firewall.models import Vlan
from storage.models import Disk from storage.models import Disk
class InstanceActivitySerializer(serializers.ModelSerializer): class InstanceActivitySerializer(serializers.ModelSerializer):
get_percentage = serializers.IntegerField()
result_data = serializers.JSONField()
class Meta: class Meta:
model = InstanceActivity model = InstanceActivity
fields = ('id', 'instance', 'resultant_state', 'interruptible', 'activity_code', 'readable_name_data', 'parent', fields = ('id', 'instance', 'resultant_state', 'interruptible', 'activity_code', 'parent',
'task_uuid', 'user', 'started', 'finished', 'succeeded', 'result_data', 'created', 'modified') 'task_uuid', 'user', 'started', 'finished', 'succeeded', 'result_data', 'created', 'modified', 'get_percentage')
class GroupSerializer(serializers.ModelSerializer): class GroupSerializer(serializers.ModelSerializer):
class Meta: class Meta:
...@@ -73,9 +78,22 @@ class InstanceSerializer(serializers.ModelSerializer): ...@@ -73,9 +78,22 @@ class InstanceSerializer(serializers.ModelSerializer):
class InterfaceSerializer(serializers.ModelSerializer): class InterfaceSerializer(serializers.ModelSerializer):
mac = serializers.SerializerMethodField('get_mac')
ipv4 = serializers.SerializerMethodField('get_ipv4')
ipv6 = serializers.SerializerMethodField('get_ipv6')
def get_mac(self, i):
return str(i.mac)
def get_ipv4(self, i):
return str(i.ipv4)
def get_ipv6(self, i):
return str(i.ipv6)
class Meta: class Meta:
model = Interface model = Interface
fields = ['id', 'vlan', 'host', 'instance', 'model'] fields = ['id', 'vlan', 'host', 'instance', 'model', 'host', 'mac', 'ipv4', 'ipv6']
class VlanSerializer(serializers.ModelSerializer): class VlanSerializer(serializers.ModelSerializer):
...@@ -97,6 +115,13 @@ class DownloadDiskSerializer(serializers.Serializer): ...@@ -97,6 +115,13 @@ class DownloadDiskSerializer(serializers.Serializer):
url = serializers.CharField(max_length=500) url = serializers.CharField(max_length=500)
name = serializers.CharField(max_length=100) name = serializers.CharField(max_length=100)
class DestroyDiskSerializer(serializers.Serializer):
disk = serializers.IntegerField()
instance = serializers.IntegerField(required=False)
class Meta:
extra_kwargs = {'instance': {'required': False, 'allow_null': True}}
class VMDeploySerializer(serializers.Serializer): class VMDeploySerializer(serializers.Serializer):
node = serializers.IntegerField(required=False) node = serializers.IntegerField(required=False)
......
...@@ -58,7 +58,7 @@ from .views import ( ...@@ -58,7 +58,7 @@ from .views import (
InterfaceREST, InstanceFromTemplateREST, InstanceFTforUsersREST, InterfaceREST, InstanceFromTemplateREST, InstanceFTforUsersREST,
DownloadDiskREST, GetInstanceREST, GetInterfaceREST, ShutdownInstanceREST, DownloadDiskREST, GetInstanceREST, GetInterfaceREST, ShutdownInstanceREST,
GetLeaseREST, GetDiskRest, DeployInstanceREST, CreateDiskREST, GetLeaseREST, GetDiskRest, DeployInstanceREST, CreateDiskREST,
VlanREST, ResizeDiskREST, GetVlanREST, VlanREST, ResizeDiskREST, GetVlanREST, DestroyDiskREST,
StorageDetail, DiskDetail, UserREST, GroupREST, StorageDetail, DiskDetail, UserREST, GroupREST,
InstanceActivityREST, GetInstanceActivityREST, InstanceActivityREST, GetInstanceActivityREST,
MessageList, MessageDetail, MessageCreate, MessageDelete, MessageList, MessageDetail, MessageCreate, MessageDelete,
...@@ -94,6 +94,7 @@ urlpatterns = [ ...@@ -94,6 +94,7 @@ urlpatterns = [
path('acpi/vm/<int:pk>/deploy/', DeployInstanceREST.as_view()), path('acpi/vm/<int:pk>/deploy/', DeployInstanceREST.as_view()),
path('acpi/vm/<int:pk>/shutdown/', ShutdownInstanceREST.as_view()), path('acpi/vm/<int:pk>/shutdown/', ShutdownInstanceREST.as_view()),
path('acpi/vm/<int:pk>/resizedisk/', ResizeDiskREST.as_view()), path('acpi/vm/<int:pk>/resizedisk/', ResizeDiskREST.as_view()),
path('acpi/vm/<int:pk>/destroydisk/', DestroyDiskREST.as_view()),
url(r'^$', IndexView.as_view(), name="dashboard.index"), url(r'^$', IndexView.as_view(), name="dashboard.index"),
url(r"^profile/list/$", UserList.as_view(), url(r"^profile/list/$", UserList.as_view(),
name="dashboard.views.user-list"), name="dashboard.views.user-list"),
......
...@@ -29,7 +29,6 @@ from sizefield.utils import filesizeformat ...@@ -29,7 +29,6 @@ from sizefield.utils import filesizeformat
from rest_framework.authentication import TokenAuthentication, BasicAuthentication from rest_framework.authentication import TokenAuthentication, BasicAuthentication
from rest_framework.permissions import IsAdminUser from rest_framework.permissions import IsAdminUser
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.parsers import JSONParser
from common.models import WorkerNotFound from common.models import WorkerNotFound
from storage.models import DataStore, Disk from storage.models import DataStore, Disk
...@@ -156,14 +155,6 @@ class DiskRest(APIView): ...@@ -156,14 +155,6 @@ class DiskRest(APIView):
serializer = DiskSerializer(templates, many=True) serializer = DiskSerializer(templates, many=True)
return JsonResponse(serializer.data, safe=False) return JsonResponse(serializer.data, safe=False)
def post(self, request, format=None):
data = JSONParser().parse(request)
serializer = DiskSerializer(data=data)
if serializer.is_valid():
serializer.save()
return JsonResponse(serializer.data, status=201)
return JsonResponse(serializer.errors, status=400)
class GetDiskRest(APIView): class GetDiskRest(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication] authentication_classes = [TokenAuthentication,BasicAuthentication]
......
...@@ -44,7 +44,9 @@ from django.views.generic import ( ...@@ -44,7 +44,9 @@ from django.views.generic import (
) )
from braces.views import SuperuserRequiredMixin, LoginRequiredMixin from braces.views import SuperuserRequiredMixin, LoginRequiredMixin
from vm.operations import DeployOperation, DestroyOperation, DownloadDiskOperation, ShutdownOperation, RenewOperation, ResizeDiskOperation from vm.operations import (DeployOperation, DestroyOperation, DownloadDiskOperation, ShutdownOperation, RenewOperation,
ResizeDiskOperation, RemoveDiskOperation
)
from common.models import ( from common.models import (
create_readable, HumanReadableException, fetch_human_exception, create_readable, HumanReadableException, fetch_human_exception,
...@@ -98,7 +100,7 @@ from rest_framework.permissions import IsAdminUser ...@@ -98,7 +100,7 @@ from rest_framework.permissions import IsAdminUser
from dashboard.serializers import ( from dashboard.serializers import (
DiskSerializer, InstanceSerializer, InterfaceSerializer, CreateDiskSerializer, DownloadDiskSerializer, DiskSerializer, InstanceSerializer, InterfaceSerializer, CreateDiskSerializer, DownloadDiskSerializer,
VMDeploySerializer, VlanSerializer, ResizeDiskSerializer, InstanceActivitySerializer VMDeploySerializer, VlanSerializer, ResizeDiskSerializer, InstanceActivitySerializer, DestroyDiskSerializer,
) )
class VlanREST(APIView): class VlanREST(APIView):
...@@ -223,7 +225,7 @@ class GetInstanceREST(APIView): ...@@ -223,7 +225,7 @@ class GetInstanceREST(APIView):
instance = Instance.objects.get(pk=pk) instance = Instance.objects.get(pk=pk)
DestroyOperation(instance).call(user=instance.owner) DestroyOperation(instance).call(user=instance.owner)
serializer = InstanceSerializer(instance, many=False) serializer = InstanceSerializer(instance, many=False)
return JsonResponse(serializer.data, status=401) return JsonResponse(serializer.data, status=204)
class DeployInstanceREST(APIView): class DeployInstanceREST(APIView):
...@@ -330,13 +332,19 @@ class ResizeDiskREST(APIView): ...@@ -330,13 +332,19 @@ class ResizeDiskREST(APIView):
return JsonResponse(serializer.errors, status=400) return JsonResponse(serializer.errors, status=400)
class StateOperationREST(APIView): class DestroyDiskREST(APIView):
authentication_classes = [TokenAuthentication,BasicAuthentication] authentication_classes = [TokenAuthentication,BasicAuthentication]
permission_classes = [IsAdminUser] permission_classes = [IsAdminUser]
def post(self, request, pk, format=None): def delete(self, request, pk, format=None):
pass data = JSONParser().parse(request)
return JsonResponse(status=400) serializer = DestroyDiskSerializer(data=data)
if serializer.is_valid():
instance = Instance.objects.get(pk=pk)
disk = Disk.objects.get(pk=int(data['disk']))
RemoveDiskOperation(instance).call(disk=disk, user=instance.owner)
return JsonResponse({}, status=204)
return JsonResponse(serializer.errors, status=400)
class VmDetailVncTokenView(CheckedDetailView): class VmDetailVncTokenView(CheckedDetailView):
......
...@@ -87,6 +87,14 @@ class Interface(Model): ...@@ -87,6 +87,14 @@ class Interface(Model):
except: except:
return Interface.generate_mac(self.instance, self.vlan) return Interface.generate_mac(self.instance, self.vlan)
@property
def ipv4(self):
return self.host.ipv4
@property
def ipv6(self):
return self.host.ipv6
@classmethod @classmethod
def generate_mac(cls, instance, vlan): def generate_mac(cls, instance, vlan):
"""Generate MAC address for a VM instance on a VLAN. """Generate MAC address for a VM instance on a VLAN.
......
...@@ -341,16 +341,17 @@ class DownloadDiskOperation(InstanceOperation): ...@@ -341,16 +341,17 @@ class DownloadDiskOperation(InstanceOperation):
disk.save() disk.save()
self.instance.disks.add(disk) self.instance.disks.add(disk)
activity.readable_name = create_readable( activity.readable_name = create_readable(
ugettext_noop("download %(name)s (id: %(disk_id)s)"), name=disk.name, disk_id=str(disk.id)) ugettext_noop("download %(name)s (id: %(disk_id)d)"), name=disk.name, disk_id=disk.id)
activity.result = create_readable(ugettext_noop( activity.result = create_readable(ugettext_noop(
"Downloading %(url)s is finished. The file md5sum " "Downloading %(url)s is finished. The file md5sum "
"is: '%(checksum)s' (id: %(disk_id)s)."), "is: '%(checksum)s' (id: %(disk_id)d)."),
url=url, checksum=disk.checksum, disk_id=str(disk.id)) url=url, checksum=disk.checksum, disk_id=disk.id, disk_size=disk.size)
activity.result_data['params']['disk_id'] = disk.id
# TODO iso (cd) hot-plug is not supported by kvm/guests # TODO iso (cd) hot-plug is not supported by kvm/guests
if self.instance.is_running and disk.type not in ["iso"]: if self.instance.is_running and disk.type not in ["iso"]:
self.instance._attach_disk(parent_activity=activity, disk=disk) self.instance._attach_disk(parent_activity=activity, disk=disk)
return create_readable(ugettext_noop("Downloading %(url)s is finished. The file md5sum "
"is: '%(checksum)s' (id: %(disk_id)s)."), url=url, checksum=disk.checksum, disk_id=str(disk.id))
@register_operation @register_operation
......
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