- fix comments
[plcapi.git] / PLC / Methods / AdmGetNodeGroupNodes.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 AdmGetNodeGroupNodes(Method):
8     """
9     Returns a list of node_ids for the node group specified.
10     """
11
12     roles = ['admin', 'pi', 'user', 'tech']
13
14     accepts = [
15         PasswordAuth(),
16         Mixed(NodeGroup.fields['nodegroup_id'],
17               NodeGroup.fields['name'])
18         ]
19
20     returns = NodeGroup.join_fields['node_ids']
21
22     def call(self, auth, nodegroup_id_or_name):
23         # Get nodes in this nodegroup
24         nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
25         if not nodegroups:
26             raise PLCInvalidArgument, "No such node group"
27
28         # Get the info for the node group specified
29         nodegroup = nodegroups.values()[0]
30
31         # Return the list of node_ids
32         return nodegroup['node_ids']