From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 1/9] controller: add spp-ctl client for SPP controller
Date: Thu, 18 Oct 2018 20:25:10 +0900 [thread overview]
Message-ID: <20181018112518.77556-2-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20181018112518.77556-1-ogawa.yasufumi@lab.ntt.co.jp>
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Add SppCtlClient class which is a utility to create requests and
responses for spp-ctl.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/controller/spp_ctl_client.py | 58 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
create mode 100644 src/controller/spp_ctl_client.py
diff --git a/src/controller/spp_ctl_client.py b/src/controller/spp_ctl_client.py
new file mode 100644
index 0000000..6de1ae4
--- /dev/null
+++ b/src/controller/spp_ctl_client.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
+
+import requests
+
+
+class SppCtlClient(object):
+
+ def __init__(self):
+ api_ver = 'v1'
+ ip_addr = '127.0.0.1'
+ port = 7777
+ self.base_url = 'http://%s:%d/%s' % (ip_addr, port, api_ver)
+
+ def request_handler(func):
+ """Request handler for spp-ctl.
+
+ Decorator for handling a http request of 'requests' library.
+ It receives one of the methods 'get', 'put', 'post' or 'delete'
+ as 'func' argment.
+ """
+
+ def wrapper(self, *args, **kwargs):
+ try:
+ res = func(self, *args, **kwargs)
+
+ # TODO(yasufum) revise print message to more appropriate
+ # for spp.py.
+ if res.status_code == 400:
+ print('Syntax or lexical error, or SPP returns' +
+ 'error for the request.')
+ elif res.status_code == 404:
+ print('URL is not supported, or no SPP process' +
+ 'of client-id in a URL.')
+ elif res.status_code == 500:
+ print('System error occured in spp-ctl.')
+
+ return res
+ except requests.exceptions.ConnectionError:
+ print('Error: Failed to connect to spp-ctl.')
+ return None
+ return wrapper
+
+ @request_handler
+ def get(self, req):
+ url = '%s/%s' % (self.base_url, req)
+ return requests.get(url)
+
+ @request_handler
+ def put(self, req, params):
+ url = '%s/%s' % (self.base_url, req)
+ return requests.put(url, json=params)
+
+ @request_handler
+ def delete(self, req):
+ url = '%s/%s' % (self.base_url, req)
+ return requests.delete(url)
--
2.13.1
next prev parent reply other threads:[~2018-10-18 11:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-18 11:25 [spp] [PATCH 0/9] Change SPP controller to use spp-ctl ogawa.yasufumi
2018-10-18 11:25 ` ogawa.yasufumi [this message]
2018-10-18 11:25 ` [spp] [PATCH 2/9] controller: change " ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 3/9] spp-ctl: add IP address binding ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 4/9] controller: add IP address and port binding ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 5/9] controller: move pri command to SppPrimary ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 6/9] controller: move sec command to SppSecondary ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 7/9] controller: move topo command to SppTopo ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 8/9] controller: move topo_resize " ogawa.yasufumi
2018-10-18 11:25 ` [spp] [PATCH 9/9] controller: move bye command to SppBye ogawa.yasufumi
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=20181018112518.77556-2-ogawa.yasufumi@lab.ntt.co.jp \
--to=ogawa.yasufumi@lab.ntt.co.jp \
--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).