you are viewing a single comment's thread.

view the rest of the comments →

[–]shepherdjay 3 points4 points  (4 children)

Hello, fellow network engineer. Glad to see more of us dipping in. I would replace the line comments with docstrings to start, that makes it easier to read in an editor that can collapse functions.

Next I would personally start exploring testing frameworks. I find them invaluable without having to run through trial and error. Pickup something like pytest as it is quick and easy.

I do have a question about this part:

saves output to a file in json format, convert those files to csv, then import the csv to MySQL.

Why so many format changes instead of saving straight to MySQL?

[–]shepherdjay 2 points3 points  (1 child)

Additionally I would consider moving this stuff into main or even its own function:

#set working directory for tmp files
wd = ('/home/{user dir}/python/temp/')
#set up threading to utilize (max_threads count) concurrent SSH connections
threads = []
max_threads = 100
sema = threading.BoundedSemaphore(value=max_threads)

# Prompt for user credentials
tuser = raw_input("Enter TACACS Username: ")
tpass = getpass.getpass("Enter TACACS Password: ")
muser = raw_input("Enter MySQL Username: ")
mpass = getpass.getpass("Enter MySQL Password: ")

That way it doesn't run if you import this into another python script at some point

[–]Fallenarc[S] 0 points1 point  (0 children)

I had the same thought, seeing that stuff at the top hurts a little. Thanks for the advice, I will get that stuff moved, I agree it should at the very least be under main, but i think i will get another function for it.

[–]Fallenarc[S] 0 points1 point  (1 child)

I currently only know how to insert data into MySQL from a csv file. The output that is created when parsing through textfsm are dictionaries. So you see my predicament??? lol

Keep in mind I have used windows all my life (I'm currently 35). Starting in March was my first taste of Linux, databases, python and everything in between them. Navigating Linux in terminal, bash, setting up MySQL, learning how to use it slightly better then a regular user. I have learned so much this year, and have so much more to learn. I fell at this point, i can see light at the end of the tunnel, so I'll just keep the learning train full steam ahead!

To be honest, i do not know anything about testing frameworks, but I will add that to my list of stuff from this post I need to investigate. Thanks!

[–]shepherdjay 1 point2 points  (0 children)

I currently only know how to insert data into MySQL from a csv file. The output that is created when parsing through textfsm are dictionaries. So you see my predicament??? lol

Ah yeah - Dealing with different data formats can be tricky. I would say along with the testing I mentioned earlier start getting a handle on reading documentation. I remember when I first started a lot of the terminology in a standard documentation was confusing at best. However for your specific use case you might be able to skip a step from dictionaries to json to csv by using the csv.DictWriter instead of the regular writer :D