Soft Patch Panel
 help / color / mirror / Atom feed
* [spp] [PATCH 0/5] Refactor SPP controller
@ 2018-10-18 11:27 ogawa.yasufumi
  2018-10-18 11:27 ` [spp] [PATCH 1/5] controller: change name of plugins directory ogawa.yasufumi
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-18 11:27 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

This series of patches is for misc updates of SPP controller.

* Change the name of directory of dynamically loaded commands. It is
  named as 'command', but ambiguous with 'commands' directory of
  delegator classes. So its name is changed to 'plugins'.

* Terminate SPP controller while launching if spp-ctl is not running
  because spp-ctl must be required for requesting and it is no meaning
  to run just SPP controller.

* Move '.spp_history' to home directory to be referred from any of
  directory.

* Move to the definition of port types to 'spp_common.py'.

* Remove SECONDARY_LIST in 'spp_common.py' because it is not used
  anymore.

Yasufumi Ogawa (5):
  controller: change name of plugins directory
  controller: exit controller if spp-ctl not running
  controller: move spp_history to home directory
  controller: move PORT_TYPES to spp_common
  controller: remove SECONDARY_LIST

 src/controller/commands/topo.py                 | 19 ++++++-------
 src/controller/{command => plugins}/__init__.py |  0
 src/controller/{command => plugins}/hello.py    |  0
 src/controller/shell.py                         | 37 +++++++++++--------------
 src/controller/spp.py                           | 14 ++++++++--
 src/controller/spp_common.py                    | 10 +++----
 src/controller/spp_ctl_client.py                |  6 ++++
 7 files changed, 47 insertions(+), 39 deletions(-)
 rename src/controller/{command => plugins}/__init__.py (100%)
 rename src/controller/{command => plugins}/hello.py (100%)

-- 
2.13.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [spp] [PATCH 1/5] controller: change name of plugins directory
  2018-10-18 11:27 [spp] [PATCH 0/5] Refactor SPP controller ogawa.yasufumi
@ 2018-10-18 11:27 ` ogawa.yasufumi
  2018-10-18 11:27 ` [spp] [PATCH 2/5] controller: exit controller if spp-ctl not running ogawa.yasufumi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-18 11:27 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

Refactor directory name of command plugins from 'command' to 'plugins'
because commands of not plugin are moved to 'commands' directory and
the name of plugins is ambiguous from 'command'.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/{command => plugins}/__init__.py |  0
 src/controller/{command => plugins}/hello.py    |  0
 src/controller/shell.py                         | 15 +++++++--------
 3 files changed, 7 insertions(+), 8 deletions(-)
 rename src/controller/{command => plugins}/__init__.py (100%)
 rename src/controller/{command => plugins}/hello.py (100%)

diff --git a/src/controller/command/__init__.py b/src/controller/plugins/__init__.py
similarity index 100%
rename from src/controller/command/__init__.py
rename to src/controller/plugins/__init__.py
diff --git a/src/controller/command/hello.py b/src/controller/plugins/hello.py
similarity index 100%
rename from src/controller/command/hello.py
rename to src/controller/plugins/hello.py
diff --git a/src/controller/shell.py b/src/controller/shell.py
index ec5f481..28ae86e 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -30,7 +30,7 @@ class Shell(cmd.Cmd, object):
 
     HIST_EXCEPT = ['bye', 'exit', 'history', 'redo']
 
-    PLUGIN_DIR = 'command'
+    PLUGIN_DIR = 'plugins'
     topo_size = '60%'
 
     # setup history file
@@ -669,24 +669,23 @@ class Shell(cmd.Cmd, object):
     def do_load_cmd(self, args):
         """Load command plugin.
 
-        Path of plugin file is 'spp/src/controller/command'.
+        Path of plugin file is 'spp/src/controller/plugins'.
 
-        spp > load hello
+        spp > load_cmd hello
         """
 
         args = re.sub(',', ' ', args)
         args = re.sub(r'\s+', ' ', args)
         list_args = args.split(' ')
 
-        libdir = 'command'
+        libdir = self.PLUGIN_DIR
         mod_name = list_args[0]
         method_name = 'do_%s' % mod_name
-        loaded = '%s.%s' % (libdir, mod_name)
-        exec('import %s' % loaded)
-        do_cmd = '%s.%s' % (loaded, method_name)
+        exec('from .%s import %s' % (libdir, mod_name))
+        do_cmd = '%s.%s' % (mod_name, method_name)
         exec('Shell.%s = %s' % (method_name, do_cmd))
 
-        print("Module '%s' loaded." % loaded)
+        print("Module '%s' loaded." % mod_name)
 
     def complete_load_cmd(self, text, line, begidx, endidx):
         """Complete command plugins
-- 
2.13.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [spp] [PATCH 2/5] controller: exit controller if spp-ctl not running
  2018-10-18 11:27 [spp] [PATCH 0/5] Refactor SPP controller ogawa.yasufumi
  2018-10-18 11:27 ` [spp] [PATCH 1/5] controller: change name of plugins directory ogawa.yasufumi
