From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 9/9] controller: move bye command to SppBye
Date: Thu, 18 Oct 2018 20:25:18 +0900 [thread overview]
Message-ID: <20181018112518.77556-10-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20181018112518.77556-1-ogawa.yasufumi@lab.ntt.co.jp>
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
SppBye defines 'bye' command and its completion as in a separated
module. It is intended to be used from Shell, which is derived from
'cmd.Cmd'.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/controller/commands/bye.py | 48 ++++++++++++++++++++++++++++++++++++++++++
src/controller/shell.py | 44 ++++++++++----------------------------
2 files changed, 59 insertions(+), 33 deletions(-)
create mode 100644 src/controller/commands/bye.py
diff --git a/src/controller/commands/bye.py b/src/controller/commands/bye.py
new file mode 100644
index 0000000..e5ca3bb
--- /dev/null
+++ b/src/controller/commands/bye.py
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
+
+
+class SppBye(object):
+ """Exec SPP bye command.
+
+ SppBye class is intended to be used in Shell class as a delegator
+ for running 'bye' command.
+
+ 'self.command()' is called from do_bye() and 'self.complete()' is called
+ from complete_bye() of both of which is defined in Shell.
+ """
+
+ BYE_CMDS = ['sec', 'all']
+
+ def __init__(self, spp_ctl_cli, spp_primary, spp_secondary):
+ self.spp_ctl_cli = spp_ctl_cli
+ self.spp_primary = spp_primary
+ self.spp_secondary = spp_secondary
+
+ def run(self, args, sec_ids):
+
+ cmds = args.split(' ')
+ if cmds[0] == 'sec':
+ self.close_all_secondary(sec_ids)
+ elif cmds[0] == 'all':
+ print('Closing secondary ...')
+ self.close_all_secondary(sec_ids)
+ print('Closing primary ...')
+ self.spp_primary.run('exit')
+
+ def complete(self, text, line, begidx, endidx):
+
+ if not text:
+ completions = self.BYE_CMDS[:]
+ else:
+ completions = [p
+ for p in self.BYE_CMDS
+ if p.startswith(text)
+ ]
+ return completions
+
+ def close_all_secondary(self, sec_ids):
+ """Terminate all secondary processes."""
+
+ for i in sec_ids:
+ self.spp_secondary.run(i, 'exit')
diff --git a/src/controller/shell.py b/src/controller/shell.py
index bdc41fe..ec5f481 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -4,6 +4,7 @@
from __future__ import absolute_import
import cmd
+from .commands import bye
from .commands import pri
from .commands import sec
from .commands import topo
@@ -11,7 +12,6 @@ import os
import re
import readline
from .shell_lib import common
-from . import spp_common
from .spp_common import logger
import subprocess
@@ -28,8 +28,6 @@ class Shell(cmd.Cmd, object):
PORT_TYPES = ['phy', 'ring', 'vhost', 'pcap', 'nullpmd']
- BYE_CMDS = ['sec', 'all']
-
HIST_EXCEPT = ['bye', 'exit', 'history', 'redo']
PLUGIN_DIR = 'command'
@@ -49,6 +47,8 @@ class Shell(cmd.Cmd, object):
self.spp_topo = topo.SppTopo(self.spp_ctl_cli,
self.get_sec_ids('nfv'),
{}, self.topo_size)
+ self.spp_bye = bye.SppBye(self.spp_ctl_cli, self.spp_primary,
+ self.spp_secondary)
def default(self, line):
"""Define defualt behaviour.
@@ -104,15 +104,6 @@ class Shell(cmd.Cmd, object):
except IOError:
print('Error: Cannot open history file "%s"' % self.hist_file)
- def close_all_secondary(self):
- """Terminate all secondary processes."""
-
- tmp_list = []
- for i in spp_common.SECONDARY_LIST:
- tmp_list.append(i)
- for i in tmp_list:
- self.command_secondary(i, 'exit')
-
def print_status(self):
"""Display information about connected clients."""
@@ -403,7 +394,7 @@ class Shell(cmd.Cmd, object):
def complete_mkdir(self, text, line, begidx, endidx):
return common.compl_common(text, line)
- def do_bye(self, arg):
+ def do_bye(self, args):
"""Terminate SPP processes and controller.
There are three usages for terminating processes.
@@ -419,30 +410,17 @@ class Shell(cmd.Cmd, object):
spp > bye
"""
- cmds = arg.split(' ')
- if cmds[0] == 'sec':
- self.close_all_secondary()
- elif cmds[0] == 'all':
- print('Closing secondary ...')
- self.close_all_secondary()
- print('Closing primary ...')
- self.spp_primary.run('exit')
- elif cmds[0] == '':
- print('Thank you for using Soft Patch Panel')
- self.close()
+ cmds = args.split(' ')
+ if cmds[0] == '':
+ self.do_exit('')
return True
+ else: # 'all' or 'sec'
+ self.spp_bye.run(args, self.get_sec_ids('nfv'))
def complete_bye(self, text, line, begidx, endidx):
"""Completion for bye commands"""
- if not text:
- completions = self.BYE_CMDS[:]
- else:
- completions = [p
- for p in self.BYE_CMDS
- if p.startswith(text)
- ]
- return completions
+ return self.spp_bye.complete(text, line, begidx, endidx)
def do_cat(self, arg):
"""View contents of a file.
@@ -592,7 +570,7 @@ class Shell(cmd.Cmd, object):
label: vm1 subgraph: "vhost:1;vhost:2"
"""
- #logger.info("Topo initialized with sec IDs %s" % sec_ids)
+ # logger.info("Topo initialized with sec IDs %s" % sec_ids)
# delimiter of node in dot file
delim_node = '_'
--
2.13.1
prev parent reply other threads:[~2018-10-18 11:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-18 11:25 [spp] [PATCH 0/9] Change SPP controller to use spp-ctl ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 1/9] controller: add spp-ctl client for SPP controller ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 2/9] controller: change controller to use spp-ctl ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 3/9] spp-ctl: add IP address binding ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 4/9] controller: add IP address and port binding ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 5/9] controller: move pri command to SppPrimary ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 6/9] controller: move sec command to SppSecondary ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 7/9] controller: move topo command to SppTopo ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 8/9] controller: move topo_resize " ogawa.yasufumi
2018-10-18 11:25 ` 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=20181018112518.77556-10-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).