3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Sites import Site, Sites
7 from PLC.Nodes import Node, Nodes
8 from PLC.Auth import PasswordAuth
9 from PLC.NodeGroups import NodeGroup, NodeGroups
10 class AdmGetNodeGroups(Method):
12 Returns a list of structs containing the details about the node groups
17 roles = ['admin', 'pi', 'user', 'tech']
21 [Mixed(NodeGroup.fields['nodegroup_id'],
22 NodeGroup.fields['name'])]
25 returns = [NodeGroup.all_fields]
27 def __init__(self, *args, **kwds):
28 Method.__init__(self, *args, **kwds)
29 # Update documentation with list of default fields returned
30 self.__doc__ += os.linesep.join(Site.default_fields.keys())
32 def call(self, auth, nodegroup_id_or_name_list=None):
33 # Authenticated function
34 assert self.caller is not None
36 # Get nodes in this nodegroup
37 nodegroups = NodeGroups(self.api, nodegroup_id_or_name_list).values()
39 # make sure sites are found
41 raise PLCInvalidArgument, "No such site"
42 elif nodegroup_id_or_name_list is None:
44 elif not len(nodegroups) == len(nodegroup_id_or_name_list):
45 raise PLCInvalidArgument, "at least one node group id is invalid"
47 # Filter out undesired or None fields (XML-RPC cannot marshal
48 # None) and turn each node into a real dict.
49 valid_return_fields_only = lambda (key, value): \
50 key in NodeGroup.all_fields and value is not None
51 nodegroups = [dict(filter(valid_return_fields_only, nodegroup.items())) \
52 for nodegroup in nodegroups]