From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bcmv-tmail01.ecl.ntt.co.jp (bcmv-tmail01.ecl.ntt.co.jp [124.146.185.148]) by dpdk.org (Postfix) with ESMTP id 22AA0695D for ; Thu, 4 Oct 2018 07:59:35 +0200 (CEST) Received: from bcmv-ns01.ecl.ntt.co.jp (bcmv-ns01.ecl.ntt.co.jp [129.60.83.123]) by bcmv-tmail01.ecl.ntt.co.jp (8.14.4/8.14.4) with ESMTP id w945xYmB008265; Thu, 4 Oct 2018 14:59:34 +0900 Received: from bcmv-ns01.ecl.ntt.co.jp (localhost [127.0.0.1]) by bcmv-ns01.ecl.ntt.co.jp (Postfix) with ESMTP id 42589129; Thu, 4 Oct 2018 14:59:34 +0900 (JST) Received: from localhost.localdomain (unknown [129.60.13.51]) by bcmv-ns01.ecl.ntt.co.jp (Postfix) with ESMTP id 2BD5B10E; Thu, 4 Oct 2018 14:59:34 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp Date: Thu, 4 Oct 2018 14:59:18 +0900 Message-Id: <20181004055918.5922-5-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20181004055918.5922-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20181004055918.5922-1-ogawa.yasufumi@lab.ntt.co.jp> X-TM-AS-MML: disable Subject: [spp] [PATCH 4/4] controller: update for parsing JSON status X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Oct 2018 05:59:36 -0000 From: Yasufumi Ogawa Because the response of status of spp_nfv and spp_vm is changed to JSON format, update for parsing the JSON format. Signed-off-by: Yasufumi Ogawa --- src/controller/shell.py | 50 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/src/controller/shell.py b/src/controller/shell.py index fb30d5d..89c5c61 100644 --- a/src/controller/shell.py +++ b/src/controller/shell.py @@ -154,45 +154,27 @@ class Shell(cmd.Cmd, object): def print_sec_status(self, msg): """Parse and print message from SPP secondary - The format of sent message is expected as YAML like format as + The format of sent message is JSON and ended series of null + character "\x00". "ports" is a set of combinations of patches. - status: idling\nports: 'phy:0-phy:1,phy:1-null'\x00\x00.. + {"status":"idling","ports":[{"src":"phy:0", "dst": ...,]}'\x00\x00.. - 'ports' is a set of combinations of patches. The value is - encapsulated with "'" and ended series of null character "\x00". - If the destination is not defined, null is assigned. + If a port is not patched, the "dst" is set to "null". """ - msg = msg.replace("\x00", "").replace("'", "") # clean sec's msg - sec_attr = msg.split("\n") + msg = msg.replace("\x00", "") # clean sec's msg - # Do nothing if returned msg is not valid format. - if len(sec_attr) < 2: - return None - - status = sec_attr[0] - ports = sec_attr[1] - - # Printed result to which port info is appended. - res = status - - port_list = ports.split(' ')[1].split(',') - if port_list[0] == '': # port_list is [''] if there are no ports - res = '%s\nports: "no ports"' % res - else: - res = "%s\nports:\n" % res - tmp_list = [] - for port_ent in port_list: - if '-' in port_ent: - p1, p2 = port_ent.split('-') - if p2 == 'null': - tmp_list.append(" - '%s'" % p1) - else: - tmp_list.append(" - '%s -> %s'" % (p1, p2)) - tmp_list.sort() - res += "\n".join(tmp_list) - - print(res) + try: + sec_attr = json.loads(msg) + print('- status: %s' % sec_attr['status']) + print('- ports:') + cnt = 1 + for port in sec_attr['ports']: + print(' %d: %s -> %s' % (cnt, port['src'], port['dst'])) + cnt += 1 + except ValueError as err: + print('Invalid format: {0}.'.format(err)) + print(" '%s'" % msg) def command_primary(self, command): """Send command to primary process""" -- 2.7.4