Open chustm opened 11 months ago
I finaly got this working. It was only moving the "template" variable out of the function and from main, and then simply call it:
import json
template = """
<template name="wlan_profile_summ">
<group name="{{ wlan_profile }}">
wlan {{ wlan_profile | _start_ }} {{ wlan_id | DIGIT }} {{ ssid }}
</group>
</template>
"""
def parse_cisco_wlans(wlcList,ssid,newPsk):
for device in wlcList:
try:
with ConnectHandler(**device) as net_connect:
wlc_hostname = net_connect.find_prompt()[:-1]
print ('=========> Connecting to ',wlc_hostname)
data = net_connect.send_command('show run | inc (^wlan.+)_([0-9]+)_([A-Za-z0-9]+)$')
parser = ttp(data, template)
parser.parse()
cisco_wlanTemplates = parser.result(structure="flat_list")
(...)
when you moved the template variable in the function you accidentaly indented all the strings, thats why it was not matching anything. If you want to move the template back in the function write something like this:
template = """
<template name="wlan_profile_summ">
<group name="{{ wlan_profile }}">
wlan {{ wlan_profile | _start_ }} {{ wlan_id }} {{ ssid }}
</group>
</template>
"""
Hi there, I'm having an issue with ttp as it's working fine when the Netmiko call is in the main body, but when I move all the code, including the Netmiko call, inside a function the dictionary returned is empty. Or even if I move ttp code to a function, and keep Netmiko call on the amin one, sending data through a function. BUT, if instead using Netmiko to get the data I use plain text as data input, it works either way inside or outside a function.
Script with Netmiko and no Function returns proper dict:
Script with Netmiko inside Function returns empty dict:
Script with plain data and no Function returns proper dict:
Script with plain data inside Function returns proper dict: