[spp] [PATCH v2 3/5] controller: change pri exit cmd to call REST API
ogawa.yasufumi at lab.ntt.co.jp
ogawa.yasufumi at lab.ntt.co.jp
Fri Nov 9 04:21:36 CET 2018
From: Yasufumi Ogawa <ogawa.yasufumi at lab.ntt.co.jp>
To send `exit` command to spp_primary, change to call REST API of
spp-ctl.
This patch includes update for removing `exit` from `pri` command
to avoid terminating spp_primary while running secondary processes.
Use `bye all` command for graceful terminating.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi at lab.ntt.co.jp>
---
src/controller/commands/bye.py | 2 +-
src/controller/commands/pri.py | 16 ++++++++++++----
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/controller/commands/bye.py b/src/controller/commands/bye.py
index e5ca3bb..3ffc259 100644
--- a/src/controller/commands/bye.py
+++ b/src/controller/commands/bye.py
@@ -28,7 +28,7 @@ class SppBye(object):
print('Closing secondary ...')
self.close_all_secondary(sec_ids)
print('Closing primary ...')
- self.spp_primary.run('exit')
+ self.spp_primary.do_exit()
def complete(self, text, line, begidx, endidx):
diff --git a/src/controller/commands/pri.py b/src/controller/commands/pri.py
index b51138d..51da7ab 100644
--- a/src/controller/commands/pri.py
+++ b/src/controller/commands/pri.py
@@ -13,7 +13,7 @@ class SppPrimary(object):
"""
# All of primary commands used for validation and completion.
- PRI_CMDS = ['status', 'exit', 'clear']
+ PRI_CMDS = ['status', 'clear']
def __init__(self, spp_ctl_cli):
self.spp_ctl_cli = spp_ctl_cli
@@ -46,12 +46,20 @@ class SppPrimary(object):
else:
print('Error: unknown response.')
- elif cmd == 'exit':
- print('"pri; exit" is deprecated.')
-
else:
print('Invalid pri command!')
+ def do_exit(self):
+ res = self.spp_ctl_cli.delete('primary')
+ if res is not None:
+ error_codes = self.spp_ctl_cli.rest_common_error_codes
+ if res.status_code == 204:
+ print('Exit primary')
+ elif res.status_code in error_codes:
+ pass
+ else:
+ print('Error: unknown response.')
+
def print_status(self, json_obj):
"""Parse SPP primary's status and print.
--
2.7.4
More information about the spp
mailing list