@ 2018-10-18 11:27 ` ogawa.yasufumi
  2018-10-18 11:27 ` [spp] [PATCH 3/5] controller: move spp_history to home directory ogawa.yasufumi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-18 11:27 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

SPP controller expects spp-ctl is running, so it should notice a user
while launching if it cannot access to spp-ctl. SPP controller already
does notify, but not while launching.

This update is to add 'is_server_running()' to SppCtlClient class to
check if spp-ctl is running. It also fixes incorrect notify of SppTopo
if it cannot access to spp-ctl.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/commands/topo.py  | 19 +++++++++----------
 src/controller/shell.py          |  6 ++----
 src/controller/spp.py            | 13 ++++++++++---
 src/controller/spp_ctl_client.py |  6 ++++++
 4 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/src/controller/commands/topo.py b/src/controller/commands/topo.py
index 53cc8b5..e8afa4a 100644
--- a/src/controller/commands/topo.py
+++ b/src/controller/commands/topo.py
@@ -22,32 +22,31 @@ class SppTopo(object):
 
     delim_node = '_'
 
-    def __init__(self, spp_ctl_cli, sec_ids, subgraphs, size):
+    def __init__(self, spp_ctl_cli, subgraphs, size):
         self.spp_ctl_cli = spp_ctl_cli
-        self.sec_ids = sec_ids
         self.subgraphs = subgraphs
         self.graph_size = size
 
-    def run(self, args):
+    def run(self, args, sec_ids):
         args_ary = args.split()
         if len(args_ary) == 0:
             print("Usage: topo dst [ftype]")
             return False
         elif (args_ary[0] == "term") or (args_ary[0] == "http"):
-            self.show(args_ary[0], self.graph_size)
+            self.show(args_ary[0], sec_ids, self.graph_size)
         elif len(args_ary) == 1:
             ftype = args_ary[0].split(".")[-1]
-            self.output(args_ary[0], ftype)
+            self.output(args_ary[0], sec_ids, ftype)
         elif len(args_ary) == 2:
-            self.output(args_ary[0], args_ary[1])
+            self.output(args_ary[0], sec_ids, args_ary[1])
         else:
             print("Usage: topo dst [ftype]")
 
-    def show(self, dtype, size):
+    def show(self, dtype, sec_ids, size):
         res_ary = []
         error_codes = self.spp_ctl_cli.rest_common_error_codes
 
-        for sec_id in self.sec_ids:
+        for sec_id in sec_ids:
             res = self.spp_ctl_cli.get('nfvs/%d' % sec_id)
             if res.status_code == 200:
                 res_ary.append(res.json())
@@ -65,11 +64,11 @@ class SppTopo(object):
         else:
             print("Invalid file type")
 
-    def output(self, fname, ftype="dot"):
+    def output(self, fname, sec_ids, ftype="dot"):
         res_ary = []
         error_codes = self.spp_ctl_cli.rest_common_error_codes
 
-        for sec_id in self.sec_ids:
+        for sec_id in sec_ids:
             res = self.spp_ctl_cli.get('nfvs/%d' % sec_id)
             if res.status_code == 200:
                 res_ary.append(res.json())
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 28ae86e..2c170e9 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -44,9 +44,7 @@ class Shell(cmd.Cmd, object):
         self.spp_ctl_cli = spp_ctl_cli
         self.spp_primary = pri.SppPrimary(self.spp_ctl_cli)
         self.spp_secondary = sec.SppSecondary(self.spp_ctl_cli)
-        self.spp_topo = topo.SppTopo(self.spp_ctl_cli,
-                                     self.get_sec_ids('nfv'),
-                                     {}, self.topo_size)
+        self.spp_topo = topo.SppTopo(self.spp_ctl_cli, {}, self.topo_size)
         self.spp_bye = bye.SppBye(self.spp_ctl_cli, self.spp_primary,
                                   self.spp_secondary)
 
