From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mogw2335.ocn.ad.jp (mogw2335.ocn.ad.jp [202.234.254.37]) by dpdk.org (Postfix) with ESMTP id 0656A1B905 for ; Sun, 10 Feb 2019 04:08:28 +0100 (CET) Received: from mf-smf-unw009c3 (mf-smf-unw009c3.ocn.ad.jp [153.138.219.107]) by mogw2335.ocn.ad.jp (Postfix) with ESMTP id 9EDCA440483; Sun, 10 Feb 2019 12:08:26 +0900 (JST) Received: from ocn-vc-mts-204c1.ocn.ad.jp ([125.206.160.20]) by mf-smf-unw009c3 with ESMTP id sfMsgvFU7L2QJsfTmgGE7F; Sun, 10 Feb 2019 12:08:26 +0900 Received: from smtp.ocn.ne.jp ([153.149.227.135]) by ocn-vc-mts-204c1.ocn.ad.jp with ESMTP id sfTmgV2g9NcWasfTmgWT0A; Sun, 10 Feb 2019 12:08:26 +0900 Received: from localhost.localdomain (p1649004-ipngn15701marunouchi.tokyo.ocn.ne.jp [153.204.174.4]) by smtp.ocn.ne.jp (Postfix) with ESMTPA; Sun, 10 Feb 2019 12:08:26 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp Date: Sun, 10 Feb 2019 12:08:20 +0900 Message-Id: <1549768101-23049-9-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549768101-23049-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> References: <1549768101-23049-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> Subject: [spp] [PATCH v3 8/9] controlle: refactor pcap command 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: Sun, 10 Feb 2019 03:08:28 -0000 From: Yasufumi Ogawa * Correct mal-formatted status. * Correct wrong description of comments shown in help. * Change to use `format()` for printing. Signed-off-by: Yasufumi Ogawa --- 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