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.Nodes import Node, Nodes
6 from PLC.Auth import PasswordAuth
8 class GetNodeNetworks(Method):
10 Returns all the networks this node is connected to, as an array of
14 roles = ['admin', 'pi', 'user', 'tech']
18 Mixed(Node.fields['node_id'],
19 Node.fields['hostname'])
22 returns = [NodeNetwork.fields]
24 def call(self, auth, node_id_or_hostname):
25 # Authenticated function
26 assert self.caller is not None
28 # Get node information
29 nodes = Nodes(self.api, [node_id_or_hostname]).values()
31 raise PLCInvalidArgument, "No such node"
34 # Get node networks for this node
35 if node['nodenetwork_ids']:
36 nodenetworks = NodeNetworks(self.api, node['nodenetwork_ids']).values()
40 # Turn each node into a real dict.
41 nodenetworks = [dict(nodenetwork.items()) for nodenetwork in nodenetworks]