def dryrun(**kwargs): lib = kwargs.get("library", False) config = kwargs.get("config", False) j2conf = kwargs.get("j2config", False) webhook = kwargs.get("webhook", False) if j2conf: j2confargs = j2conf.get("args") try: res = render_j2template(j2conf["template"], kwargs=j2confargs) config = res["data"]["task_result"]["template_render_result"] except Exception as e: config = False return e try: result = {} if lib == "napalm": napl = naplm(**kwargs) sesh = napl.connect() result = napl.config(session=sesh, command=config, dry_run=True) napl.logout(sesh) elif lib == "ncclient": ncc = ncclien(**kwargs) sesh = ncc.connect() result = ncc.editconfig(session=sesh, dry_run=True) ncc.logout(sesh) if webhook: current_jobdata = prepare_netpalm_payload(job_result=result) exec_webhook_func(jobdata=current_jobdata, webhook_payload=webhook) return result except Exception as e: return str(e)
def dryrun(**kwargs): lib = kwargs.get("library", False) config = kwargs.get("config", False) j2conf = kwargs.get("j2config", False) if j2conf: j2confargs = j2conf.get("args") try: res = render_j2template(j2conf["template"], kwargs=j2confargs) config = res["data"]["task_result"]["template_render_result"] except Exception as e: config = False return e if lib == "napalm": try: napl = naplm(**kwargs) sesh = napl.connect() result = napl.config(session=sesh, command=config, dry_run=True) napl.logout(sesh) return result except Exception as e: return str(e) elif lib == "ncclient": try: ncc = ncclien(**kwargs) sesh = ncc.connect() result = ncc.editconfig(session=sesh, dry_run=True) ncc.logout(sesh) return result except Exception as e: return str(e)
def exec_command(**kwargs): lib = kwargs.get("library", False) command = kwargs.get("command", False) if type(command) == str: commandlst = [command] else: commandlst = command if lib == "netmiko": try: netmik = netmko(**kwargs) sesh = netmik.connect() result = netmik.sendcommand(sesh, commandlst) netmik.logout(sesh) return result except Exception as e: return str(e) elif lib == "napalm": try: napl = naplm(**kwargs) sesh = napl.connect() result = napl.sendcommand(sesh, commandlst) napl.logout(sesh) return result except Exception as e: return str(e)
def exec_config(**kwargs): lib = kwargs.get("library", False) config = kwargs.get("config", False) j2conf = kwargs.get("j2config", False) if j2conf: j2confargs = j2conf.get("args") try: res = render_j2template(j2conf["template"], kwargs=j2confargs) config = res["data"]["task_result"]["template_render_result"] except Exception as e: config = False return e if lib == "netmiko": try: netmik = netmko(**kwargs) sesh = netmik.connect() result = netmik.config(sesh, config) netmik.logout(sesh) return result except Exception as e: return str(e) elif lib == "napalm": try: napl = naplm(**kwargs) sesh = napl.connect() result = napl.config(sesh, config) napl.logout(sesh) return result except Exception as e: return str(e) elif lib == "ncclient": try: ncc = ncclien(**kwargs) sesh = ncc.connect() result = ncc.editconfig(sesh) ncc.logout(sesh) return result except Exception as e: return str(e) elif lib == "restconf": try: rcc = restconf(**kwargs) sesh = rcc.connect() result = rcc.config(sesh) rcc.logout(sesh) return result except Exception as e: return str(e)
def exec_config(**kwargs): lib = kwargs.get("library", False) config = kwargs.get("config", False) j2conf = kwargs.get("j2config", False) webhook = kwargs.get("webhook", False) if j2conf: j2confargs = j2conf.get("args") try: res = render_j2template(j2conf["template"], kwargs=j2confargs) config = res["data"]["task_result"]["template_render_result"] except Exception as e: config = False return str(e) try: result = False if lib == "netmiko": netmik = netmko(**kwargs) sesh = netmik.connect() result = netmik.config(sesh, config) netmik.logout(sesh) elif lib == "napalm": napl = naplm(**kwargs) sesh = napl.connect() result = napl.config(sesh, config) napl.logout(sesh) elif lib == "ncclient": ncc = ncclien(**kwargs) sesh = ncc.connect() result = ncc.editconfig(sesh) ncc.logout(sesh) elif lib == "restconf": rcc = restconf(**kwargs) sesh = rcc.connect() result = rcc.config(sesh) rcc.logout(sesh) if webhook: current_jobdata = prepare_netpalm_payload(job_result=result) exec_webhook_func(jobdata=current_jobdata, webhook_payload=webhook) return result except Exception as e: return str(e)
def exec_config(**kwargs): lib = kwargs.get("library", False) config = kwargs.get("config", False) if lib == "netmiko": try: netmik = netmko(**kwargs) sesh = netmik.connect() result = netmik.config(sesh,config) netmik.logout(sesh) return result except Exception as e: return str(e) elif lib == "napalm": try: napl = naplm(**kwargs) sesh = napl.connect() result = napl.config(sesh,config) napl.logout(sesh) return result except Exception as e: return str(e)
def exec_command(**kwargs): lib = kwargs.get("library", False) command = kwargs.get("command", False) webhook = kwargs.get("webhook", False) if type(command) == str: commandlst = [command] else: commandlst = command try: result = {} if lib == "netmiko": netmik = netmko(**kwargs) sesh = netmik.connect() result = netmik.sendcommand(sesh,commandlst) netmik.logout(sesh) elif lib == "napalm": napl = naplm(**kwargs) sesh = napl.connect() result = napl.sendcommand(sesh,commandlst) napl.logout(sesh) elif lib == "ncclient": ncc = ncclien(**kwargs) sesh = ncc.connect() result = ncc.getconfig(sesh) ncc.logout(sesh) elif lib == "restconf": rc = restconf(**kwargs) sesh = rc.connect() result = rc.sendcommand(sesh) rc.logout(sesh) if webhook: current_jobdata = prepare_netpalm_payload(job_result=result) exec_webhook_func(jobdata=current_jobdata, webhook_payload=webhook) return result except Exception as e: return str(e)