3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Filter import Filter
7 from PLC.Nodes import Node, Nodes
8 from PLC.Persons import Person, Persons
9 from PLC.Auth import Auth
11 class GetWhitelist(Method):
13 Returns an array of structs containing details about the specified nodes
14 whitelists. If node_filter is specified and is an array of node identifiers or
15 hostnames, or a struct of node attributes, only nodes matching the
16 filter will be returned. If return_fields is specified, only the
17 specified details will be returned.
19 Some fields may only be viewed by admins.
22 roles = ['admin', 'pi', 'user', 'tech', 'node', 'anonymous']
26 Mixed([Mixed(Node.fields['node_id'],
27 Node.fields['hostname'])],
29 Parameter([str], "List of fields to return", nullok = True),
32 returns = [Node.fields]
35 def call(self, auth, node_filter = None, return_fields = None):
37 # Must query at least slice_ids_whitelist
38 if return_fields is not None:
39 added_fields = set(['slice_ids_whitelist']).difference(return_fields)
40 return_fields += added_fields
44 # Get node information
45 nodes = Nodes(self.api, node_filter, return_fields)
47 # Remove all nodes without a whitelist
49 if not node['slice_ids_whitelist']:
52 # Remove admin only fields
53 if not isinstance(self.caller, Person) or \
54 'admin' not in self.caller['roles']:
57 slice_ids.update(self.caller['slice_ids'])
58 #if node has whitelist, make sure the user has a slice on the whitelist
60 if 'slice_ids_whitelist' in node and \
61 node['slice_ids_whitelist'] and \
62 not slice_ids.intersection(node['slice_ids_whitelist']):
65 for field in ['boot_nonce', 'key', 'session', 'root_person_ids']:
69 # remove added fields if not specified
72 for field in added_fields: