27 from py2neo
import Graph
29 from prettytable
import PrettyTable
31 LOG = logging.getLogger(__name__)
36 [
'PORT',
'FL-PORT',
'FL-LINK',
'NEO4J-SRC',
'NEO4J-DST',
37 'NEO4J-REMOTE',
'WFM-ISL-FOUND',
'WFM-ISL-STATUS',
'RECEIVE-DROPPED',
38 'RECEIVE-PACKETS',
'TRANSMIT-PACKETS'], align=
'l')
39 for port_id, v
in records.items():
42 v.get(
'FL_PORT',
'-'),
43 v.get(
'FL_LINK',
'-'),
44 v.get(
'NEO4J_SRC',
'-'),
45 v.get(
'NEO4J_DST',
'-'),
47 v.get(
'WFM_ISL_FOUND',
'-'),
48 v.get(
'WFM_ISL_STATUS',
'-'),
49 v.get(
'RECEIVE_DROPPED',
'-'),
50 v.get(
'RECEIVE_PACKETS',
'-'),
51 v.get(
'TRANSMIT_PACKETS',
'-')
57 url =
"{}/wm/core/switch/{}/port/json".
format(ctx.fl_host, switch_id)
58 result = requests.get(url)
59 result.raise_for_status()
61 result_data = result.json()
64 pprint.pprint(result_data)
66 ports = result_data[
'port_reply'][0][
'port']
68 return {int(x[
'port_number']): {
'RECEIVE_DROPPED': x[
'receive_dropped'],
69 'RECEIVE_PACKETS': x[
'receive_packets'],
70 'TRANSMIT_PACKETS': x[
'transmit_packets'],
72 ports
if x[
'port_number'].isdigit()}
76 url =
"{}/wm/core/switch/{}/port-desc/json".
format(ctx.fl_host, switch_id)
77 result = requests.get(url)
78 result.raise_for_status()
84 result_data = result.json()
86 if 'port_desc' in result_data:
89 r = {
'FL_PORT':
'PORT_UP',
92 if 'PORT_DOWN' in sw[
'config']:
93 r[
'FL_PORT'] =
'PORT_DOWN' 94 if 'LINK_DOWN' in sw[
'state']:
95 r[
'FL_LINK'] =
'LINK_DOWN' 99 return {int(x[
'port_number']): get_status(x)
for x
in 100 result.json()[
'port_desc']
if x[
'port_number'].isdigit()}
106 query =
'MATCH ()-[r:isl]->() WHERE r.src_switch = "{}" OR r.dst_switch ' \
107 '= "{}" RETURN r'.
format(switch_id, switch_id)
109 graph = Graph(
"http://{}:{}@{}:7474/db/data/".
format(
114 result = graph.run(query).
data()
116 def get_status(link):
117 if link[
'src_switch'] == switch_id:
118 return {
'NEO4J_SRC': link[
'status']}
119 return {
'NEO4J_DST': link[
'status']}
121 def get_port_from_link(link):
122 if link[
'src_switch'] == switch_id:
123 return link[
'src_port']
124 return link[
'dst_port']
130 port_id = int(get_port_from_link(x)) 132 if port_id
not in retval:
135 retval[port_id].update(get_status(x))
137 if x[
'src_switch'] == switch_id:
138 retval[port_id][
'REMOTE'] =
'{}-{}'.
format(x[
'dst_switch'],
145 'wfm/kilda.topo.disco-bolt',
152 LOG.error(
"wfm/kilda.topo.disco-bolt NO RESPONSE")
156 for record
in records:
157 data = json.loads(record.value)
158 payload = data[
'payload']
160 for port
in payload[
'state'][
'discovery']:
162 if port[
'consecutive_success'] == 0:
164 elif port[
'consecutive_failure'] == 0:
169 retval[int(port[
'port_id'])] = {
170 'WFM_ISL_FOUND':
'FOUND' if port[
'found_isl']
else 'NOT FOUND',
171 'WFM_ISL_STATUS':
'{}'.
format(status)
177 @click.command(name=
'switch-port-status')
178 @click.argument(
'switch-id')
183 except Exception
as ex:
184 traceback.print_exc()
190 except Exception
as ex:
191 traceback.print_exc()
192 fl_port_stats_results = {}
196 wfm_results_no_records = len(wfm_results) == 0
197 except Exception
as ex:
198 traceback.print_exc()
200 wfm_results_no_records =
False 204 except Exception
as ex:
205 traceback.print_exc()
208 port_ids = set(list(fl_results.keys()) +
209 list(neo4j_results.keys()) +
210 list(wfm_results.keys()) +
211 list(fl_port_stats_results.keys())
216 if wfm_results_no_records:
217 wfm_results = {port_id: {
'WFM_ISL_FOUND':
'NO DATA'}
for port_id
in 220 for port
in port_ids:
222 results[port].update(fl_results.get(port, {}))
223 results[port].update(neo4j_results.get(port, {}))
224 results[port].update(wfm_results.get(port, {}))
225 results[port].update(fl_port_stats_results.get(port, {}))
def create_dump_state_by_switch(correlation_id, destination, switch)
def send_with_context(context, message)
def wfm_ports_for_switch(ctx, switch_id)
def receive_with_context_async(context, expected_count=None)
def fl_get_ports_stats_for_switch(ctx, switch_id, debug)
def neo4g_ports_for_switch(ctx, switch_id)
def switch_port_status_command(ctx, switch_id)
def fl_get_ports_for_switch(ctx, switch_id, debug)