summaryrefslogtreecommitdiff
path: root/vyroute/basic_function
diff options
context:
space:
mode:
Diffstat (limited to 'vyroute/basic_function')
-rw-r--r--vyroute/basic_function/DeleteRoute.py36
-rw-r--r--vyroute/basic_function/Modifylo.py8
-rw-r--r--vyroute/basic_function/OSPFRoute.py91
-rw-r--r--vyroute/basic_function/RIPRoute.py15
-rw-r--r--vyroute/basic_function/StaticRoute.py12
5 files changed, 125 insertions, 37 deletions
diff --git a/vyroute/basic_function/DeleteRoute.py b/vyroute/basic_function/DeleteRoute.py
index da3f8e9..048406c 100644
--- a/vyroute/basic_function/DeleteRoute.py
+++ b/vyroute/basic_function/DeleteRoute.py
@@ -1,8 +1,4 @@
# Copyright (c) 2016 Hochikong
-from Exscript.protocols import SSH2
-from Exscript import Account
-
-
def deleteroute(obj, data):
"""This method provide a router configuration delete function
@@ -25,17 +21,33 @@ def deleteroute(obj, data):
try:
if data['config'] == "all":
- obj.execute(delete_all_protocols)
- return {"Result": "Delete successfully."}
+ obj.sendline(delete_all_protocols)
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ return obj.before
+ else:
+ return {"Result": "Delete successfully."}
elif data['config'] == 'rip':
- obj.execute(delete_basic_configuration % 'rip')
- return {"Result": "Delete successfully."}
+ obj.sendline(delete_basic_configuration % 'rip')
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ return obj.before
+ else:
+ return {"Result": "Delete successfully."}
elif data['config'] == 'static':
- obj.execute(delete_basic_configuration % 'static')
- return {"Result": "Delete successfully."}
+ obj.sendline(delete_basic_configuration % 'static')
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ return obj.before
+ else:
+ return {"Result": "Delete successfully."}
elif data['config'] == 'ospf':
- obj.execute(delete_basic_configuration % 'ospf')
- return {"Result": "Delete successfully."}
+ obj.sendline(delete_basic_configuration % 'ospf')
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ return obj.before
+ else:
+ return {"Result": "Delete successfully."}
else:
return {"Error": "Nonsupport protocols type."}
except Exception as e:
diff --git a/vyroute/basic_function/Modifylo.py b/vyroute/basic_function/Modifylo.py
index f835c3e..5dca08f 100644
--- a/vyroute/basic_function/Modifylo.py
+++ b/vyroute/basic_function/Modifylo.py
@@ -15,7 +15,11 @@ def modifylo(obj, data):
try:
# Configure loopback interface lo address
- obj.execute(lo_basic_configuration % data['config'])
- return {"Result": "Modify successfully."}
+ obj.sendline(lo_basic_configuration % data['config'])
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ return obj.before
+ else:
+ return {"Result": "Modify successfully."}
except Exception as e:
return {'Error': e}
diff --git a/vyroute/basic_function/OSPFRoute.py b/vyroute/basic_function/OSPFRoute.py
index 0c3367c..b7c1c40 100644
--- a/vyroute/basic_function/OSPFRoute.py
+++ b/vyroute/basic_function/OSPFRoute.py
@@ -14,8 +14,12 @@ def ospfarea(obj, data):
try:
# Configure ospf area
- obj.execute(ospf_basic_configuration % (data['config']['area'], data['config']['network']))
- return {"Result": "Configured successfully"}
+ obj.sendline(ospf_basic_configuration % (data['config']['area'], data['config']['network']))
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ return obj.before
+ else:
+ return {"Result": "Configured successfully"}
except Exception as e:
return {"Error": e}
@@ -34,8 +38,12 @@ def router_id(obj, data):
router_id_configuration = "set protocols ospf parameters router-id %s"
try:
# Configure router id
- obj.execute(router_id_configuration % data['config']['id'])
- return {"Result": "Configured successfully"}
+ obj.sendline(router_id_configuration % data['config']['id'])
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ return obj.before
+ else:
+ return {"Result": "Configured successfully"}
except Exception as e:
return {"Error": e}
@@ -55,29 +63,46 @@ def ospf_redistribute(obj, data):
"1": "set protocols ospf redistribute connected route-map CONNECT",
}
try:
- obj.execute(redistribute_configuration['0'] % data['config']['type'])
- obj.execute(redistribute_configuration['1'])
- return {"Result": "Configured successfully"}
+ reg = 0
+ error_message = []
+ obj.sendline(redistribute_configuration['0'] % data['config']['type'])
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ error_message.append(obj.before)
+ reg += 1
+ obj.sendline(redistribute_configuration['1'])
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ error_message.append(obj.before)
+ reg += 1
+ if reg > 0:
+ return error_message
+ else:
+ return {"Result": "Configured successfully"}
except Exception as e:
return {"Error": e}
def ospf_adjacency(obj):
- """This method execute : set protocols ospf log-adjacency-changes
+ """This method sendline : set protocols ospf log-adjacency-changes
:param obj: a connection object
:return: a python dictionary
"""
log_adjacency_changes_configuration = "set protocols ospf log-adjacency-changes"
try:
- obj.execute(log_adjacency_changes_configuration)
- return {"Result": "Configured successfully"}
+ obj.sendline(log_adjacency_changes_configuration)
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ return obj.before
+ else:
+ return {"Result": "Configured successfully"}
except Exception as e:
return {"Error": e}
def ospf_default_route(obj, data):
- """This method execute : set protocols ospf default-information originate always
+ """This method sendline : set protocols ospf default-information originate always
and other commands
Parameter data example:
@@ -93,10 +118,27 @@ def ospf_default_route(obj, data):
"2": "set protocols ospf default-information originate metric-type %s",
}
try:
- obj.execute(default_route_configuration['0'])
- obj.execute(default_route_configuration['1'] % data['config']['metric'])
- obj.execute(default_route_configuration['2'] % data['config']['metric-type'])
- return {"Result": "Configured successfully"}
+ reg = 0
+ error_messsage = []
+ obj.sendline(default_route_configuration['0'])
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ error_messsage.append(obj.before)
+ reg += 1
+ obj.sendline(default_route_configuration['1'] % data['config']['metric'])
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ error_messsage.append(obj.before)
+ reg += 1
+ obj.sendline(default_route_configuration['2'] % data['config']['metric-type'])
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ error_messsage.append(obj.before)
+ reg += 1
+ if reg > 0:
+ return error_messsage
+ else:
+ return {"Result": "Configured successfully"}
except Exception as e:
return {"Error": e}
@@ -116,8 +158,21 @@ def ospf_route_map(obj, data):
"1": "set policy route-map CONNECT rule %s match interface %s",
}
try:
- obj.execute(route_map_configuration['0'] % data['config']['rule'])
- obj.execute(route_map_configuration['1'] % (data['config']['rule'], data['config']['interface']))
- return {"Result": "Configured successfully"}
+ reg = 0
+ error_messsage = []
+ obj.sendline(route_map_configuration['0'] % data['config']['rule'])
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ error_messsage.append(obj.before)
+ reg += 1
+ obj.sendline(route_map_configuration['1'] % (data['config']['rule'], data['config']['interface']))
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ error_messsage.append(obj.before)
+ reg += 1
+ if reg > 0:
+ return error_messsage
+ else:
+ return {"Result": "Configured successfully"}
except Exception as e:
return {"Error": e}
diff --git a/vyroute/basic_function/RIPRoute.py b/vyroute/basic_function/RIPRoute.py
index a493eac..cb421e0 100644
--- a/vyroute/basic_function/RIPRoute.py
+++ b/vyroute/basic_function/RIPRoute.py
@@ -14,8 +14,21 @@ def riproute(obj, data):
redistribute_configuration = "set protocols rip redistribute connected"
try:
# Configure RIP router
+ reg = 0
+ error_messsage = []
obj.execute(rip_basic_configuration % data['config'])
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ error_messsage.append(obj.before)
+ reg += 1
obj.execute(redistribute_configuration)
- return {"Result": "Configured successfully"}
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ error_messsage.append(obj.before)
+ reg += 1
+ if reg > 0:
+ return error_messsage
+ else:
+ return {"Result": "Configured successfully"}
except Exception as e:
return {"Error": e}
diff --git a/vyroute/basic_function/StaticRoute.py b/vyroute/basic_function/StaticRoute.py
index b70ed19..9bdf378 100644
--- a/vyroute/basic_function/StaticRoute.py
+++ b/vyroute/basic_function/StaticRoute.py
@@ -14,9 +14,13 @@ def staticroute(obj, data):
try:
# Configure static router
- obj.execute(static_basic_configuration % (data['config']['target'],
- data['config']['next-hop'],
- data['config']['distance']))
- return {"Result": "Configured successfully"}
+ obj.sendline(static_basic_configuration % (data['config']['target'],
+ data['config']['next-hop'],
+ data['config']['distance']))
+ obj.prompt()
+ if len(obj.before) > obj.before.index('\r\n') + 2:
+ return obj.before
+ else:
+ return {"Result": "Configured successfully"}
except Exception as e:
return {'Error': e}