Soft Patch Panel
 help / color / mirror / Atom feed
* [spp] [PATCH] controller: move completion of pri launch
@ 2019-06-24 10:45 yasufum.o
  0 siblings, 0 replies; only message in thread
From: yasufum.o @ 2019-06-24 10:45 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This update is to move completion of `pri; launch` command defined in
complete() method to out side and add new method _setup_launch_opts()
because it is getting long.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/controller/commands/pri.py | 152 +++++++++++++++++----------------
 1 file changed, 78 insertions(+), 74 deletions(-)

diff --git a/src/controller/commands/pri.py b/src/controller/commands/pri.py
index 6089137..97f8780 100644
--- a/src/controller/commands/pri.py
+++ b/src/controller/commands/pri.py
@@ -155,6 +155,83 @@ class SppPrimary(object):
                     rid=rports['id'], rx=rports['rx'], tx=rports['tx'],
                     rx_drop=rports['rx_drop'], tx_drop=rports['tx_drop']))
 
+    def _setup_launch_opts(self, tokens, cli_config):
+        """Make options for launch cmd from config params."""
+
+        if 'max_secondary' in cli_config.keys():
+            max_secondary = int(cli_config['max_secondary']['val'])
+
+            if (tokens[2] in spp_common.SEC_TYPES) and \
+                    (int(tokens[3])-1 in range(max_secondary)):
+                ptype = tokens[2]
+                sid = tokens[3]
+
+                if ptype == 'nfv':
+                    opt_sid = '-n'
+                else:
+                    opt_sid = '--client-id'
+
+                # Need to replace port from `7777` of spp-ctl to `6666`
+                # of secondary process.
+                server_addr = common.current_server_addr()
+                server_addr = server_addr.replace('7777', '6666')
+
+                # Lcore ID of worker lcore starts from sec ID in
+                # default.
+                lcore_base = int(sid)
+
+                # Define rest of worker lcores from config dynamically.
+                if ptype == 'nfv':  # one worker lcore is enough
+                    if 'sec_nfv_nof_lcores' in cli_config.keys():
+                        tmpkey = 'sec_nfv_nof_lcores'
+                        nof_workers = int(
+                                cli_config[tmpkey]['val'])
+
+                elif ptype == 'vf':
+                    if 'sec_vf_nof_lcores' in cli_config.keys():
+                        nof_workers = int(
+                                cli_config['sec_vf_nof_lcores']['val'])
+
+                elif ptype == 'mirror':  # two worker cores
+                    if 'sec_mirror_nof_lcores' in cli_config.keys():
+                        tmpkey = 'sec_mirror_nof_lcores'
+                        nof_workers = int(
+                                cli_config[tmpkey]['val'])
+
+                elif ptype == 'pcap':  # at least two worker cores
+                    if 'sec_pcap_nof_lcores' in cli_config.keys():
+                        tmpkey = 'sec_pcap_nof_lcores'
+                        nof_workers = int(
+                                cli_config[tmpkey]['val'])
+
+                    if 'sec_pcap_port' in cli_config.keys():
+                        temp = '-c {}'.format(
+                                cli_config['sec_pcap_port']['val'])
+
+                        self.launch_template = '{} {}'.format(
+                            self.launch_template, temp)
+
+                last_core = lcore_base + nof_workers - 1
+
+                # Decide lcore option based on configured number of
+                # lcores.
+                if last_core == lcore_base:
+                    rest_core = '{}'.format(last_core)
+                else:
+                    rest_core = '{}-{}'.format(lcore_base, last_core)
+
+                temp = self._setup_launch_template(
+                        cli_config, self.launch_template)
+                candidates = [temp.format(
+                    wlcores=rest_core, opt_sid=opt_sid, sid=sid,
+                    sec_addr=server_addr)]
+        else:
+            logger.error(
+                    'Error: max_secondary is not defined in config')
+            candidates = []
+
+        return candidates
+
     # TODO(yasufum) add checking for cli_config has keys
     def complete(self, text, line, begidx, endidx, cli_config):
         """Completion for primary process commands.
@@ -191,80 +268,7 @@ class SppPrimary(object):
                     candidates = []
 
             elif len(tokens) == 5 and tokens[1] == 'launch':
-                # TODO(yasufum) move this long completion to method.
-
-                if 'max_secondary' in cli_config.keys():
-                    max_secondary = int(cli_config['max_secondary']['val'])
-
-                    if (tokens[2] in spp_common.SEC_TYPES) and \
-                            (int(tokens[3])-1 in range(max_secondary)):
-                        ptype = tokens[2]
-                        sid = tokens[3]
-
-                        if ptype == 'nfv':
-                            opt_sid = '-n'
-                        else:
-                            opt_sid = '--client-id'
-
-                        # Need to replace port from `7777` of spp-ctl to `6666`
-                        # of secondary process.
-                        server_addr = common.current_server_addr()
-                        server_addr = server_addr.replace('7777', '6666')
-
-                        # Lcore ID of worker lcore starts from sec ID in
-                        # default.
-                        lcore_base = int(sid)
-
-                        # Define rest of worker lcores from config dynamically.
-                        if ptype == 'nfv':  # one worker lcore is enough
-                            if 'sec_nfv_nof_lcores' in cli_config.keys():
-                                tmpkey = 'sec_nfv_nof_lcores'
-                                nof_workers = int(
-                                        cli_config[tmpkey]['val'])
-
-                        elif ptype == 'vf':
-                            if 'sec_vf_nof_lcores' in cli_config.keys():
-                                nof_workers = int(
-                                        cli_config['sec_vf_nof_lcores']['val'])
-
-                        elif ptype == 'mirror':  # two worker cores
-                            if 'sec_mirror_nof_lcores' in cli_config.keys():
-                                tmpkey = 'sec_mirror_nof_lcores'
-                                nof_workers = int(
-                                        cli_config[tmpkey]['val'])
-
-                        elif ptype == 'pcap':  # at least two worker cores
-                            if 'sec_pcap_nof_lcores' in cli_config.keys():
-                                tmpkey = 'sec_pcap_nof_lcores'
-                                nof_workers = int(
-                                        cli_config[tmpkey]['val'])
-
-                            if 'sec_pcap_port' in cli_config.keys():
-                                temp = '-c {}'.format(
-                                        cli_config['sec_pcap_port']['val'])
-
-                                self.launch_template = '{} {}'.format(
-                                    self.launch_template, temp)
-
-                        last_core = lcore_base + nof_workers - 1
-
-                        # Decide lcore option based on configured number of
-                        # lcores.
-                        if last_core == lcore_base:
-                            rest_core = '{}'.format(last_core)
-                        else:
-                            rest_core = '{}-{}'.format(lcore_base, last_core)
-
-                        temp = self._setup_launch_template(
-                                cli_config, self.launch_template)
-                        candidates = [temp.format(
-                            wlcores=rest_core, opt_sid=opt_sid, sid=sid,
-                            sec_addr=server_addr)]
-
-                else:
-                    logger.error(
-                            'Error: max_secondary is not defined in config')
-                    candidates = []
+                candidates = self._setup_launch_opts(tokens, cli_config)
 
         if not text:
             completions = candidates
-- 
2.17.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-06-24 10:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24 10:45 [spp] [PATCH] controller: move completion of pri launch yasufum.o

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