- no longer filter out None
[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         # Turn each nodegroup into a real dict.
29         nodegroups = [dict(nodegroup.items()) for nodegroup in nodegroups]
30
31         return nodegroups