2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Filter import Filter
6 from PLC.Nodes import Node, Nodes
7 from PLC.Persons import Person, Persons
8 from PLC.Auth import Auth
10 class GetNodes(Method):
12 Returns an array of structs containing details about nodes. If
13 node_filter is specified and is an array of node identifiers or
14 hostnames, or a struct of node attributes, only nodes matching the
15 filter will be returned. If return_fields is specified, only the
16 specified details will be returned.
18 Some fields may only be viewed by admins.
21 roles = ['admin', 'pi', 'user', 'tech', 'node', 'anonymous']
25 Mixed([Mixed(Node.fields['node_id'],
26 Node.fields['hostname'])],
27 Parameter(str,"hostname"),
28 Parameter(int,"node_id"),
30 Parameter([str], "List of fields to return", nullok = True),
33 returns = [Node.fields]
36 def call(self, auth, node_filter = None, return_fields = None):
38 # Must query at least slice_ids_whitelist
39 if return_fields is not None:
40 added_fields = set(['slice_ids_whitelist', 'site_id']).difference(return_fields)
41 return_fields += added_fields
45 # Get node information
46 nodes = Nodes(self.api, node_filter, return_fields)
48 # Remove admin only fields
49 if not isinstance(self.caller, Person) or \
50 'admin' not in self.caller['roles']:
55 slice_ids.update(self.caller['slice_ids'])
56 if isinstance(self.caller, Node):
57 site_ids.update([self.caller['site_id']])
59 site_ids.update(self.caller['site_ids'])
61 # if node has whitelist, only return it if users is at
62 # the same site or user has a slice on the whitelist
64 if 'site_id' in node and \
65 site_ids.intersection([node['site_id']]):
67 if 'slice_ids_whitelist' in node and \
68 node['slice_ids_whitelist'] and \
69 not slice_ids.intersection(node['slice_ids_whitelist']):
72 # remove remaining admin only fields
74 for field in ['boot_nonce', 'key', 'session', 'root_person_ids']:
78 # remove added fields if not specified
81 for field in added_fields: