X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FAdmGetAllNodeNetworks.py;h=3e9eb1c67af9b817f7895fc2c514b78a4c4a578a;hb=42a5b49014fb9063f10c53b418b0800d41771c7a;hp=48f2cb7b26b75191fc7d0435c0a1cee2fbe0898d;hpb=5c10b06bd3eb270477033093876c69315262d763;p=plcapi.git diff --git a/PLC/Methods/AdmGetAllNodeNetworks.py b/PLC/Methods/AdmGetAllNodeNetworks.py index 48f2cb7..3e9eb1c 100644 --- a/PLC/Methods/AdmGetAllNodeNetworks.py +++ b/PLC/Methods/AdmGetAllNodeNetworks.py @@ -1,5 +1,3 @@ -import os - from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed @@ -11,7 +9,6 @@ class AdmGetAllNodeNetworks(Method): """ Returns all the networks this node is connected to, as an array of structs. - """ roles = ['admin', 'pi', 'user', 'tech'] @@ -19,33 +16,31 @@ class AdmGetAllNodeNetworks(Method): 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