1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-26 08:05:22 +00:00
webvirtcloud/networks/api/viewsets.py

29 lines
780 B
Python
Raw Normal View History

from computes.models import Compute
2022-11-02 13:05:41 +00:00
from django.shortcuts import get_object_or_404
from rest_framework import viewsets
from rest_framework.response import Response
from vrtManager.network import wvmNetworks
from .serializers import NetworksSerializer
class NetworkViewSet(viewsets.ViewSet):
"""
A viewset for listing retrieving networks.
"""
2022-11-02 13:05:41 +00:00
def list(self, request, compute_pk=None):
2022-11-02 13:05:41 +00:00
compute = get_object_or_404(Compute, pk=compute_pk)
2022-11-02 13:05:41 +00:00
conn = wvmNetworks(
compute.hostname, compute.login, compute.password, compute.type
)
queryset = conn.get_networks_info()
2022-11-02 13:05:41 +00:00
serializer = NetworksSerializer(
queryset, many=True, context={"request": request}
)
return Response(serializer.data)