make openstack cli -f shell output friendly to bash

Bug #1616323 reported by Robin Cernin on 2016-08-24
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Steve Martinelli

Bug Description

openstack cli is returning a set of variables like for example:


When we use eval for passing all these data to environment variables and they get parsed by script.
We do have problem when openstack returns variables like:


Because the character : is not a a valid character for variable names, also there are variables containing the character -

We could have workaround this by using tr :- _ however then one lose the exit return code with echo $?.

Can we request to implement this a way that all variables returned from openstack cli are shell friendly without characters like : or - only characters allowed to environment variables?

Can be reproduced with:
eval `openstack network show public -f shell`

Results are:
bash: provider:network_type=vxlan: command not found

Expected results would be:
openstack network show public -f shell returning the variables in shell friendly way without characters like : or -.


Steve Martinelli (stevemar) wrote :

Not sure how easy this'll be to maintain. When we "show" a resource, the properties we are displaying often come from the server's response. So, although we could fix this for your specific example, I'm not sure we could actively prevent this from coming up again.

Robin Cernin (rcernin) wrote :


Please can you comment why then we use shell formatter? We thought this is implemented to give out the variables that are shell parseable?

output formatters:
-f {shell,table,value}, --format {shell,table,value} the output format, defaults to table


Hugh Saunders (hughsaunders) wrote :

I just stumbled across this, and added |awk -F= '{gsub(/:/, "_", $1); print ($1"="$2)}' to fix my immediate problem, but it occurred to me that this could be easily fixed in openstack client.
IMO the shell output filter should ensure that keys are valid shell identifiers.

Example rules for doing so:
![a-zA-Z0-9_] --> _
^([0-9]) --> _\1

Hugh Saunders (hughsaunders) wrote :

Update to my awk in comment #3: |awk -F= '{OFS="="; gsub(/[-:]/, "_", $1); print}'

Steve Martinelli (stevemar) wrote :

Let's see if we can fix this in cliff proper

Changed in python-openstackclient:
status: New → Invalid

Fix proposed to branch: master

Changed in python-cliff:
assignee: nobody → Steve Martinelli (stevemar)
status: New → In Progress
Steve Martinelli (stevemar) wrote :

I posted a patch, feel free to try it out and review

Submitter: Jenkins
Branch: master

commit a89dbbb2fe305656e8b3ed60a5273ff8f50bb233
Author: Steve Martinelli <email address hidden>
Date: Wed Nov 9 12:28:04 2016 -0500

    Replace dashes and colons when using bash formatter

    When a resource property has dashes and colons and
    the bash formatter is used, it actually breaks with
    `command not found`.

    For example, when doing:
      eval `osc network show public --format shell`

    The network resource has a property:

    Which results in:
      "bash: provider:network_type=vxlan: command not found"

    Change-Id: I57ca08c9dfd7ef022ab91d50ec42a98a6df08b09
    Closes-Bug: #1616323

Changed in python-cliff:
status: In Progress → Fix Released
Steve Martinelli (stevemar) wrote :

This should be fixed in the next version of OpenStackClient (3.4.0)

This issue was fixed in the openstack/cliff 2.3.0 release.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers