from base import NetworkDriver from ncclient import manager def __execute_rpc__(conn, rpc_command): output = conn.rpc(str(rpc_command)) if len(output.xpath('/rpc-reply/error')) > 0: raise Exception(output.tostring) return output class JunOSDriver(NetworkDriver): def __init__(self, hostname, user, password): self.hostname = hostname self.user = user self.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) def close(self): rpc_command = '' __execute_rpc__(self.device, rpc_command) self.device.close_session() 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) def compare_config(self): rpc_command = ''' ''' conf = __execute_rpc__(self.device, rpc_command) return conf.xpath('/rpc-reply/configuration-information/configuration-output')[0].text def commit_config(self): rpc_command = '' __execute_rpc__(self.device, rpc_command) def discard_config(self): rpc_command = '' __execute_rpc__(self.device, rpc_command) def rollback(self): rpc_command = '' __execute_rpc__(self.device, rpc_command) self.commit_config()