2022-08-22 12:12:33 +00:00
|
|
|
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
|
2022-08-22 12:12:33 +00:00
|
|
|
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
|
|
|
|
2022-08-22 12:12:33 +00:00
|
|
|
def list(self, request, compute_pk=None):
|
2022-11-02 13:05:41 +00:00
|
|
|
|
2022-08-22 12:12:33 +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
|
|
|
|
)
|
2022-08-22 12:12:33 +00:00
|
|
|
queryset = conn.get_networks_info()
|
|
|
|
|
2022-11-02 13:05:41 +00:00
|
|
|
serializer = NetworksSerializer(
|
|
|
|
queryset, many=True, context={"request": request}
|
|
|
|
)
|
2022-08-22 12:12:33 +00:00
|
|
|
|
|
|
|
return Response(serializer.data)
|