[spp] [PATCH 7/8] controller: revise completion of launch command

ogawa.yasufumi at lab.ntt.co.jp ogawa.yasufumi at lab.ntt.co.jp
Tue Jan 29 13:22:00 CET 2019


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

To help users by reducing input of launch command, change to generate
options automatically from given secondary ID.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi at lab.ntt.co.jp>
---
 src/controller/commands/pri.py | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/src/controller/commands/pri.py b/src/controller/commands/pri.py
index 577952c..7712ba2 100644
--- a/src/controller/commands/pri.py
+++ b/src/controller/commands/pri.py
@@ -136,7 +136,8 @@ class SppPrimary(object):
         candidates = []
         tokens = line.split(' ')
 
-        mytemplate = "-l 1,2 -m 512 -- -n {} -s {}"
+        base_core = 1  # shared among secondaries
+        mytemplate = "-l {},{} -m 512 -- {} {} -s {}"
 
         # Show sub commands
         if len(tokens) == 2:
@@ -156,8 +157,30 @@ class SppPrimary(object):
         elif len(tokens) == 5 and tokens[1] == 'launch':
             if (tokens[2] in spp_common.SEC_TYPES) and \
                     (int(tokens[3])-1 in range(spp_common.MAX_SECONDARY)):
+                ptype = tokens[2]
                 sid = tokens[3]
-                candidates = [mytemplate.format(sid, common.current_server_addr())]
+
+                if ptype == 'nfv':
+                    opt_sid = '-n'
+                else:
+                    opt_sid = '--client-id'
+
+                server_addr = common.current_server_addr()
+                server_addr = server_addr.replace('7777', '6666')
+
+                # Define rest of cores dynamically.
+                # TODO(yasufum) decide rest of cores considering used cores
+                if ptype == 'nfv':  # one core is enough
+                    rest_core = sid
+                elif ptype == 'vf':  # at least three cores
+                    rest_core = '{}-{}'.format(int(sid), int(sid)+2)
+                elif ptype == 'mirror':  # two cores
+                    rest_core = sid
+                elif ptype == 'pcap':  # at least two cores
+                    rest_core = '{}-{}'.format(int(sid), int(sid)+1)
+
+                candidates = [mytemplate.format(
+                    base_core, rest_core, opt_sid, sid, server_addr)]
 
         if not text:
             completions = candidates
@@ -166,8 +189,6 @@ class SppPrimary(object):
                            if p.startswith(text)
                            ]
 
-        #completions.append("nof_tokens:{}".format(len(tokens)))
-
         return completions
 
     def _get_sec_ids(self):
@@ -299,7 +320,7 @@ class SppPrimary(object):
         if res is not None:
             error_codes = self.spp_ctl_cli.rest_common_error_codes
             if res.status_code == 204:
-                print('Succeeded to launch {}:{}.'.format(
+                print('Send request to launch {}:{}.'.format(
                     proc_type, sec_id))
             elif res.status_code in error_codes:
                 pass
-- 
2.7.4



More information about the spp mailing list