Hi folks,

I'm looking for feedback on a proposal for the format of parseable output from 
networking commands.  In general, it's helpful for building administrative 
scripts as well as test cases that there be some way to cause networking 
commands to issue output in a format that is stable and easy for scripts to 
parse.  Some of the more recently designed Solaris administrative commands 
already provide this feature.  On snv_83:

# dladm show-link -p
LINK="e1000g0" CLASS="phys" MTU="1500" STATE="up" OVER=""
LINK="e1000g1" CLASS="phys" MTU="1500" STATE="unknown" OVER=""
LINK="e1000g2" CLASS="phys" MTU="1500" STATE="unknown" OVER=""
LINK="e1000g3" CLASS="phys" MTU="1500" STATE="unknown" OVER=""

# dladm show-phys -p
LINK="e1000g0" MEDIA="Ethernet" STATE="up" SPEED="1000" DUPLEX="full" 
DEVICE="e1000g0"
LINK="e1000g1" MEDIA="n" STATE="unknown" SPEED="0" DUPLEX="half" 
DEVICE="e1000g1"
LINK="e1000g2" MEDIA="n" STATE="unknown" SPEED="0" DUPLEX="half" 
DEVICE="e1000g2"
LINK="e1000g3" MEDIA="n" STATE="unknown" SPEED="0" DUPLEX="half" 
DEVICE="e1000g3"

$ zoneadm list -p
0:global:running:/::native:shared

These two examples illustrate that there is already a bit of inconsistency in 
the format of parseable output among Solaris administrative commands.  What I'm 
hoping to do is build some consensus around a format that is acceptable 
specifically for networking commands, so at least those commands can produce 
output in a consistent format.  My examples focus on "ipmpstat", since we're 
currently working to define the parseable format output for that command.  
Additional work will be needed to make dladm fall in line as well.  I'd like to 
focus just on parseable output, and not other aspects of the ipmpstat command, 
which are really part of the larger Clearview/IPMP project design.

1. How to activate parseable output

Generally, a command line switch is used to activate parseable output.  I'm 
proposing "-P".  This leaves "-p" available for other uses in commands that are 
frequently entered by hand at the command line.  Existing networking commands 
that produce parseable output already via some other switch will have to be 
addressed on a case by cases basis; in some cases it may be possible to change 
them to the standard, in others, it will be necessary to continue using an 
alternative option letter (dladm falls into the latter category).

In addition, the "-o list" switch will instruct the command which fields to 
emit in the parseable output.  This would look like:

ipmpstat -g -P -o groupname,group

This allows a script to request only fields that are of interest to it.

Going forward, the -o switch should be required with -P.  If we do not require 
the caller to explicitly list the fields it's interested in, we can't add new 
fields in the future without potentially breaking existing scripts.

2. How to format parseable output

Of primary consideration in choosing an output format is ease of parsing by 
shell scripts.  The assumption is that more elaborate scripting languages like 
perl or python can parse any reasonable output format without too much trouble.

Toward that end, the current output of "dladm show-link -p", as show above, 
looks promising, but actually has a couple of major pitfalls.  While it's 
trivial to get access to the set of field values by eval-ing the output one 
line at a time, this has the disadvantage of possibly clobbering variables 
already in use by the script.  This means that any time a new field is added, 
there is the potential to break any script that happened to use that field name 
as a local variable.  Another problem is security related - any command where a 
non-privileged user might gain control over any field's value makes eval as 
root (say, in an admin script) unsafe.

So, I'm suggesting we use a simple field separator scheme as is already 
employed by "zoneadm list -p"  The hitch is the separator itself - ":" may work 
well for zoneadm, but for networking commands, ":" will be showing up 
frequently in IPv6 addresses, making an alternative field separator preferable. 
 For that reason I'm suggesting "|" as the field separator.

Finally, since there is always the possibility that some field value will have 
a literal "|" in it, parseable output will escape literal "|" as "\|", and 
literal "\" as "\\".

As it happens, this output is already parsed nicely by the shell read command:

echo 'ant|bat\|cat|dog\\|elk' | while IFS='|' read a b c d; do
    echo "a=$a, b=$b, c=$c, d=$d"
done
a=ant, b=bat|cat, c=dog\, d=elk

So, the final syntax suggested would work like this:

Human readable output:
# ipmpstat -g -o groupname,group
GROUPNAME     GROUP
joe's group          ipmp2

Parseable output:
# ipmpstat -P -g -o groupname,group
joe's group|ipmp2

So ... any comments?

-John
 
 
This message posted from opensolaris.org
_______________________________________________
networking-discuss mailing list
[email protected]

Reply via email to