@spuluka Thank you for considering my question and for your response. Did you have a chance to test this out or were you just going with the commit_check description?
If you did test this out, and you actually got the output details I was seeking to capture (basically, the output I would have seen in CLI, containing the hint about the storage being full, in this case) then perhaps I am not doing this right, as am still missing those.
Using commit_check does not seem to provide any information that is beyond or different from what I was getting with commit(). I have not used 'commit check' extensively when working in CLI, and while I am sure there must be some subtle differences in how Junos processes the two commands, operationally there does not seem to be much difference (other than that a successful 'commit check' must be followed up with a commit). Same seems to be the case here. If commit or commit_check/commit fail, I get basically the same error message, I am still missing output details I would have seen in CLI, and I still need to rollback config changes.
With commit():
With commit_check():
Again, what I wanted to capture is output I would have seen in CLI, this time for commit check:
The jnpr.junos.exception is a nice tool the PyEZ makes available, but in this case anyway the way it captures an error misses out on some more specific information. Here it seems it captures error text just from the error on the virtual-chassis master, ignoring the more informative error text from member0 on which the error actually occurs.
I do not mind attempting to write my own code to parse CLI output to extract the info I want. So, my question stands, perhaps rephrased more precisely now:
Is there a way, using PyEZ, to capture output of the commit() command that one would see were one executing commit command directly on the device?
This is possibly not the only command whose output is massaged and cleaned up by PyEZ and something is lost in the process. Is there a way to capture raw/CLI output?
Thank you!
------------------------------
LYDIALYDIA
------------------------------
Original Message:
Sent: 07-28-2021 05:40
From: STEVE PULUKA
Subject: is there a way to capture commit() output when using PyEZ?
I think what you are looking for is the commit check function. This would be run after you load the intended change.
When it returns true you can continue normally.
When it returns an error save that out to your file, rollback the change and move on to the next ip in the inventory.
def commit_check(self): """ Perform a commit check. If the commit check passes, this function will return ``True``. If the commit-check results in warnings, they are reported and available in the Exception errs. :returns: ``True`` if commit-check is successful (no errors) :raises CommitError: When errors detected in candidate configuration. You can use the Exception errs variable to identify the specific problems :raises RpcError: When underlying ncclient has an error """
------------------------------
Steve Puluka BSEET - Juniper Ambassador
IP Architect - DQE Communications Pittsburgh, PA (Metro Ethernet & ISP)
http://puluka.com/home
Original Message:
Sent: 07-28-2021 00:06
From: LYDIA NEMIROVSKY
Subject: is there a way to capture commit() output when using PyEZ?
I am working on a script that eventually will connect to a number of EX switches, whose IPs are contained in an Excel spreadsheet, and make a config change. I am trying to account for possible commit errors, extract unique details of errors and write them to the same file, so that later it would be easy to know and fix the specific issues with each switch where a config failed.
However, I am having a hard time finding info on how I can capture output of an unsuccessful commit operation that I would normally see when SSH'd into a switch or connected via console. For example, I have a 2-switch virtual chassis where storage is full on one of the switches, and thus commit fails. It fails with the following messages:
I would like a chance to capture this commit error and have a chance to distill useful info from it (like a hint that there might be a storage space issue) and write that out to a file.
Is there a way to do this?
I understand that I can use CommitError from jnpr.junos.exception, but the text of that error is not descriptive enough of the specific issue encountered. When I use this with try/except construction I only get:
------------------------------
LYDIA
------------------------------