From d589b3d766754fb18583e48c90e02017769d5344 Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Mon, 16 Oct 2006 19:13:13 +0000 Subject: [PATCH] make GetNodeNetworks consistent with all other Get functions --- PLC/Methods/AdmGetAllNodeNetworks.py | 40 +++++++++++++++++++++++++++- PLC/Methods/GetNodeNetworks.py | 31 +++++++-------------- 2 files changed, 48 insertions(+), 23 deletions(-) diff --git a/PLC/Methods/AdmGetAllNodeNetworks.py b/PLC/Methods/AdmGetAllNodeNetworks.py index 291e19ab..fc40ad68 100644 --- a/PLC/Methods/AdmGetAllNodeNetworks.py +++ b/PLC/Methods/AdmGetAllNodeNetworks.py @@ -1,8 +1,46 @@ +from PLC.Faults import * +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Nodes import Node, Nodes +from PLC.NodeNetworks import NodeNetwork, NodeNetworks +from PLC.Auth import PasswordAuth from PLC.Methods.GetNodeNetworks import GetNodeNetworks class AdmGetAllNodeNetworks(GetNodeNetworks): """ - Deprecated. See GetNodeNetworks. + Deprecated. Functionality can be implemented with GetNodes and + GetNodeNetworks. """ status = "deprecated" + + roles = ['admin', 'pi', 'user', 'tech'] + + accepts = [ + PasswordAuth(), + Mixed(Node.fields['node_id'], + Node.fields['hostname']) + ] + + 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 = [] + + # Cast from NodeNetwork to real dict + nodenetworks = [dict(nodenetwork) for nodenetwork in nodenetworks] + + return nodenetworks diff --git a/PLC/Methods/GetNodeNetworks.py b/PLC/Methods/GetNodeNetworks.py index 199f9bdc..1bc6ef24 100644 --- a/PLC/Methods/GetNodeNetworks.py +++ b/PLC/Methods/GetNodeNetworks.py @@ -2,42 +2,29 @@ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.NodeNetworks import NodeNetwork, NodeNetworks -from PLC.Nodes import Node, Nodes from PLC.Auth import PasswordAuth class GetNodeNetworks(Method): """ - Returns all the networks this node is connected to, as an array of - structs. + Return an array of structs contain details about node network + interfaces. If nodenetwork_id_or_hostname_list is specified, only + the specified node network interfaces will be queried. """ roles = ['admin', 'pi', 'user', 'tech'] accepts = [ PasswordAuth(), - Mixed(Node.fields['node_id'], - Node.fields['hostname']) + [Mixed(NodeNetwork.fields['nodenetwork_id'], + NodeNetwork.fields['hostname'])] ] returns = [NodeNetwork.fields] - def call(self, auth, node_id_or_hostname): - # Authenticated function - assert self.caller is not None + def call(self, auth, nodenetwork_id_or_hostname_list = None): + nodenetworks = NodeNetworks(self.api, nodenetwork_id_or_hostname_list).values() - # 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 = [] - - # Turn each node into a real dict. - nodenetworks = [dict(nodenetwork.items()) for nodenetwork in nodenetworks] + # Cast from NodeNetwork to real dict + nodenetworks = [dict(nodenetwork) for nodenetwork in nodenetworks] return nodenetworks -- 2.47.0