mirror of
https://github.com/retspen/webvirtcloud
synced 2024-11-01 20:14:15 +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>
26 lines
770 B
Python
26 lines
770 B
Python
from django.shortcuts import get_object_or_404
|
|
from computes.models import Compute
|
|
from rest_framework import status, viewsets
|
|
|
|
from vrtManager.network import wvmNetworks
|
|
|
|
from .serializers import NetworksSerializer
|
|
from rest_framework.response import Response
|
|
|
|
|
|
class NetworkViewSet(viewsets.ViewSet):
|
|
"""
|
|
A viewset for listing retrieving networks.
|
|
"""
|
|
|
|
def list(self, request, compute_pk=None):
|
|
|
|
compute = get_object_or_404(Compute, pk=compute_pk)
|
|
|
|
conn = wvmNetworks(compute.hostname, compute.login, compute.password, compute.type)
|
|
queryset = conn.get_networks_info()
|
|
|
|
serializer = NetworksSerializer(queryset, many=True, context={'request': request})
|
|
|
|
return Response(serializer.data)
|
|
|