Problem: A command generates a table that makes it very hard to script around.
Solution: Convert table into a Python dictionary for much more efficient use. These tables can have 1 - 20 differing virtual drives and attributes such as "Name" may not be set.
Example Table:
Virtual Drives = 4
VD LIST :
=======
----------------------------------------------------------
DG/VD TYPE State Access Consist Cache sCC Size Name
----------------------------------------------------------
0/0 RAID1 Optl RW No RWTD - 1.818 TB one
1/1 RAID1 Optl RW No RWTD - 1.818 TB two
2/2 RAID1 Optl RW No RWTD - 1.818 TB three
3/3 RAID1 Optl RW No RWTD - 1.818 TB four
4/4 RAID10 Reblg RW No RWTD - 4.681 TB
----------------------------------------------------------
Example Dictionary:
{"DG/VD":"0/0", "TYPE":"RAID1", "State":"Optl", "Access":"RW", "Consist":"No", "Cache":"RWTD", "sCC":"-", "Size":"1.818 TB", "Name":"one"}
{"DG/VD":"4/4", "TYPE":"RAID10", "State":"Reblg", "Access":"RW", "Consist":"No", "Cache":"RWTD", "sCC":"-", "Size":"4.681 TB", "Name":""}
There would be a total of four dictionaries, one for each virtual drive. How best to solve this issue?
I have some ideas. First, search for the table header and split on spaces to define a list. Second, search for the virtual drive with "number/number" and split on spaces to define the second list. However, 'Size' will need to be special as it will need to ignore the space between number and "TB".
Next, zip the two lists together to generate a dictionary. Does anybody have a better idea for manipulating this text?
# Create a list of all the headers in the virtual disk table
get_table_header = " /c0/vall show | awk '/^DG\/VD/'"
table_header_values = console_info(utility + get_table_header).split()
['DG/VD', 'TYPE', 'State', 'Access', 'Consist', 'Cache', 'sCC', 'Size', 'Name']
# Create a list of all virtual drives
get_virtual_drives = " /c0/vall show | awk '/^[0-9]\/[0-9]/'"
virtual_drive_values = console_info(utility + get_virtual_drives).split()
["0/0", "RAID1", "Optl", "RW", "No", "RWTD", "-", "1.818", "TB", "0"]