cancel
Showing results for 
Search instead for 
Did you mean: 

Export text file from XMC

Export text file from XMC

Lunee
New Contributor

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.

9 REPLIES 9

Lunee
New Contributor

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.

Lunee
New Contributor
from xmclib import loggerfrom xmclib import emc_varsimport jsonimport redef 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 outputexecConfigCmd("enable")execConfigCmd("terminal length 0")text = execConfigCmd("show eapol multihost interface")print(text)import rep = "(?<=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 = 1non_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 +=1print(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 )

 

StephanH
Valued Contributor III

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?

 

Regards Stephan

Lunee
New Contributor

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.

StephanH
Valued Contributor III

Hello Lunee,

you have two options, among others:

  • For example, you can use the "Activity" mail in the workflow and send the information to you by mail.
  • Or you can save the text file in the file system of the Linux OS. If you include a network share in the Linux/XMC, then you can also store the text file there.

You can realize the whole thing easily with Python as a workflow.

Regards Stephan
GTM-P2G8KFN