Skip to content

Instantly share code, notes, and snippets.

@ktbyers
Created March 23, 2017 18:14
Show Gist options
  • Save ktbyers/4874ceb8fb157c9d8486c88632b505fe to your computer and use it in GitHub Desktop.
Save ktbyers/4874ceb8fb157c9d8486c88632b505fe to your computer and use it in GitHub Desktop.
Arista Class
import socket
import jsonrpclib
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
class AristaSwitch(object):
def __init__(self, switch, username, password):
self.switch = switch
self.username = username
self.password = password
self.remote_connect = None
def switch_connect(self):
switch = socket.gethostbyname(self.switch)
switch_url = 'https://{}:{}@{}'.format(self.username, self.password, switch)
switch_url = switch_url+'/command-api'
print(switch_url)
remote_connect = jsonrpclib.Server(switch_url)
self.remote_connect = remote_connect
return remote_connect
def run_commands(self, cmd):
response = self.remote_connect.runCmds(1, [cmd])
return response
if __name__ == "__main__":
my_device = AristaSwitch(switch="10.10.10.72", username="pyclass",
password="whatever")
my_device.switch_connect()
my_device.run_commands(cmd="show version")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment