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 v3 8/9] controlle: refactor pcap command
Date: Sun, 10 Feb 2019 12:08:20 +0900	[thread overview]
Message-ID: <1549768101-23049-9-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <1549768101-23049-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp>

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

* Correct mal-formatted status.

* Correct wrong description of comments shown in help.

* Change to use `format()` for printing.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/commands/pcap.py | 24 ++++++++++--------------
 src/controller/shell.py         | 22 ++++++----------------
 2 files changed, 16 insertions(+), 30 deletions(-)

diff --git a/src/controller/commands/pcap.py b/src/controller/commands/pcap.py
index 89a1a5f..d06327b 100644
--- a/src/controller/commands/pcap.py
+++ b/src/controller/commands/pcap.py
@@ -13,11 +13,7 @@ class SppPcap(object):
     """
 
     # All of commands and sub-commands used for validation and completion.
-    PCAP_CMDS = {
-            'status': None,
-            'start': None,
-            'stop': None,
-            'exit': None}
+    PCAP_CMDS = { 'status': None, 'start': None, 'stop': None, 'exit': None}
 
     WORKER_TYPES = ['receive', 'write']
 
@@ -104,14 +100,14 @@ class SppPcap(object):
             if res is not None:
                 error_codes = self.spp_ctl_cli.rest_common_error_codes
                 if res.status_code == 204:
-                    print("Exit pcap %d." % (self.sec_id))
+                    print("Exit pcap {}.".format(self.sec_id))
                 elif res.status_code in error_codes:
                     pass
                 else:
                     print('Error: unknown response.')
 
         else:
-            print('Invalid command "%s".' % cmd)
+            print('Invalid command "{}".'.format(cmd))
 
     def print_status(self, json_obj):
         """Parse and print message from SPP PCAP.
@@ -134,21 +130,21 @@ class SppPcap(object):
         """
 
         # client id and status
-        print('  - client-id: %d' % json_obj['client-id'])
-        print('  - status: %s' % json_obj['status'])
+        print('  - client-id: {}'.format(json_obj['client-id']))
+        print('  - status: {}'.format(json_obj['status']))
 
         # Core
         for worker in json_obj['core']:
             if 'role' in worker.keys():
-                print("  - core:%d %s" % (
-                        worker['core'], worker['role']))
+                print("  - core:{core_id} {role}".format(
+                        core_id=worker['core'], role=worker['role']))
 
                 if worker['role'] == 'receive':
                     pt = worker['rx_port'][0]['port']
-                    msg = '    - %s:%s'
-                    print(msg % ('rx', pt))
+                    msg = '    - {direction}: {res_id}'
+                    print(msg.format(direction='rx', res_id=pt))
                 else:
-                    print('    - filename: %s' % worker['filename'])
+                    print('    - filename: {}'.format(worker['filename']))
 
     def complete(self, sec_ids, text, line, begidx, endidx):
         """Completion for spp_pcap commands.
diff --git a/src/controller/shell.py b/src/controller/shell.py
index ed64847..ec4aaab 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -585,31 +585,21 @@ class Shell(cmd.Cmd, object):
     def do_pcap(self, cmd):
         """Send a command to spp_pcap.
 
-        spp_pcap is a secondary process for duplicating incoming
-        packets to be used as similar to TaaS in OpenStack. This
-        command has four sub commands.
-          * status
-          * start
-          * stop
-          * exit
+        Spp_pcap is a secondary process for capturing incoming packets.
 
-        Each of sub commands other than 'status' takes several parameters
-        for detailed operations. Notice that 'start' for launching a worker
-        is replaced with 'stop' for terminating. 'exit' for spp_pcap
-        terminating.
+        'start' for launching a worker is replaced with 'stop' for
+        terminating. 'exit' for spp_pcap terminating.
 
         Examples:
 
         # (1) show status of worker threads and resources
         spp > pcap 1; status
 
-        # (2) launch capture thread
+        # (2) launch or terminate capture thread
         spp > pcap 1; start
-
-        # (3) terminate capture thread
         spp > pcap 1; stop
 
-        # (4) terminate spp_pcap secondaryd
+        # (3) terminate spp_pcap secondaryd
         spp > pcap 1; exit
         """
 
@@ -621,7 +611,7 @@ class Shell(cmd.Cmd, object):
         elif str.isdigit(cmds[0]):
             self.spp_pcaps[int(cmds[0])].run(cmds[1])
         else:
-            print('Invalid command: %s' % tmparg)
+            print('Invalid command: {}'.format(tmparg))
 
     def complete_pcap(self, text, line, begidx, endidx):
         """Completion for pcap command"""
-- 
2.7.4

  parent reply	other threads:[~2019-02-10  3:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-10  3:08 [spp] [PATCH v3 0/9] Introduce spp_pcap ogawa.yasufumi
2019-02-10  3:08 ` [spp] [PATCH v3 1/9] spp_pcap: add command main ogawa.yasufumi
2019-02-10  3:08 ` [spp] [PATCH v3 2/9] spp_pcap: add command parser functions ogawa.yasufumi
2019-02-10  3:08 ` [spp] [PATCH v3 3/9] spp_pcap: add management data and utilities ogawa.yasufumi
2019-02-10  3:08 ` [spp] [PATCH v3 4/9] spp_pcap: add main and related functions ogawa.yasufumi
2019-02-10  3:08 ` [spp] [PATCH v3 5/9] spp_pcap: update Makefile ogawa.yasufumi
2019-02-10  3:08 ` [spp] [PATCH v3 6/9] controller: add SppPcap class ogawa.yasufumi
2019-02-10  3:08 ` [spp] [PATCH v3 7/9] controller: add pcap command to SPP controller ogawa.yasufumi
2019-02-10  3:08 ` ogawa.yasufumi [this message]
2019-02-10  3:08 ` [spp] [PATCH v3 9/9] controller: fix init of pcap instances ogawa.yasufumi
2019-02-13  5:55 ` [spp] [PATCH v3 0/9] Introduce spp_pcap Yasufumi Ogawa

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=1549768101-23049-9-git-send-email-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).