summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-29 18:14:05 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-29 18:14:05 +0900
commitcbcc16c65b75be7af2a6c3e227107cce3795b33f (patch)
treef688793009a40fe7b2e7be8e289bf42d990267b6
parent5fcf89a9814773216687290262ee56d0cd7a704d (diff)
cli: show nice error message when failed to connect to gobgpd
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rwxr-xr-xcli/gobgpcli35
1 files changed, 27 insertions, 8 deletions
diff --git a/cli/gobgpcli b/cli/gobgpcli
index ff69f625..de3e7109 100755
--- a/cli/gobgpcli
+++ b/cli/gobgpcli
@@ -52,12 +52,17 @@ class Action(object):
def __call__(self):
if len(self.args) != 2:
return 1
- r = requests.post(self.base_url + "/neighbor/" + self.args[1] + "/" + self.command)
- if r.status_code == requests.codes.ok:
- print "Succeed"
+ try:
+ r = requests.post(self.base_url + "/neighbor/" + self.args[1] + "/" + self.command)
+ except:
+ print "Failed to connect to gobgpd. It runs?"
+ sys.exit(1)
else:
- print "Failed"
- return 0
+ if r.status_code == requests.codes.ok:
+ print "Succeed"
+ else:
+ print "Failed"
+ return 0
class Show(object):
@@ -85,7 +90,12 @@ class Show(object):
65: "FOUR_OCTET_AS_NUMBER",
70: "ENHANCED_ROUTE_REFRESH",
128: "ROUTE_REFRESH_CISCO"}
- r = requests.get(self.base_url + "/neighbors")
+ try:
+ r = requests.get(self.base_url + "/neighbors")
+ except:
+ print "Failed to connect to gobgpd. It runs?"
+ sys.exit(1)
+
neighbors = r.json()
if self.options.debug:
print neighbors
@@ -136,7 +146,12 @@ class Show(object):
def do_neighbors(self):
if len(self.args) != 1:
return 1
- r = requests.get(self.base_url + "/neighbors")
+ try:
+ r = requests.get(self.base_url + "/neighbors")
+ except:
+ print "Failed to connect to gobgpd. It runs?"
+ sys.exit(1)
+
neighbors = r.json()
if self.options.debug:
print neighbors
@@ -250,8 +265,12 @@ class Show(object):
self.args[2] = "adj-rib-in"
if self.args[2] == "advertised-routes":
self.args[2] = "adj-rib-out"
+ try:
+ r = requests.get(self.base_url + "/neighbor/" + self.args[1] + "/" + self.args[2])
+ except:
+ print "Failed to connect to gobgpd. It runs?"
+ sys.exit(1)
- r = requests.get(self.base_url + "/neighbor/" + self.args[1] + "/" + self.args[2])
if self.options.debug:
print r.json()
return 0