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 GetWhitelist(Method):
12 Returns an array of structs containing details about the specified nodes
13 whitelists. If 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'])],
28 Parameter([str], "List of fields to return", nullok = True),
31 returns = [Node.fields]
34 def call(self, auth, node_filter = None, return_fields = None):
36 # Must query at least slice_ids_whitelist
37 if return_fields is not None:
38 added_fields = set(['slice_ids_whitelist']).difference(return_fields)
39 return_fields += added_fields
43 # Get node information
44 nodes = Nodes(self.api, node_filter, return_fields)
46 # Remove all nodes without a whitelist
48 if not node['slice_ids_whitelist']:
51 # Remove admin only fields
52 if not isinstance(self.caller, Person) or \
53 'admin' not in self.caller['roles']:
56 slice_ids.update(self.caller['slice_ids'])
57 #if node has whitelist, make sure the user has a slice on the whitelist
59 if 'slice_ids_whitelist' in node and \
60 node['slice_ids_whitelist'] and \
61 not slice_ids.intersection(node['slice_ids_whitelist']):
64 for field in ['boot_nonce', 'key', 'session', 'root_person_ids']:
68 # remove added fields if not specified
71 for field in added_fields: