Getting instances by zone returns nothing
Closed this issue · 6 comments
Hi everybody,
i have just started using the python wrapper for the exoscale api but already came across an issue.
I am not able to retrieve all instances by zone, as the generator that is returned is empty.
zones = exo.compute.list_zones()
for zone in zones:
instances = exo.compute.list_instances(zone=zone)
for x in instances:
print(x)
In my case instances
is just an empty generator.
Any idea what is happening here and where the problem is?
exoscale version: 0.8.0
python version: 3.10
Hi @dexma-dev, if you're just getting started can I suggest using the bindings for our v2 API? The namespaces you're using will be deprecated in the near future since they target our legacy API.
It's not clear what is wrong with your code but here is how to achieve what you want with our v2 API:
from exoscale.api.v2 import Client
key = "…"
secret = "…"
c = Client(key, secret) # this creates a client for the default zone
for zone in c.list_zones()["zones"]:
c = Client(key, secret, zone=zone["name"])
for instance in c.list_instances()["instances"]:
print(instance)
You basically have 1 client for each zone you work in. Hope this helps!
@brutasse thank you for your quick reply.
i have already tested the v2 Client, but i am experiencing the same issue. Running your code results in the following:
{'id': '1128bd56-b4d9-4ac6-a7b9-c715b187ce11', 'name': 'ch-gva-2'}
[]
{'id': '91e5e9e4-c9ed-4b76-bee4-427004b3baf9', 'name': 'ch-dk-2'}
[]
{'id': '4da1b188-dcd6-4ff5-b7fd-bde984055548', 'name': 'at-vie-1'}
[]
{'id': '35eb7739-d19e-45f7-a581-4687c54d6d02', 'name': 'de-fra-1'}
[]
{'id': '70e5f8b1-0b2c-4457-a5e0-88bcf1f3db68', 'name': 'bg-sof-1'}
[]
I am not sure what this is related to. I am using an unrestricted API key, as i thought this might be a permission issue
Indeed if your key is unrestricted it's not a perms issue. Can you get in touch with support so that we can have a closer look via a private channel?
@brutasse i did open a support ticket. will report back here after we found a solution
I was able to accomplish what i wanted after using the V2 bindings and using the following api routes:
https://exoscale.github.io/python-exoscale/v2.html#exoscale.api.v2.Client.list_instance_types
https://exoscale.github.io/python-exoscale/v2.html#exoscale.api.v2.Client.get_instance_type
Closing.
Thanks @dexma-dev!