-import os
-
from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
"""
Returns all the networks this node is connected to, as an array of
structs.
-
"""
roles = ['admin', 'pi', 'user', 'tech']
accepts = [
PasswordAuth(),
Mixed(Node.fields['node_id'],
- Node.fields['hostname'])
+ Node.fields['hostname'])
]
- #returns = [NodeNetwork.all_fields]
+ returns = [NodeNetwork.fields]
def call(self, auth, node_id_or_hostname):
# Authenticated function
assert self.caller is not None
# Get node information
- nodes = Nodes(self.api, [node_id_or_hostname], NodeNetwork.all_fields).values()
+ nodes = Nodes(self.api, [node_id_or_hostname]).values()
if not nodes:
- raise PLCInvalidArgument, "No such node"
+ raise PLCInvalidArgument, "No such node"
node = nodes[0]
-
+
# Get node networks for this node
- nodenetwork_ids = node['nodenetwork_ids']
- if not nodenetwork_ids:
- raise PLCInvalidArgument, "Node has no node networks"
- nodenetworks = NodeNetworks(self.api, nodenetwork_ids).values()
+ if node['nodenetwork_ids']:
+ nodenetworks = NodeNetworks(self.api, node['nodenetwork_ids']).values()
+ else:
+ nodenetworks = []
# Filter out undesired or None fields (XML-RPC cannot marshal
# None) and turn each node into a real dict.
- valid_return_fields_only = lambda (key, value): \
- key in NodeNetwork.all_fields and value is not None
+ valid_return_fields_only = lambda (key, value): value is not None
nodenetworks = [dict(filter(valid_return_fields_only, nodenetwork.items())) \
- for nodenetwork in nodenetworks]
-
+ for nodenetwork in nodenetworks]
return nodenetworks