linode-cli icon indicating copy to clipboard operation
linode-cli copied to clipboard

linodes list-ips output not working as expected for --json and --text

Open l8gravely opened this issue 3 years ago • 4 comments

Using linode-cli v5.0.1, when I run the command:

linode-cli linodes ips-list --json --suppress-warnings --format 'private' 123456

I get some json-like outpout. But when I do it with '--text --no-headers' I get shorter more targeted output but also in json format.

For example, --json first.

$ linode-cli linodes ips-list --suppress-warnings --format 'private' --json 25152787
[{"ipv4": {"private": [{"address": "192.168.215.203", "gateway": null, "subnet_mask": "255.255.128.0", "prefix": 17, "type": "ipv4", "public": false, "rdns": null, "linode_id": 25152787, "region": "us-central"}]}}]

Now with '--text --no-headers' instead:

$ linode-cli linodes ips-list --suppress-warnings --format 'private' --text --no-headers 25152787
{'address': '192.168.215.203', 'gateway': None, 'subnet_mask': '255.255.128.0', 'prefix': 17, 'type': 'ipv4', 'public': False, 'rdns': None, 'linode_id': 25152787, 'region': 'us-central'}

See how it comes out in JSON mode? This is actually what I want the first format to be, since it's simpler to parse within Ansible.

l8gravely avatar Mar 12 '21 20:03 l8gravely

Hmm.. looking at the normal console output for that operation I suspect that it's not being parsed very well:

┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─────────┬────────┬──────────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬────────┐
│ public                                                                                                                                                                                                                    │ private │ shared │ reserved │ link_local                                                                                                                                                                                                     │ slaac                                                                                                                                                                                                              │ global │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────┼────────┼──────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────┤
│ {'address': '192.81.134.229', 'gateway': '192.81.134.1', 'subnet_mask': '255.255.255.0', 'prefix': 24, 'type': 'ipv4', 'public': True, 'rdns': 'li620-229.members.linode.com', 'linode_id': 8221065, 'region': 'us-west'} │         │        │          │ {'address': 'fe80::f03c:91ff:fe95:aa28', 'gateway': 'fe80::1', 'subnet_mask': 'ffff:ffff:ffff:ffff::', 'prefix': 64, 'type': 'ipv6', 'rdns': None, 'linode_id': 8221065, 'region': 'us-west', 'public': False} │ {'address': '2600:3c01::f03c:91ff:fe95:aa28', 'gateway': 'fe80::1', 'subnet_mask': 'ffff:ffff:ffff:ffff::', 'prefix': 64, 'type': 'ipv6', 'rdns': None, 'linode_id': 8221065, 'region': 'us-west', 'public': True} │        │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴─────────┴────────┴──────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴────────┘

The command you're using is correct, but the output is definitely wrong. I hate to say that you shouldn't depend on it, since it's probably worth fixing - the output above is pretty much unusable.

Dorthu avatar Mar 12 '21 21:03 Dorthu

Yes, the output for the --json case is useless, I spent all day screwing around trying to parse it in various ansible tasks. Then on a whim I tried the --text format and it gave me useful outout that I can now use. I'm certainly finding all the edge cases lately... :-)

Also, note that I'm not trying to get the public IP, I'm just trying to get the single private IP, if it exists, for a group of linodes. So I'm doing a bunch of silly loops and such to make this work. It would be nice if there was somehow a way to ask for and get just the single private IP if it exists.

Not sure what the answer really is.

Well... the answer is for the Ansible linode_v4 module to grow some more features. Heh.

l8gravely avatar Mar 12 '21 21:03 l8gravely

While there isn't a loop-free way to find all private IPs for a group of Linodes in one call, you might get something like what you're looking for by searching for a single tag or group from linode-cli linodes list and asking for the ipv4s back. In this case, I'm showing all the ipv4s for all linodes tagged "demo2" on my account:

$ linode-cli linodes list --tags demo2 --format 'ipv4' --text --no-headers
192.81.134.229
45.79.5.231
45.79.180.86
97.107.138.83
162.216.19.10 192.168.160.16

The last row has a public and a private IP - you'd still need to loop over them and see if each address was in the private range, but it might be easier than what you're doing now.

Dorthu avatar Mar 15 '21 11:03 Dorthu

"William" == William Smith @.***> writes:

William> While there isn't a loop-free way to find all private IPs for William> a group of Linodes in one call, you might get something like William> what you're looking for by searching for a single tag or William> group from linode-cli linodes list and asking for the ipv4s William> back. In this case, I'm showing all the ipv4s for all linodes William> tagged "demo2" on my account:

William> $ linode-cli linodes list --tags demo2 --format 'ipv4' --text --no-headers William> 192.81.134.229 William> 45.79.5.231 William> 45.79.180.86 William> 97.107.138.83 William> 162.216.19.10 192.168.160.16

William> The last row has a public and a private IP - you'd still need William> to loop over them and see if each address was in the private William> range, but it might be easier than what you're doing now.

Thanks for your help William! I turns out there's a bug in linode-cli and if you do:

linode-cli linodes ips-list --text --format 'private' --no-headers

you get back a much easier to parse reply. But I'm also intrigued by the previous couple of emails which talk about doing

  • debug: msg: "{{ somevar.stderr|type_debug }}"

to help decipher stuff. But in general the linode-cli tool has some bugs and they're getting worked on.

Cheers, John

l8gravely avatar Mar 15 '21 14:03 l8gravely

Unfortunately, this issue seems to be the result of the linode/instances/{linodeId}/ips endpoint not conforming to the typical list endpoint response format. In this case, the response contains a variety of nested structures and lists. As a result, using --format 'private' returns the entire response structure filtered to only include portions relevant to the ipv4.private field.

I'll bring this up with my team and see what we can do about improving the column processing and table formatting logic for one-off endpoints like this :slightly_smiling_face:

lgarber-akamai avatar Nov 07 '22 19:11 lgarber-akamai