linode_api4-python
linode_api4-python copied to clipboard
Missing/Insufficent Documentation on how to query specific Linode instances
I am trying to query the status of a Linode instance I created via the API. I haven't found any good examples of this being done anywhere online so I looked at the docs. Looking at the LinodeClient documentation, I see the client.linode.instances() function to get all instances: https://linode-api4.readthedocs.io/en/latest/linode_api4/linode_client.html?highlight=linode.instance_create#linode_api4.linode_client.LinodeGroup.instances
This function is supposed to take a filter as a parameter. However, when I try that exact example I get an error:
>>> client.linode.instances(Instance.group == "prod")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Instance' is not defined
Where is this 'Instance' object supposed to come from? I suspect there is an import I am missing, but the docs are only using: from linode_api4 import LinodeClient
It would be nice if there were more code example of doing common tasks with the API. I see some example of creating Linode instances but I can't find many for querying existing instances or changing configuration on existing instances.
Thanks for the feedback! There is additional documentation on filtering here, but it also does not include the full import paths required to actually make the example code work. I'll update both example to include the relevant imports.
The docs note how to update existing models here; what could make this better to explain how to update existing services?
Thanks for the quick response.
Thanks for updating the examples to add the import paths. I think that will help others in the future trying the code examples. I was able to get my script working by adding from linode_api4.objects import *
and then modifying the code a bit:
>>> client.linode.instances(linode.Instance.group == "prod")
I must have missed that section on updating models. That looks fine as a generic example of how to modify existing resources. One things I could recommend though is a full example of how to update a resource to do some real world task. Something like a full python file showing how to add another disk. That could show all the imports needed, the process of setting up the client, making the update, and just showing the best practice on how to do so.