Initial checkin of new API implementation
[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         NodeGroup.fields['nodegroup_id']
21         ]
22
23     returns = [NodeGroup.join_fields['node_ids']]
24
25     def __init__(self, *args, **kwds):
26         Method.__init__(self, *args, **kwds)
27         # Update documentation with list of default fields returned
28         self.__doc__ += os.linesep.join(Site.default_fields.keys())
29
30     def call(self, auth, nodegroup_id):
31         # Authenticated function
32         assert self.caller is not None
33
34         # Get nodes in this nodegroup
35         nodegroup = NodeGroups(self.api, [nodegroup_id])        
36
37         # make sure sites are found
38         if not nodegroup:
39                 raise PLCInvalidArgument, "No such site"
40         
41         #get the info for the node group specified
42         nodegroup_values = nodegroup.values()[0]
43
44         #grab the list of node ides fromt the disctioary
45         node_ids = nodegroup_values['node_ids']
46         
47         return node_ids