Skip to content

Commit

Permalink
Fix the sort order on ls-interfaces
Browse files Browse the repository at this point in the history
The ls-interfaces option currently returns an array of strings
that are the string representation of dictionaries with data on
the wired interfaces.  This patch takes the result and converts
then to proper dictionaries, and then sorts the output to sort
on the interface names.   The output is further formatted to look
like the following:

interface: em1, mac address: 0c:c4:7a:eb:8c:16, switch IP: 192.168.0.1, port: xe-0/0/22:2
interface: em2, mac address: 0c:c4:7a:eb:8c:17, switch IP: 192.168.0.1, port: xe-0/0/22:3
interface: em3, mac address: b8:ca:3a:63:83:98, switch IP: 192.168.0.1, port: xe-0/0/20:2
interface: em4, mac address: b8:ca:3a:63:83:9a, switch IP: 192.168.0.1, port: xe-0/0/20:3

Fixes: #313
Change-Id: If01ecf56691059561a214c7c4e03933be5cc06a5
  • Loading branch information
kambiz-aghaiepour committed Feb 20, 2020
1 parent ef48064 commit 9404d2e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions bin/quads-cli
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# along with QUADs. If not, see <http://www.gnu.org/licenses/>.

import argparse
import json
import asyncio
from datetime import datetime
import functools
Expand Down Expand Up @@ -109,9 +110,15 @@ def main(_args):
logger.error("Could not connect to the quads-server, verify service is up and running.")
exit(1)
if data:
for interface in data["result"]:
logger.info(interface)
exit(0)
result = [json.loads(entry) for entry in data['result']]
for interface in sorted(result, key=lambda k: k['name']):
message = \
f"interface: {interface['name']}, " \
f"mac address: {interface['ip_address']}, " \
f"switch IP: {interface['ip_address']}, " \
f"port: {interface['switch_port']}"
logger.info(message)
exit(0)

if _args.action == 'schedule':
if _args.host:
Expand Down

0 comments on commit 9404d2e

Please sign in to comment.