mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-26 08:05:22 +00:00
cfce71ec2b
* Add rest framework for API: First Commit * modify some shell scripts to make variable references safer; modify some python scripts to reduce the code complexity and cyclomatic complexity of functions. * Add REST API for some webvirtcloud functions. Instance list/delete/create, compute list/delete/create, storages-network list/retrieve. Add swagger and redoc for API interface * update requirements Co-authored-by: herengui <herengui@uniontech.com>
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
from computes.models import Compute
|
|
from rest_framework import viewsets
|
|
from rest_framework import permissions
|
|
|
|
from vrtManager.create import wvmCreate
|
|
from .serializers import ComputeSerializer
|
|
from rest_framework.response import Response
|
|
|
|
|
|
class ComputeViewSet(viewsets.ModelViewSet):
|
|
"""
|
|
API endpoint that allows computes to be viewed or edited.
|
|
"""
|
|
queryset = Compute.objects.all().order_by('name')
|
|
serializer_class = ComputeSerializer
|
|
permission_classes = [permissions.IsAuthenticated]
|
|
|
|
|
|
class ComputeArchitecturesView(viewsets.ViewSet):
|
|
|
|
def list(self, request, compute_pk=None):
|
|
"""
|
|
Return a list of supported host architectures.
|
|
"""
|
|
compute = Compute.objects.get(pk=compute_pk)
|
|
conn = wvmCreate(
|
|
compute.hostname,
|
|
compute.login,
|
|
compute.password,
|
|
compute.type,
|
|
)
|
|
return Response(conn.get_hypervisors_machines())
|
|
|
|
def retrieve(self, request, compute_pk=None, pk=None):
|
|
compute = Compute.objects.get(pk=compute_pk)
|
|
conn = wvmCreate(
|
|
compute.hostname,
|
|
compute.login,
|
|
compute.password,
|
|
compute.type,
|
|
)
|
|
return Response(conn.get_machine_types(pk))
|
|
|
|
|
|
class ComputeMachinesView(viewsets.ViewSet):
|
|
|
|
def list(self, request, compute_pk=None, archs_pk=None):
|
|
"""
|
|
Return a list of supported host architectures.
|
|
"""
|
|
compute = Compute.objects.get(pk=compute_pk)
|
|
conn = wvmCreate(
|
|
compute.hostname,
|
|
compute.login,
|
|
compute.password,
|
|
compute.type,
|
|
)
|
|
return Response(conn.get_machine_types(archs_pk))
|