From fa68051ccf79dd2b1c84f16b084530d4ea40ebd1 Mon Sep 17 00:00:00 2001 From: Nader Lahouti Date: Fri, 7 Apr 2017 17:22:28 -0700 Subject: [PATCH] Update get_physical_network with the latest change to topology The keys to the json output of 'show network physical-topology hosts' command changed from hostname to chassis ID. This patch makes the code to work with older and latest version of the command's output. Change-Id: Ibfe35e7da4555ea9a5f77645eaca0a498b83cb87 --- networking_arista/ml2/arista_ml2.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/networking_arista/ml2/arista_ml2.py b/networking_arista/ml2/arista_ml2.py index c69a865..13cb745 100644 --- a/networking_arista/ml2/arista_ml2.py +++ b/networking_arista/ml2/arista_ml2.py @@ -1986,7 +1986,6 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase): for a given host_id """ fqdns_used = cfg.CONF.ml2_arista['use_fqdn'] - hostname = None physnet = None switch_id = None mac_to_hostname = {} @@ -1999,20 +1998,20 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase): neighbors = response[0]['neighbors'] for neighbor in neighbors: if host_id in neighbor: - hostname = neighbors[neighbor]['toPort'][0]['hostname'] - physnet = hostname if fqdns_used else ( - hostname.split('.')[0]) + switchname = neighbors[neighbor]['toPort'][0]['hostname'] + physnet = switchname if fqdns_used else ( + switchname.split('.')[0]) + switch_id = neighbors[neighbor]['toPort'][0].get('hostid') + if not switch_id: + switch_id = response[1]['hosts'][switchname]['name'] break - # Get response for 'show network physical-topology hosts' command - if hostname: - switch_id = response[1]['hosts'][hostname]['name'] # Check if the switch is part of an MLAG pair, and lookup the # pair's physnet name if so physnet = self.mlag_pairs.get(physnet, physnet) - for k in response[1]['hosts']: - mac_to_hostname[response[1]['hosts'][k]['name']] = k + for host in response[1]['hosts'].values(): + mac_to_hostname[host['name']] = host['hostname'] res = {'physnet': physnet, 'switch_id': switch_id,