-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateRoute
executable file
·110 lines (96 loc) · 4.55 KB
/
updateRoute
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/python
#
# Copyright (c) 2012-2013, Arista Networks, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# - Neither the name of Arista Networks nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Update route
#
# Version 1.0 8/14/2013
# Written by:
# Mark Berly, Arista Networks
#
# Revision history:
# 1.0 - initially written using Command API
"""
DESCRIPTION
The updateRoute script can be used in order to add or delete
routes from the routing table.
INSTALLATION
updateRoute can be run / installed on any device that runs
Python 2.7 or later. In order to run updateRoute against a
switch, first enable Command API on the switch as follows:
(config)# management api http-commands
(config)# protocol [http|https]
(config)# no shutdown
updateRoute can then be executed directly from bash as shown in
the example below:
(bash:root)# updateRoute 1.1.1.0/24 ethernet1 192.168.3.34 test test
Command-line arguments:
- route with CIDR mask
- egress interface or next-hop address
- host name / ip address of switch to push/pull route
- username
- password
Optional argumets:
--delete: removes route from routing table instead of adding it
--http: use HTTP instead of the default HTTPS
--enable-password: enable-mode password
COMPATIBILITY
Version 1.0 has been developed and tested against EOS-4.12.x and is using
the eAPI interface so should maintain backward compatibility with future
EOS versions.
LIMITATIONS
None known.
"""
import argparse
from jsonrpclib import Server
def connect( sIpOrHostname, username, password, secure=True ):
return Server( "%s://%s:%s@%s/command-api"
% ( "http" if not secure else "https", password, username, sIpOrHostname ) )
def updateRoute( switch, route, nextHop, delete, enablePass ):
rc = switch.runCmds( 1, [ { "cmd": "enable", "input": enablePass },
"configure",
"%s ip route %s %s"
% ( "no " if delete else "", route, nextHop ) ] )
def main():
parser = argparse.ArgumentParser(description='Get route information')
parser.add_argument( 'route', help='Route with CIDR mask (e.g 1.1.1.0/24)' )
parser.add_argument( 'intf', help='Output interface or next hop' )
parser.add_argument( 'sIpOrHostname', help='Switch IP address or Hostname' )
parser.add_argument( 'username', help='Username' )
parser.add_argument( 'password', help='Password' )
parser.add_argument( "--delete", help="Delete route",
action="store_true" )
parser.add_argument( "--http", help="Use unsecure http connection (default is https)",
action="store_false", default=True )
parser.add_argument( "--enable-password", help="Enable-mode password",
default="" )
args = parser.parse_args()
switch = connect ( args.sIpOrHostname, args.username, args.password, args.http )
updateRoute ( switch, args.route, args.intf, args.delete, args.enable_password )
if __name__ == '__main__':
main()