1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Filter import Filter
5 from PLC.Nodes import Node, Nodes
6 from PLC.Persons import Person, Persons
7 from PLC.Auth import Auth
9 admin_only = ['key', 'session', 'boot_nonce' ]
11 class GetNodes(Method):
13 Returns an array of structs containing details about nodes. If
14 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.
18 If return_fields is specified, only the specified details will be
19 returned. NOTE that if return_fields is unspecified, the complete
20 set of native fields are returned, which DOES NOT include tags at
23 Some fields may only be viewed by admins.
26 roles = ['admin', 'pi', 'user', 'tech', 'node', 'anonymous']
30 Mixed([Mixed(Node.fields['node_id'],
31 Node.fields['hostname'])],
32 Parameter(str,"hostname"),
33 Parameter(int,"node_id"),
35 Parameter([str], "List of fields to return", nullok = True),
38 returns = [Node.fields]
41 def call(self, auth, node_filter = None, return_fields = None):
43 # Must query at least slice_ids_whitelist
44 if return_fields is not None:
45 added_fields = set(['slice_ids_whitelist', 'site_id']).difference(return_fields)
46 return_fields += added_fields
50 # Get node information
51 nodes = Nodes(self.api, node_filter, return_fields)
53 # Remove admin only fields
54 if not isinstance(self.caller, Person) or \
55 'admin' not in self.caller['roles']:
60 slice_ids.update(self.caller['slice_ids'])
61 if isinstance(self.caller, Node):
62 site_ids.update([self.caller['site_id']])
64 site_ids.update(self.caller['site_ids'])
66 # if node has whitelist, only return it if users is at
67 # the same site or user has a slice on the whitelist
69 if 'site_id' in node and \
70 site_ids.intersection([node['site_id']]):
72 if 'slice_ids_whitelist' in node and \
73 node['slice_ids_whitelist'] and \
74 not slice_ids.intersection(node['slice_ids_whitelist']):
77 # remove remaining admin only fields
79 for field in admin_only:
83 # remove added fields if not specified
86 for field in added_fields: