allow filtering by node name
diff --git a/xos/core/xoslib/methods/sshkeys.py b/xos/core/xoslib/methods/sshkeys.py
index 31121fc..9bbe55d 100644
--- a/xos/core/xoslib/methods/sshkeys.py
+++ b/xos/core/xoslib/methods/sshkeys.py
@@ -16,21 +16,41 @@
def get(self, request, format=None):
instances=[]
- for sliver in Sliver.objects.all():
+ for sliver in self.get_queryset().all():
if sliver.instance_id:
instances.append( {"id": sliver.instance_id,
- "public_keys": sliver.get_public_keys() } )
+ "public_keys": sliver.get_public_keys(),
+ "node_name": sliver.node.name } )
return Response(instances)
+ def get_queryset(self):
+ queryset = queryset=Sliver.objects.all()
+
+ node_name = self.request.QUERY_PARAMS.get('node_name', None)
+ if node_name is not None:
+ queryset = queryset.filter(node__name = node_name)
+
+ return queryset
+
class SSHKeyDetail(APIView):
method_kind = "detail"
method_name = "sshkeys"
def get(self, request, format=None, pk=0):
- slivers = Sliver.objects.filter(instance_id=pk)
+ slivers = self.get_queryset().filter(instance_id=pk)
if not slivers:
raise XOSNotFound("didn't find sliver for instance %s" % pk)
return Response( [ {"id": slivers[0].instance_id,
- "public_keys": slivers[0].get_public_keys() } ])
+ "public_keys": slivers[0].get_public_keys(),
+ "node_name": sliver.node.name } ])
+
+ def get_queryset(self):
+ queryset = queryset=Sliver.objects.all()
+
+ node_name = self.request.QUERY_PARAMS.get('node_name', None)
+ if node_name is not None:
+ queryset = queryset.filter(node__name = node_name)
+
+ return queryset