[openstack-dev] [openstackclient] Use and practices of --format shell for defining individual variables

Ronald Bradford me at ronaldbradford.com
Tue May 26 15:18:09 UTC 2015


Hi list,

I came across the following neutron client specific syntax and decided to
see if I could reproduce using the openstack client and it's flexible
formatting capabilities


$ NIC_ID1=$(neutron net-show public | awk '/ id /{print $4}')

$  echo $NIC_ID1
210d976e-16a3-42dc-ac31-f01810dbd297

I can get similar syntax (unfortunately lowercase variable name only) with:
NOTE: It may be nice to be able to pass an option to UPPERCASE all shell
variables names.

$ openstack network show public -c id --format shell --prefix nic_
nic_id="210d976e-16a3-42dc-ac31-f01810dbd297"

However to use this I effectively have to place in a file and source that
file to expose this variable to my current running shell.
Reproducing the same syntax does not work obviously.

$ NIC_ID2=$(openstack network show public -c id --format shell)
$  echo $NIC_ID2
id="210d976e-16a3-42dc-ac31-f01810dbd297"

And even stripping out the "name=" portion still results in a quoted
response.

$ NIC_ID3=$(openstack network show public -c id --format shell | cut -d=
-f2)
$ echo $NIC_ID3
"210d976e-16a3-42dc-ac31-f01810dbd297"

So in order to accurately reproduce I need the following which seems more
long winded then the original.

$ NIC_ID4=$(openstack network show public -c id --format shell | cut -d=
-f2 | tr -d '"')
$ echo $NIC_ID4
210d976e-16a3-42dc-ac31-f01810dbd297

While I presume the intended use to create a file to source variables is
there any merit it supporting per variable definition as in this example?

Any thoughts appreciated.


Regards

Ronald
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20150526/0046fae1/attachment.html>


More information about the OpenStack-dev mailing list