blob: cb421e02b8772a5eef26594039359655528eaff5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# Copyright (c) 2016 Hochikong
def riproute(obj, data):
"""This method provide a RIP protocols router configuration function
Parameter data example:
{'config':'192.168.10.0/24',
}
:param obj: a connection object
:param data: a python dictionary
:return: a python dictionary
"""
rip_basic_configuration = "set protocols rip network %s"
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)
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}
|