09-21-2021 01:04 PM
Hi,
I am new to XMC workflow.
I have created a workflow that list all the Non Eap ports with port name/descriptions. I need to export output in the form of text file for each switch. I can do it manually through workflow input. But I need to automate this process so that I can schedule workflow.
09-22-2021 07:26 AM
This is my script for workflow. From here I can save my file to /tmp/Switchname.txt from the custom input.
I want this custom input to be dynamic so that the filename is changed acording to the switch name.
09-22-2021 07:23 AM
from xmclib import logger
from xmclib import emc_vars
import json
import re
def wf_info(log):
print 'INFO:' +log
logger.info(log)
def execConfigCmd(cmd,Wait=True):
wf_info("running cmd " + str(cmd))
cli_results = emc_cli.send(cmd,Wait)
if cli_results.isSuccess() is False:
wf_error("ERROR EXECUTING COMMANDS")
output = cli_results.getOutput()
return output
execConfigCmd("enable")
execConfigCmd("terminal length 0")
text = execConfigCmd("show eapol multihost interface")
print(text)
import re
p = "(?<=Non-EAP RADIUS Authentication)(.*)(?=\n)"
matches = re.findall(p, text, re.MULTILINE)
print(matches)
port_pattern = "(?<=Port)(.*)(?=\n)"
portmatches = re.findall(port_pattern, text, re.MULTILINE)
#print(portmatches)
matches1 = [str(x.replace(":","").strip()) for x in portmatches]
count = 1
non_eap_port = []
for m in matches:
status = m.strip().replace(":","").strip().lower()
print("status", status)
if str(status) != "disabled":
emc_results.put("Finish", "True")
non_eap_port.append(matches1[count])
count +=1
print(non_eap_port)
#varMatchedPorts = non_eap_port
#varMatchedPorts =[str(x) for x in eval(varMatchedPorts)]
port = ",".join(non_eap_port)
print("port", port)
out = execConfigCmd("show interface name %s"%port)
print ("out", out)
try:
f = open(emc_vars["Attachments"], "w")
f.write(execConfigCmd("show interface name %s"%port))
f.close()
except:
wf_error("Can't write to file %s" % emc_vars["Attachments"])
status = emc_results.Status;
emc_results.setStatus( status.ERROR )
09-21-2021 01:33 PM
Ahh,
ok I asume you contact your switches via a python script. You can start your script against the first switch and than you can change the device focus to other switches with:
cli_result = emc_cli.setIpAddress(switchIp)
and close the session to the switch with
emc_cli.close()
In that way you can move thru your switches within a single workflow and you can write a file for every switch.
Does that help?
09-21-2021 01:23 PM
Thank you for the answer.
I am able to save the text file for one switch with the custom input. I need to do it for several switches and need to have a textfile for each switch.
09-21-2021 01:16 PM
Hello Lunee,
you have two options, among others:
You can realize the whole thing easily with Python as a workflow.