[Openstack] neutron -f json output parsing

Bill Nerenberg bill.nerenberg75 at gmail.com
Fri Sep 30 08:55:44 UTC 2016


Hi all

When I run neutron -f json in the command below, the pools value is quoted
so I cannot use it with JSON parsers like jq

For example, this is neutron's problematic output [1] (see the pools line)

$ neutron lbaas-loadbalancer-show ef315cff-1d0a-4327-93c6-e9bf7e544e2d -f
json
{
  "description": "",
  "admin_state_up": false,
  "tenant_id": "1bcf7ba13bcb496196d72f481bfebb5c",
  "provisioning_status": "ACTIVE",
  "vip_subnet_id": "d02c8267-30be-4cdc-aa4a-a7c1ca6504b8",
  "listeners": "",
  "vip_address": "10.0.2.160",
  "vip_port_id": "07227a77-1afe-466b-9d54-20e8637fc2b0",
  "provider": "f5networks",
  "pools": "{\"id\": \"1b792ace-0cbf-47cc-a3d5-2140c570ccee\"}",
  "id": "ef315cff-1d0a-4327-93c6-e9bf7e544e2d",
  "operating_status": "ONLINE",
  "name": "test-lbaasv2"
}

Which triggers an error in jq (or other tools)

neutron lbaas-loadbalancer-show ef315cff-1d0a-4327-93c6-e9bf7e544e2d -f
json | jq ".pools.id"
jq: error: Cannot index string with string


If instead I use the followin JSON without the double quotes it works just
fine

$ cat myjson
{
  "description": "",
  "admin_state_up": false,
  "tenant_id": "1bcf7ba13bcb496196d72f481bfebb5c",
  "provisioning_status": "ACTIVE",
  "vip_subnet_id": "d02c8267-30be-4cdc-aa4a-a7c1ca6504b8",
  "listeners": "",
  "vip_address": "10.0.2.160",
  "vip_port_id": "07227a77-1afe-466b-9d54-20e8637fc2b0",
  "provider": "f5networks",
  "pools": {"id": "1b792ace-0cbf-47cc-a3d5-2140c570ccee"},
  "id": "ef315cff-1d0a-4327-93c6-e9bf7e544e2d",
  "operating_status": "ONLINE",
  "name": "test-lbaasv2"
}
$ cat myjson | jq ".pools.id"
"1b792ace-0cbf-47cc-a3d5-2140c570ccee"

Questions, questions...

Is it intentional the output of [1] or is it a bug? If it is not a bug and
it is intentional... how is it expected we should be parsing it?

Comments would be greatly appreciated

Many thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack/attachments/20160930/564cc5a4/attachment.html>


More information about the Openstack mailing list