07-18-2019 11:17 AM
I'm playing around with using Genie in a python script. Whenever I do anything with Genie, like device.connect(), it prints the output to the console. How do I suppress that? Thanks, Mike
Solved! Go to Solution.
10-15-2019 05:29 AM
10-11-2019 08:38 AM - edited 10-11-2019 08:38 AM
Given a device instance, you can change the log settings via the connectionmgr instance.
For example:
import logging
# dev is a Device instance from a testbed
dev.connectionmgr.log.setLevel(logging.ERROR)
# now execute a command and you will not see the output on the console
resp = dev.execute('show version')
# you can print the response
print(resp)
10-15-2019 05:29 AM
10-20-2019 06:14 PM
Thanks Jeremy! That did the trick. However when I use dev.connect(log_stdout=False) then the output is not logged to a file. A few follow up questions:
10-20-2019 07:47 PM
Hi @Mike Assel,
re: connect(log_stdout=False) I learned via a response on Twitter from one of the DevNet genie developers. After I learned this, I did a scan of the sourcecode and I could not find any reference to this Device() argument either. Seem like an opportunity for the DevNet team to add more documentation.
re: logging - even though the console logging is disabled, there is still a logfile. You can find it using the Device.logfile attribute, for example:
In [11]: dev.logfile Out[11]: '/tmp/atlrs21-cli-20191021T024126194.log'
I have not experimented with changing the logfile value.
Hope this helps!
10-21-2019 06:36 AM
My bad. I had checked and thought I did not see a log file, but I checked again and indeed it was there. Thanks for the help.
01-21-2022 07:33 AM
I know this is a blast from the past but would you be willing to take a walk down memory lane and walk me through how you found this? I've spent hours trying it myself. I think my hold up is I can't even find the connect method that the object of class genie.libs.conf.device.nxos.device.Device can run to inspect the code. I looked into all the inherited classes but didn't find a connect method. Using the inspect module it looks like it my be written in C and maybe thats why I can't see the code. How did you find out the exact syntax to use?
I'm using this code in ipython to test
from genie import testbed tb = testbed.load(".\testbed.yaml") core1 = tb.devices.Core1 core1.connect()
01-21-2022 07:54 AM
nevermind, I completely missed the post where you got that straight from a dev
01-21-2022 08:17 AM
stumbled across the documentation for the connect method. It uses another cisco framework call Unicon. On their docs it lists out the options you can use for pyats
05-13-2024 06:09 AM
Here's a direct link to the Unicon device connection arguments.
https://pubhub.devnetcloud.com/media/unicon/docs/user_guide/connection.html#python-apis
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide