Closed IvanShires closed 4 months ago
Switch that has files in the bootflash:
data = """
switch2_name#
switch2_name#dir bootflash:
Directory of bootflash:/
1 -rwx 19476896 Jan 3 2018 09:15:49 +00:00 cat4500-entservicesk9-mz.150-2.SG10.bin
2 -rw- 1501 May 6 2022 11:18:08 +00:00 network-confg
60817408 bytes total (41338752 bytes free)
"""
get_switch_freespace(data)
Produces expected output:
[['bootflash:/',
'1',
'-rwx',
'19476896',
'60817408',
'41338752',
'Jan 3 2018 09:15:49 +00:00',
'cat4500-entservicesk9-mz.150-2.SG10.bin'],
['bootflash:/',
'2',
'-rw-',
'1501',
'60817408',
'41338752',
'May 6 2022 11:18:08 +00:00',
'network-confg']]
@IvanShires
The "file" line with Record
is the key to why this doesn't work with any files present on flash.
If that Record
line is not matched then nothing gets captured.
I did some experimentation and I can get things to capture a new entry for the TOTAL_SIZE and TOTAL_FREE, but it creates a new entry with a blank file name. This also occurs in the output for a switch that has files.
:question: Is this allowable?
Thoughts? @jvanderaa @jmcgill298
Update: :bulb:
We should probably use Continue.Record
for Directory of
We should probably use
Continue.Record
forDirectory of
@jmcgill298 This does indeed help. The side effect is that there's an extra dictionary with a blank file name in the output which does have files. (example below)
If this isn't a big drawback, I have the changes in a local branch ready to go.
---
parsed_sample:
- date_time: ""
file_system: "bootflash:/"
id: ""
name: ""
permissions: ""
size: ""
total_free: "6612774912"
total_size: "7835619328"
- date_time: "Mar 2 2015 08:46:31 +00:00"
file_system: "bootflash:/"
id: "11"
name: "lost+found"
permissions: "drwx"
size: "16384"
total_free: "6612774912"
total_size: "7835619328"
- date_time: "Mar 2 2015 08:47:35 +00:00"
file_system: "bootflash:/"
id: "681409"
name: ".super.iso.dir"
permissions: "drwx"
size: "4096"
total_free: "6612774912"
total_size: "7835619328"
... snipped ...
@mjbear that is because you are doing Filldown, you can either make a non-filldown Required
, or end the file with EOF
to override the default EOF -> Record
Hmmm. :thinking:
This textfsm template already has EOF at the end.
For raw dir
output with no files, the three values that will be present are FILE_SYSTEM
, TOTAL_SIZE
, and TOTAL_FREE
. The first one is Filldown and the latter two are Fillup.
@jmcgill298 I appreciate the thoughts and guidance! Thank you!
Using the cisco_ios_dir.textfsm template, I am unable to return the "bytes free" field (or bytes total) when there are no files present on the device.
Code:
Which outputs:
[]
Template file:
In my head, this should work.. But I also don't know if there is something I am missing, I am not familiar enough with Regex (specifically with the value parameters) to confidently diagnose this..
show version output: