(most) all functions now take SessionAuth in addition to PasswordAuth
[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 Auth
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         Auth(),
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         # Get node information
29         nodes = Nodes(self.api, [node_id_or_hostname]).values()
30         if not nodes:
31             raise PLCInvalidArgument, "No such node"
32         node = nodes[0]
33
34         if not node['nodenetwork_ids']:
35             return []
36
37         return GetNodeNetworks.call(self, auth, node['nodenetwork_ids'])