From d4d3c20929e812a097c4065de6b6d56f61c41140 Mon Sep 17 00:00:00 2001 From: David Barroso Date: Mon, 16 Mar 2015 09:52:36 +0100 Subject: [PATCH] Migrated from ncclient to pyEZ --- drivers/junos.py | 51 ++++++++++++------------------------------------ 1 file changed, 13 insertions(+), 38 deletions(-) diff --git a/drivers/junos.py b/drivers/junos.py index bc90111..171ef4b 100644 --- a/drivers/junos.py +++ b/drivers/junos.py @@ -1,7 +1,7 @@ from base import NetworkDriver -from ncclient import manager - +from jnpr.junos import Device +from jnpr.junos.utils.config import Config def __execute_rpc__(conn, rpc_command): output = conn.rpc(str(rpc_command)) @@ -18,60 +18,35 @@ class JunOSDriver(NetworkDriver): self.hostname = hostname self.user = user self.password = password + self.device = Device(hostname, user=user, password=password) def open(self): - self.device = manager.connect( - host=self.hostname, - port=830, - username=self.user, - password=self.password, - timeout=10, - hostkey_verify=False, - device_params={'name':'junos'}, - ) - rpc_command = '' - __execute_rpc__(self.device, rpc_command) + self.device.open() + self.device.bind( cu=Config ) + self.device.cu.lock() def close(self): - rpc_command = '' - __execute_rpc__(self.device, rpc_command) - self.device.close_session() + self.device.cu.unlock() + self.device.close() def load_candidate_config(self, filename=None, config=None): - if filename is None: configuration = config else: with open(filename) as f: configuration = f.read() - rpc_command = ''' - - - %s - - - ''' % configuration - - __execute_rpc__(self.device, rpc_command) + self.device.cu.load(configuration, format='text', overwrite=True) def compare_config(self): - rpc_command = ''' - - ''' - conf = __execute_rpc__(self.device, rpc_command) - return conf.xpath('/rpc-reply/configuration-information/configuration-output')[0].text + return self.device.cu.diff() def commit_config(self): - rpc_command = '' - __execute_rpc__(self.device, rpc_command) + self.device.cu.commit() def discard_config(self): - rpc_command = '' - __execute_rpc__(self.device, rpc_command) + self.device.cu.rollback(rb_id=0) def rollback(self): - rpc_command = '' - __execute_rpc__(self.device, rpc_command) + self.device.cu.rollback(rb_id=1) self.commit_config() -