From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH 2/5] controller: exit controller if spp-ctl not running
Date: Thu, 18 Oct 2018 20:27:34 +0900 [thread overview]
Message-ID: <20181018112737.77626-3-ogawa.yasufumi@lab.ntt.co.jp> (raw)
In-Reply-To: <20181018112737.77626-1-ogawa.yasufumi@lab.ntt.co.jp>
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
SPP controller expects spp-ctl is running, so it should notice a user
while launching if it cannot access to spp-ctl. SPP controller already
does notify, but not while launching.
This update is to add 'is_server_running()' to SppCtlClient class to
check if spp-ctl is running. It also fixes incorrect notify of SppTopo
if it cannot access to spp-ctl.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
src/controller/commands/topo.py | 19 +++++++++----------
src/controller/shell.py | 6 ++----
src/controller/spp.py | 13 ++++++++++---
src/controller/spp_ctl_client.py | 6 ++++++
4 files changed, 27 insertions(+), 17 deletions(-)
diff --git a/src/controller/commands/topo.py b/src/controller/commands/topo.py
index 53cc8b5..e8afa4a 100644
--- a/src/controller/commands/topo.py
+++ b/src/controller/commands/topo.py
@@ -22,32 +22,31 @@ class SppTopo(object):
delim_node = '_'
- def __init__(self, spp_ctl_cli, sec_ids, subgraphs, size):
+ def __init__(self, spp_ctl_cli, subgraphs, size):
self.spp_ctl_cli = spp_ctl_cli
- self.sec_ids = sec_ids
self.subgraphs = subgraphs
self.graph_size = size
- def run(self, args):
+ def run(self, args, sec_ids):
args_ary = args.split()
if len(args_ary) == 0:
print("Usage: topo dst [ftype]")
return False
elif (args_ary[0] == "term") or (args_ary[0] == "http"):
- self.show(args_ary[0], self.graph_size)
+ self.show(args_ary[0], sec_ids, self.graph_size)
elif len(args_ary) == 1:
ftype = args_ary[0].split(".")[-1]
- self.output(args_ary[0], ftype)
+ self.output(args_ary[0], sec_ids, ftype)
elif len(args_ary) == 2:
- self.output(args_ary[0], args_ary[1])
+ self.output(args_ary[0], sec_ids, args_ary[1])
else:
print("Usage: topo dst [ftype]")
- def show(self, dtype, size):
+ def show(self, dtype, sec_ids, size):
res_ary = []
error_codes = self.spp_ctl_cli.rest_common_error_codes
- for sec_id in self.sec_ids:
+ for sec_id in sec_ids:
res = self.spp_ctl_cli.get('nfvs/%d' % sec_id)
if res.status_code == 200:
res_ary.append(res.json())
@@ -65,11 +64,11 @@ class SppTopo(object):
else:
print("Invalid file type")
- def output(self, fname, ftype="dot"):
+ def output(self, fname, sec_ids, ftype="dot"):
res_ary = []
error_codes = self.spp_ctl_cli.rest_common_error_codes
- for sec_id in self.sec_ids:
+ for sec_id in sec_ids:
res = self.spp_ctl_cli.get('nfvs/%d' % sec_id)
if res.status_code == 200:
res_ary.append(res.json())
diff --git a/src/controller/shell.py b/src/controller/shell.py
index 28ae86e..2c170e9 100644
--- a/src/controller/shell.py
+++ b/src/controller/shell.py
@@ -44,9 +44,7 @@ class Shell(cmd.Cmd, object):
self.spp_ctl_cli = spp_ctl_cli
self.spp_primary = pri.SppPrimary(self.spp_ctl_cli)
self.spp_secondary = sec.SppSecondary(self.spp_ctl_cli)
- self.spp_topo = topo.SppTopo(self.spp_ctl_cli,
- self.get_sec_ids('nfv'),
- {}, self.topo_size)
+ self.spp_topo = topo.SppTopo(self.spp_ctl_cli, {}, self.topo_size)
self.spp_bye = bye.SppBye(self.spp_ctl_cli, self.spp_primary,
self.spp_secondary)
@@ -660,7 +658,7 @@ class Shell(cmd.Cmd, object):
spp > topo network_conf.js# text
"""
- self.spp_topo.run(args)
+ self.spp_topo.run(args, self.get_sec_ids('nfv'))
def complete_topo(self, text, line, begidx, endidx):
diff --git a/src/controller/spp.py b/src/controller/spp.py
index 6b0d99c..99cdda3 100644
--- a/src/controller/spp.py
+++ b/src/controller/spp.py
@@ -19,9 +19,16 @@ def main(argv):
help='bind address, default=7777')
args = parser.parse_args()
- shell = Shell(spp_ctl_client.SppCtlClient(args.bind_addr, args.api_port))
- shell.cmdloop()
- shell = None
+ try:
+ spp_ctl_cli = spp_ctl_client.SppCtlClient(args.bind_addr, args.api_port)
+ if spp_ctl_cli.is_server_running() == False:
+ print('Is not spp-ctl running, nor correct IP address?')
+ exit()
+ shell = Shell(spp_ctl_cli)
+ shell.cmdloop()
+ shell = None
+ except Exception as e:
+ print(e)
if __name__ == "__main__":
diff --git a/src/controller/spp_ctl_client.py b/src/controller/spp_ctl_client.py
index 8a88fa4..0f8687a 100644
--- a/src/controller/spp_ctl_client.py
+++ b/src/controller/spp_ctl_client.py
@@ -56,3 +56,9 @@ class SppCtlClient(object):
def delete(self, req):
url = '%s/%s' % (self.base_url, req)
return requests.delete(url)
+
+ def is_server_running(self):
+ if self.get('processes') is None:
+ return False
+ else:
+ return True
--
2.13.1
next prev parent reply other threads:[~2018-10-18 11:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-18 11:27 [spp] [PATCH 0/5] Refactor SPP controller ogawa.yasufumi
2018-10-18 11:27 ` [spp] [PATCH 1/5] controller: change name of plugins directory ogawa.yasufumi
2018-10-18 11:27 ` ogawa.yasufumi [this message]
2018-10-18 11:27 ` [spp] [PATCH 3/5] controller: move spp_history to home directory ogawa.yasufumi
2018-10-18 11:27 ` [spp] [PATCH 4/5] controller: move PORT_TYPES to spp_common ogawa.yasufumi
2018-10-18 11:27 ` [spp] [PATCH 5/5] controller: remove SECONDARY_LIST 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=20181018112737.77626-3-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).