Posted by: terryhowe | May 19, 2016

OpenStack Client Parsing

I’ve talked to a lot of people using the OpenStack Client that are trying to parse reports formatted with prettytable to access fields.  This kind of surprises me because it isn’t required to use awk, sed or anything else to do this, just use the command line options.  For example, if you wanted to get the id of a server and you know the name:

$ ID=$(openstack server show --format value -c id nfs-server)
$ echo $ID
6bfac570-f7a3-4cd7-a753-9d17d27d588b
$

You can use this technique to get any field that is available to the show command.

These switches are also available for create:

$ VOLUME_ID=$(os volume create --size 1 --format value -c id foo)

The –format and -c switches are also on the list commands, but the names of the fields may be different.  You can use these options for pipes and other scripting activities. Here is a silly example:

$ os server list --format value -c ID | while read ID
> do
> echo $ID
> done
919dd13e-0186-4fbe-8e3d-e2fbb76b5db3
dbbefc39-5d0c-40e8-8d41-7e1b23c752da
550c9852-322c-4a76-9cef-1a8c57878a4a
6bfac570-f7a3-4cd7-a753-9d17d27d588b
ed56f41c-27d3-4612-bce7-267e0626422d
4455507c-bba1-4143-9efc-f5291791e8c5
156a80c0-1355-4112-8915-2f0517c976de
05138f7e-9644-4bdf-abbb-a46eaae66f61
20d3e319-92d7-44a3-884d-849bb4ca9caf
4c2319a2-1835-4907-9da0-db354a32f413
e370e766-195a-4e3a-b4cc-ce083de64e91
$
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: