linode / cli

This is the DEPRECATED Linode CLI. Use https://github.com/linode/linode-cli
https://www.linode.com/docs/platform/linode-cli
Other
466 stars 36 forks source link

[request] IPs array on json result should describe external and internal ip #40

Closed n0n0x closed 6 years ago

n0n0x commented 8 years ago

I can't easily do linode -c linode -a list -j | jq '.[].ips[0]' because the ips array is not ordered, [0] could be either an internal or external IP. It would be great if you can expand this IP list the following way:

      "ips" : {
         "internal_ip": "192.168.205.104",
         "external_ip": "45.79.223.140"
      },

this way I can easily do linode -c linode -a list -j | jq '.[].ips.external_ip' to fetch only the external IP without hard-filtering out internal IPs

displague commented 6 years ago

Thanks for reporting this @n0n0x.

This API v3 based CLI is deprecated in favor of the Linode API v4 based CLI at https://www.github.com/linode/linode-cli (pip install linode-cli).

Using the new CLI and jq, you could split the public and private IPs as such:

$ linode-cli linodes  view $LINODE_ID --json | jq '.[0].ipv4[] | select(test("192.168")|not)'
"23.239.29.162"

$ linode-cli linodes  view $LINODE_ID --json | jq '.[0].ipv4[] | select(test("192.168"))'
"192.168.213.233"

You could also use the linode-cli networking ips-list command with more advanced jq selectors (this is the first time I am using jq selectors, so this may not be the most efficient approach):

$ linode-cli networking ips-list --json | jq  '.[] | select(.public and (.linode_id|contains($LINODE_ID)) and (.type|contains("ipv4"))) | .address'
"23.239.29.162"

You may find that you can reuse the jq selector above to get the same behavior in the deprecated CLI.

Thanks again!