- removed 'Adm' prefix
[plcapi.git] / PLC / Methods / GetNodeGroups.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Auth import PasswordAuth
5 from PLC.NodeGroups import NodeGroup, NodeGroups
6
7 class GetNodeGroups(Method):
8     """
9     Returns an array of structs containing details about all node
10     groups. If nodegroup_id_or_name_list is specified, only the
11     specified node groups will be queried.
12     """
13
14     roles = ['admin', 'pi', 'user', 'tech']
15
16     accepts = [
17         PasswordAuth(),
18         [Mixed(NodeGroup.fields['nodegroup_id'],
19                NodeGroup.fields['name'])]
20         ]
21
22     returns = [NodeGroup.fields]
23   
24     def call(self, auth, nodegroup_id_or_name_list = None):
25         # Get node group details
26         nodegroups = NodeGroups(self.api, nodegroup_id_or_name_list).values()
27
28         # Filter out undesired or None fields (XML-RPC cannot marshal
29         # None) and turn each nodegroup into a real dict.
30         valid_return_fields_only = lambda (key, value): value is not None
31         nodegroups = [dict(filter(valid_return_fields_only, nodegroup.items())) \
32                       for nodegroup in nodegroups]
33
34         return nodegroups