[TriZPUG] More Fun With Text Processing

Josh Johnson jj at email.unc.edu
Fri Apr 3 20:36:27 CEST 2009


bob gailer wrote:
> How we handle this depends on what you want to do with the results. 
> Please say more about that.
>
Good point :) I'm just checking for existence.

So, the user wants to create a new LUN[1] on the hardware. I have two 
ways of knowing that the LUN they are trying to create is already there:

1. I can try to make it again and catch the failure -or-
2. I can see if it already exists

I'm opting for option 2, since the hardware isn't very forgiving. Also, 
I'm using pexpect, and that makes error handling a bit weird. I can't 
just respond to a return code, I have to "expect" every possible error 
and handle it.

I also lean towards option 2 since I see a positive side-effect to 
parsing this output: I can easily monitor what's going on, or sync a 
database... which gets to your next point!
> My guess is this would benefit from being put into a database such as 
> sqlite against which you can then run queries.
>
You are totally right here. Long-term, I'd like to keep an easy-to-query 
database of the hardware configuration. But since we may not always be 
using the scripts to interact with the hardware, I need to be able to 
ask the hardware what it thinks it's doing, and reconcile against that 
future database.
> Or my Pipelines program might be the tool of choice.
I'll investigate that. I'm running an interactive program (it's a weird 
ssh-like shell) that's actually getting the tabular data. It's expecting 
a human to chat with it, so I don't know if pipelines can help
> As others have asked - is the format fixed and known? If so then it is 
> easy to split the lines.
It's not fixed, in fact I was hoping to use the same function to parse 
output from several similar commands. However, it does look like the 
field lengths _are_ fixed within a data set, they just might vary from 
call to call.
>> I'd like a structure I can work with, like say, a list of hashes.
>
> Please clarify that. An example perhaps.
I'm just checking to see if something is present already, at this point. 
Eventually I'd like to let the user ask things like "how much space do 
we have left". This is storage hardware.

What I think would be most useful structure-wise would look something 
like this (given the output I mentioned in my first post)

[{'TARGET':'1.1',
   'VOLUME GROUP':'HIGHAVAIL',
   'LENGTH':'5001.023GB',
   'AVAILABLE':'4501.008GB',
   'NPE':'1192337',
   'MIRROR':'2.1'},
  'TARGET':'1.3',
   'VOLUME GROUP':'BACKUP',
   'LENGTH':'5001.023GB',
   'AVAILABLE':'4250.759GB',
   'NPE':'1192337',
   'MIRROR':''},
  etc,
  etc]
>
> You are welcome in advance!
:D


JJ


More information about the TriZPUG mailing list