X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FGetNodeNetworks.py;h=1168e4916a6590568020f2d799a6f49f0be4947a;hb=8f070b5b4e512641e6e2468ee36f856e1eb52661;hp=14cdd48c405a496c25b3a7c45466131db4f224eb;hpb=40d33ca5c3e174e3ac07e3519c07e43825b4c797;p=plcapi.git diff --git a/PLC/Methods/GetNodeNetworks.py b/PLC/Methods/GetNodeNetworks.py index 14cdd48..1168e49 100644 --- a/PLC/Methods/GetNodeNetworks.py +++ b/PLC/Methods/GetNodeNetworks.py @@ -1,46 +1,31 @@ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed +from PLC.Filter import Filter from PLC.NodeNetworks import NodeNetwork, NodeNetworks -from PLC.Nodes import Node, Nodes -from PLC.Auth import PasswordAuth +from PLC.Auth import Auth class GetNodeNetworks(Method): """ - Returns all the networks this node is connected to, as an array of - structs. + Returns an array of structs containing details about node network + interfacess. If nodenetworks_filter is specified and is an array + of node network identifiers, or a struct of node network + attributes, only node network interfaces matching the filter will + be returned. If return_fields is specified, only the + specified details will be returned. """ roles = ['admin', 'pi', 'user', 'tech'] accepts = [ - PasswordAuth(), - Mixed(Node.fields['node_id'], - Node.fields['hostname']) + Auth(), + Mixed([NodeNetwork.fields['nodenetwork_id']], + Filter(NodeNetwork.fields)), + Parameter([str], "List of fields to return", nullok = True) ] 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]).values() - if not nodes: - raise PLCInvalidArgument, "No such node" - node = nodes[0] - - # Get node networks for this node - 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): value is not None - nodenetworks = [dict(filter(valid_return_fields_only, nodenetwork.items())) \ - for nodenetwork in nodenetworks] - - return nodenetworks + def call(self, auth, nodenetwork_filter = None, return_fields = None): + return NodeNetworks(self.api, nodenetwork_filter, return_fields)