@@ -660,7 +658,7 @@ class Shell(cmd.Cmd, object):
         spp > topo network_conf.js# text
         """
 
-        self.spp_topo.run(args)
+        self.spp_topo.run(args, self.get_sec_ids('nfv'))
 
     def complete_topo(self, text, line, begidx, endidx):
 
diff --git a/src/controller/spp.py b/src/controller/spp.py
index 6b0d99c..99cdda3 100644
--- a/src/controller/spp.py
+++ b/src/controller/spp.py
@@ -19,9 +19,16 @@ def main(argv):
                         help='bind address, default=7777')
     args = parser.parse_args()
 
-    shell = Shell(spp_ctl_client.SppCtlClient(args.bind_addr, args.api_port))
-    shell.cmdloop()
-    shell = None
+    try:
+        spp_ctl_cli = spp_ctl_client.SppCtlClient(args.bind_addr, args.api_port)
+        if spp_ctl_cli.is_server_running() == False:
+            print('Is not spp-ctl running, nor correct IP address?')
+            exit()
+        shell = Shell(spp_ctl_cli)
+        shell.cmdloop()
+        shell = None
+    except Exception as e:
+        print(e)
 
 
 if __name__ == "__main__":
diff --git a/src/controller/spp_ctl_client.py b/src/controller/spp_ctl_client.py
index 8a88fa4..0f8687a 100644
--- a/src/controller/spp_ctl_client.py
+++ b/src/controller/spp_ctl_client.py
@@ -56,3 +56,9 @@ class SppCtlClient(object):
     def delete(self, req):
         url = '%s/%s' % (self.base_url, req)
         return requests.delete(url)
+
+    def is_server_running(self):
+        if self.get('processes') is None:
+            return False
+        else:
+            return True
-- 
2.13.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [spp] [PATCH 3/5] controller: move spp_history to home directory
  2018-10-18 11:27 [spp] [PATCH 0/5] Refactor SPP controller ogawa.yasufumi
  2018-10-18 11:27 ` [spp] [PATCH 1/5] controller: change name of plugins directory ogawa.yasufumi
  2018-10-18 11:27 ` [spp] [PATCH 2/5] controller: exit controller if spp-ctl not running ogawa.yasufumi
@ 2018-10-18 11:27 ` ogawa.yasufumi
  2018-10-18 11:27 ` [spp] [PATCH 4/5] controller: move PORT_TYPES to spp_common ogawa.yasufumi
  2018-10-18 11:27 ` [spp] [PATCH 5/5] controller: remove SECONDARY_LIST ogawa.yasufumi
  4 siblings, 0 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-18 11:27 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

Move history file from project root to user's home directory as
'~/.spp_history'.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/shell.py | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/controller/shell.py b/src/controller/shell.py
index 2c170e9..383d2f1 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -19,17 +19,15 @@ import subprocess
 class Shell(cmd.Cmd, object):
     """SPP command prompt."""
 
-    # TODO(yasufum) move hist_file to $HOME as default
-    hist_file = '.spp_history'
+    recorded_file = None
+    hist_file = os.path.expanduser('~/.spp_history')
+    HIST_EXCEPT = ['bye', 'exit', 'history', 'redo']
 
     intro = 'Welcome to the spp.   Type help or ? to list commands.\n'
     prompt = 'spp > '
-    recorded_file = None
 
     PORT_TYPES = ['phy', 'ring', 'vhost', 'pcap', 'nullpmd']
 
-    HIST_EXCEPT = ['bye', 'exit', 'history', 'redo']
-
     PLUGIN_DIR = 'plugins'
     topo_size = '60%'
 
-- 
2.13.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [spp] [PATCH 4/5] controller: move PORT_TYPES to spp_common
  2018-10-18 11:27 [spp] [PATCH 0/5] Refactor SPP controller ogawa.yasufumi
                   ` (2 preceding siblings ...)
  2018-10-18 11:27 ` [spp] [PATCH 3/5] controller: move spp_history to home directory ogawa.yasufumi
@ 2018-10-18 11:27 ` ogawa.yasufumi
  2018-10-18 11:27 ` [spp] [PATCH 5/5] controller: remove SECONDARY_LIST ogawa.yasufumi
  4 siblings, 0 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-18 11:27 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

Move PORT_TYPES defining all of port types in SPP to spp_common module.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/shell.py      |  8 ++++----
 src/controller/spp.py        |  5 +++--
 src/controller/spp_common.py | 12 +++++++-----
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/controller/shell.py b/src/controller/shell.py
index 383d2f1..9fce6f4 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -12,6 +12,7 @@ import os
 import re
 import readline
 from .shell_lib import common
+from . import spp_common
 from .spp_common import logger
 import subprocess
 
@@ -26,8 +27,6 @@ class Shell(cmd.Cmd, object):
     intro = 'Welcome to the spp.   Type help or ? to list commands.\n'
     prompt = 'spp > '
 
-    PORT_TYPES = ['phy', 'ring', 'vhost', 'pcap', 'nullpmd']
-
     PLUGIN_DIR = 'plugins'
     topo_size = '60%'
 
@@ -148,8 +147,9 @@ class Shell(cmd.Cmd, object):
             if re.match(ptn, id1) and re.match(ptn, id2):
                 pt1 = id1.split(delim)[0]
                 pt2 = id2.split(delim)[0]
-                if (pt1 in self.PORT_TYPES) and (pt2 in self.PORT_TYPES):
-                    return True
+                if (pt1 in spp_common.PORT_TYPES) \
+                        and (pt2 in spp_common.PORT_TYPES):
+                            return True
         return False
 
     def check_sec_cmds(self, cmds):
diff --git a/src/controller/spp.py b/src/controller/spp.py
index 99cdda3..5211ec9 100644
--- a/src/controller/spp.py
+++ b/src/controller/spp.py
@@ -20,8 +20,9 @@ def main(argv):
     args = parser.parse_args()
 
     try:
-        spp_ctl_cli = spp_ctl_client.SppCtlClient(args.bind_addr, args.api_port)
-        if spp_ctl_cli.is_server_running() == False:
+        spp_ctl_cli = spp_ctl_client.SppCtlClient(args.bind_addr,
+                                                  args.api_port)
+        if spp_ctl_cli.is_server_running() is False:
             print('Is not spp-ctl running, nor correct IP address?')
             exit()
         shell = Shell(spp_ctl_cli)
diff --git a/src/controller/spp_common.py b/src/controller/spp_common.py
index 809bee5..20c6bc8 100644
--- a/src/controller/spp_common.py
+++ b/src/controller/spp_common.py
@@ -5,6 +5,13 @@
 import logging
 import os
 
+SECONDARY_LIST = []
+
+PORT_TYPES = ['phy', 'ring', 'vhost', 'pcap', 'nullpmd']
+
+# Maximum num of sock queues for secondaries
+MAX_SECONDARY = 16
+
 # Setup logger object
 logger = logging.getLogger(__name__)
 # handler = logging.StreamHandler()
@@ -18,8 +25,3 @@ formatter = logging.Formatter(
 handler.setFormatter(formatter)
 logger.setLevel(logging.DEBUG)
 logger.addHandler(handler)
-
-SECONDARY_LIST = []
-
-# Maximum num of sock queues for secondaries
-MAX_SECONDARY = 16
-- 
2.13.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [spp] [PATCH 5/5] controller: remove SECONDARY_LIST
  2018-10-18 11:27 [spp] [PATCH 0/5] Refactor SPP controller ogawa.yasufumi
                   ` (3 preceding siblings ...)
  2018-10-18 11:27 ` [spp] [PATCH 4/5] controller: move PORT_TYPES to spp_common ogawa.yasufumi
@ 2018-10-18 11:27 ` ogawa.yasufumi
  4 siblings, 0 replies; 6+ messages in thread
From: ogawa.yasufumi @ 2018-10-18 11:27 UTC (permalink / raw)
  To: spp, ferruh.yigit, ogawa.yasufumi

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

SECONDARY_LIST is a list of secondary IDs running on, but no need
anymore because running secondary IDs can be retrieved from spp-ctl.
This update is to remove SECONDARY_LIST.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
 src/controller/spp_common.py | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/controller/spp_common.py b/src/controller/spp_common.py
index 20c6bc8..1a15bcc 100644
--- a/src/controller/spp_common.py
+++ b/src/controller/spp_common.py
@@ -5,8 +5,6 @@
 import logging
 import os
 
-SECONDARY_LIST = []
-
 PORT_TYPES = ['phy', 'ring', 'vhost', 'pcap', 'nullpmd']
 
 # Maximum num of sock queues for secondaries
-- 
2.13.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-10-18 11:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-18 11:27 [spp] [PATCH 0/5] Refactor SPP controller ogawa.yasufumi
2018-10-18 11:27 ` [spp] [PATCH 1/5] controller: change name of plugins directory ogawa.yasufumi
2018-10-18 11:27 ` [spp] [PATCH 2/5] controller: exit controller if spp-ctl not running ogawa.yasufumi
2018-10-18 11:27 ` [spp] [PATCH 3/5] controller: move spp_history to home directory ogawa.yasufumi
2018-10-18 11:27 ` [spp] [PATCH 4/5] controller: move PORT_TYPES to spp_common ogawa.yasufumi
2018-10-18 11:27 ` [spp] [PATCH 5/5] controller: remove SECONDARY_LIST ogawa.yasufumi

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).