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 # Filter out undesired or None fields (XML-RPC cannot marshal
41 # None) and turn each node into a real dict.
42 valid_return_fields_only = lambda (key, value): value is not None
43 nodenetworks = [dict(filter(valid_return_fields_only, nodenetwork.items())) \
44 for nodenetwork in nodenetworks]