- fixed exception response
[plcapi.git] / PLC / Methods / AdmGetNodeGroupNodes.py
1 import os
2
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 AdmGetNodeGroupNodes(Method):
11     """
12     Return a list of node_ids for the node group specified.
13
14     """
15
16     roles = ['admin', 'pi', 'user', 'tech']
17
18     accepts = [
19         PasswordAuth(),
20         Mixed(NodeGroup.fields['nodegroup_id'],
21               NodeGroup.fields['name'])
22         ]
23
24     returns = [NodeGroup.join_fields['node_ids']]
25
26
27     def call(self, auth, nodegroup_id_or_name):
28         # Authenticated function
29         assert self.caller is not None
30
31         # Get nodes in this nodegroup
32         nodegroup = NodeGroups(self.api, [nodegroup_id_or_name])        
33
34         # make sure nodegroup is found
35         if not nodegroup:
36                 raise PLCInvalidArgument, "No such nodegroup"
37         
38         #get the info for the node group specified
39         nodegroup_values = nodegroup.values()[0]
40
41         #grab the list of node ides fromt the disctioary
42         node_ids = nodegroup_values['node_ids']
43         
44         return node_ids