Soft Patch Panel
 help / color / mirror / Atom feed
From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 4/4] controller: update for parsing JSON status
Date: Thu,  4 Oct 2018 14:59:18 +0900	[thread overview]
Message-ID: <20181004055918.5922-5-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20181004055918.5922-1-ogawa.yasufumi@lab.ntt.co.jp>

From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

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 <ogawa.yasufumi@lab.ntt.co.jp>
---
 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

      parent reply	other threads:[~2018-10-04  5:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-04  5:59 [spp] [PATCH 0/4] Change format of sec status to JSON ogawa.yasufumi
2018-10-04  5:59 ` [spp] [PATCH 1/4] shared: change sec status to JSON format ogawa.yasufumi
2018-10-04  5:59 ` [spp] [PATCH 2/4] spp_nfv: update retrieving status ogawa.yasufumi
2018-10-04  5:59 ` [spp] [PATCH 3/4] spp_vm: " ogawa.yasufumi
2018-10-04  5:59 ` ogawa.yasufumi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181004055918.5922-5-ogawa.yasufumi@lab.ntt.co.jp \
    --to=ogawa.yasufumi@lab.ntt.co.jp \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).