blob: a7142124a1ddc5ac03e88f0bf18c67dd3bdcccae [file] [log] [blame]
Scott Bakera115c1e2015-05-07 14:58:46 -07001from rest_framework.decorators import api_view
2from rest_framework.response import Response
3from rest_framework.reverse import reverse
4from rest_framework import serializers
5from rest_framework import generics
6from rest_framework.views import APIView
7from core.models import *
8from django.forms import widgets
9from syndicate_storage.models import Volume
10from django.core.exceptions import PermissionDenied
11from xos.exceptions import XOSNotFound
12
13class SSHKeyList(APIView):
14 method_kind = "list"
15 method_name = "sshkeys"
16
17 def get(self, request, format=None):
18 instances=[]
Scott Baker071dae72015-05-07 15:28:23 -070019 for sliver in self.get_queryset().all():
Scott Bakera115c1e2015-05-07 14:58:46 -070020 if sliver.instance_id:
21 instances.append( {"id": sliver.instance_id,
Scott Baker071dae72015-05-07 15:28:23 -070022 "public_keys": sliver.get_public_keys(),
23 "node_name": sliver.node.name } )
Scott Bakera115c1e2015-05-07 14:58:46 -070024
25 return Response(instances)
26
Scott Baker071dae72015-05-07 15:28:23 -070027 def get_queryset(self):
28 queryset = queryset=Sliver.objects.all()
29
30 node_name = self.request.QUERY_PARAMS.get('node_name', None)
31 if node_name is not None:
32 queryset = queryset.filter(node__name = node_name)
33
34 return queryset
35
Scott Bakera115c1e2015-05-07 14:58:46 -070036class SSHKeyDetail(APIView):
37 method_kind = "detail"
38 method_name = "sshkeys"
39
40 def get(self, request, format=None, pk=0):
Scott Baker071dae72015-05-07 15:28:23 -070041 slivers = self.get_queryset().filter(instance_id=pk)
Scott Bakera115c1e2015-05-07 14:58:46 -070042 if not slivers:
43 raise XOSNotFound("didn't find sliver for instance %s" % pk)
44 return Response( [ {"id": slivers[0].instance_id,
Scott Baker071dae72015-05-07 15:28:23 -070045 "public_keys": slivers[0].get_public_keys(),
Scott Bakerf46cec12015-05-07 15:31:55 -070046 "node_name": slivers[0].node.name } ])
Scott Baker071dae72015-05-07 15:28:23 -070047
48 def get_queryset(self):
49 queryset = queryset=Sliver.objects.all()
50
51 node_name = self.request.QUERY_PARAMS.get('node_name', None)
52 if node_name is not None:
53 queryset = queryset.filter(node__name = node_name)
54
55 return queryset
Scott Bakera115c1e2015-05-07 14:58:46 -070056