Created
May 22, 2014 13:28
-
-
Save markberly/ba2f39f6bb978aedfd8d to your computer and use it in GitHub Desktop.
A quick script to add 100 loopback interfaces to a network elemenet, designed to work with Arista EOS eAPI (via JSON RPC) written in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
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 addLoopback( switch, enablePass, intfLo, ipAddr ): | |
rc = switch.runCmds( 1, [ { "cmd": "enable", "input": enablePass }, | |
"configure", | |
intfLo, | |
ipAddr ] ) | |
return rc | |
def main(): | |
parser = argparse.ArgumentParser(description='Provision Loopbacks') | |
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( "--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 ) | |
intfLo = "" | |
ipAddr = "" | |
for x in range(1,101) : | |
intfLo = "interface loopback %s" % (x) | |
ipAddr = "ip address 10.10.10.%s/32" % (x) | |
addLoopback ( switch, args.enable_password , intfLo, ipAddr ) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment