[spp] [PATCH 2/5] spp-ctl: add exit cmd support for spp_nfv

ogawa.yasufumi at lab.ntt.co.jp ogawa.yasufumi at lab.ntt.co.jp
Thu Oct 25 07:19:40 CEST 2018


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

Spp-ctl does not support exit spp_nfv and spp_vm, but it is required
using from `spp.py`. This update is to add a REST API for exiting the
process. It also add `do_exit()` method into spp-ctl to send `exit`
command to spp_nfv.

Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi at lab.ntt.co.jp>
---
 src/spp-ctl/spp_ctl.py    | 9 +++++++++
 src/spp-ctl/spp_proc.py   | 4 ++++
 src/spp-ctl/spp_webapi.py | 5 +++++
 3 files changed, 18 insertions(+)

diff --git a/src/spp-ctl/spp_ctl.py b/src/spp-ctl/spp_ctl.py
index 80a78b6..81a2fe0 100644
--- a/src/spp-ctl/spp_ctl.py
+++ b/src/spp-ctl/spp_ctl.py
@@ -141,6 +141,15 @@ class Controller(object):
             procs.append(p)
         return procs
 
+    def do_exit(self, sec_type, sec_id):
+        target_key = None
+        for k, proc in self.procs.items():
+            if proc.type == sec_type and proc.id == sec_id:
+                target_key = k
+                break
+        if target_key is not None:
+            del self.procs[target_key]
+
 
 def main():
     parser = argparse.ArgumentParser(description="SPP Controller")
diff --git a/src/spp-ctl/spp_proc.py b/src/spp-ctl/spp_proc.py
index 3b01e3f..aa928f2 100644
--- a/src/spp-ctl/spp_proc.py
+++ b/src/spp-ctl/spp_proc.py
@@ -168,6 +168,10 @@ class NfvProc(SppProc):
     def stop(self):
         return "stop"
 
+    @exec_command
+    def do_exit(self):
+        return "exit"
+
 
 class PrimaryProc(SppProc):
 
diff --git a/src/spp-ctl/spp_webapi.py b/src/spp-ctl/spp_webapi.py
index b2fbe3b..8332cab 100644
--- a/src/spp-ctl/spp_webapi.py
+++ b/src/spp-ctl/spp_webapi.py
@@ -310,6 +310,7 @@ class V1NFVHandler(BaseHandler):
 
     def set_route(self):
         self.route('/<sec_id:int>', 'GET', callback=self.nfv_get)
+        self.route('/<sec_id:int>', 'DELETE', callback=self.nfv_exit)
         self.route('/<sec_id:int>/forward', 'PUT',
                    callback=self.nfv_forward)
         self.route('/<sec_id:int>/ports', 'PUT',
@@ -377,6 +378,10 @@ class V1NFVHandler(BaseHandler):
     def nfv_patch_del(self, proc):
         proc.patch_reset()
 
+    def nfv_exit(self, proc):
+        self.ctrl.do_exit(proc.type, proc.id)
+        proc.do_exit()
+
 
 class V1PrimaryHandler(BaseHandler):
 
-- 
2.7.4



More information about the spp mailing list