* [spp] [PATCH] spp-ctl: add APIs for pri for managing ports
@ 2019-10-17 12:58 yasufum.o
0 siblings, 0 replies; only message in thread
From: yasufum.o @ 2019-10-17 12:58 UTC (permalink / raw)
To: spp, ferruh.yigit, yasufum.o
From: Yasufumi Ogawa <yasufum.o@gmail.com>
Add REST APIs for spp_primary for running `forward`, `stop` and
`patch` commands which are similar to spp_nfv. For example, forward
can be run with curl as below.
$ curl -X PUT -H 'application/json' -d '{"action": "start"}' \
http://127.0.0.1:7777/v1/primary/forward
Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
src/spp-ctl/spp_proc.py | 17 +++++++++++++
src/spp-ctl/spp_webapi.py | 51 +++++++++++++++++++++++++++++++++++----
2 files changed, 63 insertions(+), 5 deletions(-)
diff --git a/src/spp-ctl/spp_proc.py b/src/spp-ctl/spp_proc.py
index 33bde43..35919fb 100644
--- a/src/spp-ctl/spp_proc.py
+++ b/src/spp-ctl/spp_proc.py
@@ -11,6 +11,7 @@ import spp_ctl
LOG = logging.getLogger(__name__)
+# TODO(yasufum): Move following definitions to another file.
ID_PRIMARY = 0
TYPE_PRIMARY = "primary"
TYPE_VF = "vf"
@@ -300,6 +301,22 @@ class PrimaryProc(SppProc):
def port_del(self, port):
return "del {port}".format(**locals())
+ @exec_command
+ def patch_add(self, src_port, dst_port):
+ return "patch {src_port} {dst_port}".format(**locals())
+
+ @exec_command
+ def patch_reset(self):
+ return "patch reset"
+
+ @exec_command
+ def forward(self):
+ return "forward"
+
+ @exec_command
+ def stop(self):
+ return "stop"
+
@exec_command
def do_launch_sec_proc(self, args):
proc_name = args['proc_name']
diff --git a/src/spp-ctl/spp_webapi.py b/src/spp-ctl/spp_webapi.py
index 8451711..a21fd86 100644
--- a/src/spp-ctl/spp_webapi.py
+++ b/src/spp-ctl/spp_webapi.py
@@ -455,13 +455,20 @@ class V1PrimaryHandler(BaseHandler):
def set_route(self):
self.route('/status', 'GET', callback=self.get_status)
self.route('/status', 'DELETE', callback=self.clear_status)
- self.route('/ports', 'PUT',
- callback=self.primary_port)
- self.route('/launch', 'PUT',
- callback=self.launch_sec_proc)
+ self.route('/forward', 'PUT', callback=self.nfv_forward)
+ self.route('/ports', 'PUT', callback=self.primary_port)
+ self.route('/patches', 'PUT', callback=self.nfv_patch_add)
+ self.route('/patches', 'DELETE', callback=self.nfv_patch_del)
+ self.route('/launch', 'PUT', callback=self.launch_sec_proc)
self.route('/', 'DELETE', callback=self.pri_exit)
def _get_proc(self):
+ """Get Primary object for requesting.
+
+ This method is call everytime received request via REST API
+ to confirm primary is alive.
+ """
+
proc = self.ctrl.procs.get(spp_proc.ID_PRIMARY)
if proc is None:
raise bottle.HTTPError(404, "primary not found.")
@@ -483,7 +490,22 @@ class V1PrimaryHandler(BaseHandler):
proc = self._get_proc()
proc.clear()
- # TODO(yasufum) change name and make it to shared method
+ # TODO(yasufum) change name `nfv` and make it to shared method
+ def _validate_nfv_forward(self, body):
+ if 'action' not in body:
+ raise KeyRequired('action')
+ if body['action'] not in ["start", "stop"]:
+ raise KeyInvalid('action', body['action'])
+
+ # TODO(yasufum) change name `nfv` and make it to shared method
+ def nfv_forward(self, body):
+ proc = self._get_proc()
+ if body['action'] == "start":
+ proc.forward()
+ else:
+ proc.stop()
+
+ # TODO(yasufum) change name `nfv` and make it to shared method
def _validate_nfv_port(self, body):
for key in ['action', 'port']:
if key not in body:
@@ -501,6 +523,25 @@ class V1PrimaryHandler(BaseHandler):
else:
proc.port_del(body['port'])
+ # TODO(yasufum) change name `nfv` and make it to shared method
+ def _validate_nfv_patch(self, body):
+ for key in ['src', 'dst']:
+ if key not in body:
+ raise KeyRequired(key)
+ self._validate_port(body['src'])
+ self._validate_port(body['dst'])
+
+ # TODO(yasufum) change name `nfv` and make it to shared method
+ def nfv_patch_add(self, body):
+ proc = self._get_proc()
+ self._validate_nfv_patch(body)
+ proc.patch_add(body['src'], body['dst'])
+
+ # TODO(yasufum) change name `nfv` and make it to shared method
+ def nfv_patch_del(self):
+ proc = self._get_proc()
+ proc.patch_reset()
+
def launch_sec_proc(self, body): # the arg should be "body"
for key in ['client_id', 'proc_name', 'eal', 'app']:
if key not in body:
--
2.17.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-10-17 12:58 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-17 12:58 [spp] [PATCH] spp-ctl: add APIs for pri for managing ports 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).