9d0b4df28daffd9cadbbc04b4788d6e142ac7d66
[plcapi.git] / PLC / Methods / GetNodeNetworks.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.NodeNetworks import NodeNetwork, NodeNetworks
5 from PLC.Auth import PasswordAuth
6
7 class GetNodeNetworks(Method):
8     """
9     Return an array of structs contain details about node network
10     interfaces. If nodenetwork_id_or_ip_list is specified, only
11     the specified node network interfaces will be queried.
12     """
13
14     roles = ['admin', 'pi', 'user', 'tech']
15
16     accepts = [
17         PasswordAuth(),
18         [Mixed(NodeNetwork.fields['nodenetwork_id'],
19                NodeNetwork.fields['ip'])]
20         ]
21
22     returns = [NodeNetwork.fields]
23
24     def call(self, auth, nodenetwork_id_or_ip_list = None):
25         nodenetworks = NodeNetworks(self.api, nodenetwork_id_or_ip_list).values()
26
27         # Cast from NodeNetwork to real dict
28         nodenetworks = [dict(nodenetwork) for nodenetwork in nodenetworks]
29         
30         return nodenetworks