[spp] [PATCH 1/2] controller: add exit command to vf and mirror
ogawa.yasufumi at lab.ntt.co.jp
ogawa.yasufumi at lab.ntt.co.jp
Fri Dec 21 10:26:18 CET 2018
From: Yasufumi Ogawa <ogawa.yasufumi at lab.ntt.co.jp>
Since `exit` is added to spp_vf and spp_mirror, add `exit` command to
CLI. `bye` command is also updated to terminate all of secondaries
including spp_vf and spp_mirror at once.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi at lab.ntt.co.jp>
---
src/controller/commands/bye.py | 6 ++----
src/controller/commands/mirror.py | 16 ++++++++++++++++
src/controller/commands/vf.py | 16 ++++++++++++++++
3 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/src/controller/commands/bye.py b/src/controller/commands/bye.py
index af77b08..cd14961 100644
--- a/src/controller/commands/bye.py
+++ b/src/controller/commands/bye.py
@@ -45,7 +45,5 @@ class SppBye(object):
"""Terminate all secondary processes."""
for sec_type, spp_procs in spp_secondaries.items():
- # TODO(yasufum) Remove if they support exit command.
- if not (sec_type in ['vf', 'mirror']):
- for sec in spp_procs.values():
- sec.run('exit')
+ for sec in spp_procs.values():
+ sec.run('exit')
diff --git a/src/controller/commands/mirror.py b/src/controller/commands/mirror.py
index fcc630a..a01e1eb 100644
--- a/src/controller/commands/mirror.py
+++ b/src/controller/commands/mirror.py
@@ -69,6 +69,9 @@ class SppMirror(object):
elif cmd == 'port':
self._run_port(params)
+ elif cmd == 'exit':
+ self._run_exit()
+
else:
print('Invalid command "%s".' % cmd)
@@ -272,6 +275,19 @@ class SppMirror(object):
else:
print('Error: unknown response.')
+ def _run_exit(self):
+ """Run `exit` command."""
+
+ res = self.spp_ctl_cli.delete('mirrors/%d' % self.sec_id)
+ if res is not None:
+ error_codes = self.spp_ctl_cli.rest_common_error_codes
+ if res.status_code == 204:
+ print('Exit mirror %d.' % self.sec_id)
+ elif res.status_code in error_codes:
+ pass
+ else:
+ print('Error: unknown response.')
+
def _compl_component(self, sub_tokens):
if len(sub_tokens) < 6:
subsub_cmds = ['start', 'stop']
diff --git a/src/controller/commands/vf.py b/src/controller/commands/vf.py
index 8828110..01795a5 100644
--- a/src/controller/commands/vf.py
+++ b/src/controller/commands/vf.py
@@ -73,6 +73,9 @@ class SppVf(object):
elif cmd == 'classifier_table':
self._run_cls_table(params)
+ elif cmd == 'exit':
+ self._run_exit()
+
else:
print('Invalid command "%s".' % cmd)
@@ -347,6 +350,19 @@ class SppVf(object):
else:
print('Error: unknown response.')
+ def _run_exit(self):
+ """Run `exit` command."""
+
+ res = self.spp_ctl_cli.delete('vfs/%d' % self.sec_id)
+ if res is not None:
+ error_codes = self.spp_ctl_cli.rest_common_error_codes
+ if res.status_code == 204:
+ print('Exit vf %d.' % self.sec_id)
+ elif res.status_code in error_codes:
+ pass
+ else:
+ print('Error: unknown response.')
+
def _compl_component(self, sub_tokens):
if len(sub_tokens) < 6:
subsub_cmds = ['start', 'stop']
--
2.7.4
More information about the spp
mailing list