Soft Patch Panel
 help / color / mirror / Atom feed
From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH 2/2] spp-ctl: add port add and del APIs for spp_primary
Date: Tue, 16 Jul 2019 16:30:57 +0900	[thread overview]
Message-ID: <20190716073057.18821-3-yasufum.o@gmail.com> (raw)
In-Reply-To: <20190716073057.18821-1-yasufum.o@gmail.com>

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

This update is to add REST APIs for adding ro deleting to spp_primary.
Here is an example for adding `vhost:1`.

    $ curl -X PUT -H 'application/json' -d \
      '{"action": "add", "port": "vhost:1"}' \
      http://127.0.0.1:7777/v1/primary/ports

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/spp-ctl/spp_proc.py   |  8 ++++++++
 src/spp-ctl/spp_webapi.py | 20 ++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/src/spp-ctl/spp_proc.py b/src/spp-ctl/spp_proc.py
index fe7ecea..2bc14e6 100644
--- a/src/spp-ctl/spp_proc.py
+++ b/src/spp-ctl/spp_proc.py
@@ -292,6 +292,14 @@ class PrimaryProc(SppProc):
     def clear(self):
         return "clear"
 
+    @exec_command
+    def port_add(self, port):
+        return "add {port}".format(**locals())
+
+    @exec_command
+    def port_del(self, port):
+        return "del {port}".format(**locals())
+
     @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 7f2baad..89b188a 100644
--- a/src/spp-ctl/spp_webapi.py
+++ b/src/spp-ctl/spp_webapi.py
@@ -452,6 +452,8 @@ 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('/', 'DELETE', callback=self.pri_exit)
@@ -478,6 +480,24 @@ class V1PrimaryHandler(BaseHandler):
         proc = self._get_proc()
         proc.clear()
 
+    # TODO(yasufum) change name and make it to shared method
+    def _validate_nfv_port(self, body):
+        for key in ['action', 'port']:
+            if key not in body:
+                raise KeyRequired(key)
+        if body['action'] not in ["add", "del"]:
+            raise KeyInvalid('action', body['action'])
+        self._validate_port(body['port'])
+
+    def primary_port(self, body):
+        self._validate_nfv_port(body)
+        proc = self._get_proc()
+
+        if body['action'] == "add":
+            proc.port_add(body['port'])
+        else:
+            proc.port_del(body['port'])
+
     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


      parent reply	other threads:[~2019-07-16  7:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-16  7:30 [spp] [PATCH 0/2] Add REST APIs for add or del port to spp_primary yasufum.o
2019-07-16  7:30 ` [spp] [PATCH 1/2] spp_primary: add commands to add and del port yasufum.o
2019-07-16  7:30 ` yasufum.o [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190716073057.18821-3-yasufum.o@gmail.com \
    --to=yasufum.o@gmail.com \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).