cancel
Showing results for 
Search instead for 
Did you mean: 
Post a Question
Highlighted
Jin_Zhou
Nickel

Find out if an object exists for a network with mgmt_cli

I am trying to find out if an object exists for a network with exact match. But "mgmt_cli show objects" gives more than I wanted. For example I need to find if an object exist for network "52.0.0.0/15" exist. I tried the following.

mgmt_cli show objects type network filter "52.0.0.0/15" -f json -r true -d Internet

and

mgmt_cli show objects type network filter "52.0.0.0" -f json -r true -d Internet

They all give the same output with additional info for 52.0.0.0/8. Is there a way to get a result with the exact match?

{
"from" : 1,
"to" : 2,
"total" : 2,
"objects" : [ {
"uid" : "0bbb18f7-9d3d-49c7-bfc4-e4c569dcd5bb",
"name" : "Net52.0.0.0-15",
"type" : "network",
"domain" : {
"uid" : "aa6cae9a-7dd9-4a6d-b5bd-4d6bcedb25d4",
"name" : "Internet",
"domain-type" : "domain"
},
"subnet4" : "52.0.0.0",
"mask-length4" : 15,
"subnet-mask" : "255.254.0.0"
}, {
"uid" : "085626b1-8c50-40c9-8c8d-a924b96ce62a",
"name" : "net52.0.0.0-8",
"type" : "network",
"domain" : {
"uid" : "aa6cae9a-7dd9-4a6d-b5bd-4d6bcedb25d4",
"name" : "Internet",
"domain-type" : "domain"
},
"subnet4" : "52.0.0.0",
"mask-length4" : 8,
"subnet-mask" : "255.0.0.0"
} ]
}

 

 

0 Kudos
2 Replies
Jin_Zhou
Nickel

Re: Find out if an object exists for a network with mgmt_cli

Anyone has any idea? Now I am trying to use jq to get the exact match. The following works.

mgmt_cli show objects type network filter "52.0.0.0/15" -f json |  jq -r '.objects[]|select(."mask-length4" == 15)'

but if I try to pass a variable it won't work. There is no error but just no output. Tried the following.

LEN=15

mgmt_cli show objects type network filter "52.0.0.0/15" -f json |  jq -- arg v1 $LEN -r '.objects[]|select(."mask-length4" == $v1)'

or

mgmt_cli show objects type network filter "52.0.0.0/15" -f json |  jq -- arg v1 15 -r '.objects[]|select(."mask-length4" == $v1)'

 

I wonder if jq on GAIA is not a full version.

0 Kudos
Jin_Zhou
Nickel

Re: Find out if an object exists for a network with mgmt_cli

Figured out the problem and a workaround. 

jq --arg variable only passed as a string. So the select test is always false. There is another option jq --argjson but version 1.4 does not support it. The workaround is to echo the whole mgmt_cli command line to a file and make the file executable and run it. 

0 Kudos