- fix AdmGetAllNodeNetworks() to return node networks only for specified node
[plcapi.git] / PLC / Methods / AdmGetAllNodeNetworks.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Nodes import Node, Nodes
5 from PLC.NodeNetworks import NodeNetwork, NodeNetworks
6 from PLC.Auth import PasswordAuth
7 from PLC.Methods.GetNodeNetworks import GetNodeNetworks
8
9 class AdmGetAllNodeNetworks(GetNodeNetworks):
10     """
11     Deprecated. Functionality can be implemented with GetNodes and
12     GetNodeNetworks.
13     """
14
15     status = "deprecated"
16
17     roles = ['admin', 'pi', 'user', 'tech']
18
19     accepts = [
20         PasswordAuth(),
21         Mixed(Node.fields['node_id'],
22               Node.fields['hostname'])
23         ]
24
25     returns = [NodeNetwork.fields]
26
27     def call(self, auth, node_id_or_hostname):
28         # Authenticated function
29         assert self.caller is not None
30
31         # Get node information
32         nodes = Nodes(self.api, [node_id_or_hostname]).values()
33         if not nodes:
34             raise PLCInvalidArgument, "No such node"
35         node = nodes[0]
36
37         return GetNodeNetworks.call(self, auth, node['nodenetwork_ids'])