linode / linode-cli

The official Linode command line interface.
https://linode.com
BSD 3-Clause "New" or "Revised" License
373 stars 132 forks source link

needs examples: linode-cli nodebalancers rebuild #226

Closed l8gravely closed 3 years ago

l8gravely commented 3 years ago

Hi, I'm working to build Nodebalancer configs (using v5.0.0 of linode-cli, based on 4.85.0 version of API) and I think I would like to use the command:

linode-cli nodebalancers rebuild --configs ....

but there's no examples or even explanation of what the input to the --configs arg is.

Looking at https://www.linode.com/docs/api/nodebalancers/#config-rebuild doesn't even show what to do when using the cli. Is this not supported? Do I just pass in some JSON formatted text?

So I tried using: linode-cli nodebalancers config-view --json XXXX YYYY

then tweaking the parameters returned and doing:

$ linode-cli nodebalancers rebuilt 124991 161299 --configs '[{"id": 161299, "port": 80, "protocol": "http", "algorithm": "roundrobin", "stickiness": "none", "check": "none", "check_interval": 0, "check_timeout": 60, "check_attempts": 3, "check_path": "", "check_body": "", "check_passive": true, "proxy_protocol": "none", "cipher_suite": "recommended", "nodebalancer_id": 124991, "ssl_commonname": "", "ssl_fingerprint": "", "ssl_cert": null, "ssl_key": null, "nodes_status": {"up": 0, "down": 0}}]' No action rebuilt for command nodebalancers

where I just changed the "check_timeout": 60 from 30.

Dorthu commented 3 years ago

Thanks for the report! There is an example on the docs site, but it looks like it's not accurate. The docs for that endpoint also entirely incomplete it seems.

I believe the intention is for it to accept the same arguments a linode-cli nodebalancers config-create, but it doesn't seem to at present. I'm digging into it now to see if i can get it fixed up.

Dorthu commented 3 years ago

Alright, I think this is what it's gonna settle on:

linode-cli nodebalancers config-rebuild $NODEBALANCER_ID $CONFIG_ID \
    --port 80 \
    --check_passive no \
    --nodes '{"address":"$PRIVATE_IP:80","label":"node1"}' \
    --nodes '{"address":"$ANOTHER_PRIVATE_IP:80","label":"node2"}'

It should accept all the same arguments as config-create, but also --nodes once per node you want to add. I'm getting a PR up for this now.

Dorthu commented 3 years ago

That aught to do it - once that's merged and deployed I'll rebuild the CLI and close this issue. Sorry for the inconvenience!

l8gravely commented 3 years ago

Thanks for the quick work! So isn't the :80 for the private IP redundant? Oh wait, not. You can redirect to port 8080 or any other port on the inside.

And this will replace the current config like the docs say? And it looks like you'll be removing the non-working --config .... option too, right?

Dorthu commented 3 years ago

Yep, this will overwrite whatever was in the config with the new values. It looks like you can preserve individual nodes that already exist by including them by ID, like --nodes '{"id":$EXISTING_NODE_ID}' (optionally with other fields to update), but otherwise all existing nodes are removed and the nodes included in the request are created in their place.

The --config option will be removed (it was an artifact of the incorrect spec format)

l8gravely commented 3 years ago

Sweet! This will simplify my using of Ansible to configure nodebalancers by quite a bit.

I think that the top level help for: linode-cli nodebalancers -h should also be updated to say that 'update' does both config and any node(s).

How will it act if the configuration doesn't exist? What will the return codes be for: no existing config, no changes to config, and changes to config?

Dorthu commented 3 years ago

If a config with the given ID doesn't exist, you'll get back a normal 404 (and should use conig-create instead); in the other two cases you'll get back the same response - it doesn't do anything different if there are or are not changes made.

l8gravely commented 3 years ago

Right, that's makes sense. But this gives me a simpler way to add private IPs to the config for sure I think.

Will this be out in v5.0.1?

Dorthu commented 3 years ago

yes, which I just uploaded this morning - let me know if it's working for you so I can close this issue