lxd v. 4.12
dnsmasq on non-managed bridge br1 10.0.4.0/22
In past, I got the instance IP by monitoring dnsmasq leases and match with instance name in a shell while loop (till instance appeared in dnsmasq leases!)
It was around 9-20s for fetching the image (depending on size and location) and another 3-5 seconds for instance to boot and reach network runlevel and obtain IP from dnsamsq.
Now with an lxd divided by projects, the above procedure not reliable, as Instance name can be same but in different projects.
Lxd distinguishes at different levels for example storage : project_instancename etc., but dnsmasq uses instancename only without any hint to project. There is no conflict sofar as dnsmasq uses MAC for IP lease, but my past procedure of fetching IP by name through dnsmasq cant work reliably.
I chose following approach to determine the IP4 of instance:
All steps through rest-api:
- launch an instance from image.
- start instance and follow up the operation: /1.0/operations//wait
- fetch /1.0/instances/instancename/state?project=project
Though operation of starting was completed, IP was not available yet (due to instance not in network mode yet or dnsmasq yet not advertising the IP)
How can I adjust the timing for fetching the IP?
Make another loop of each 1-2 seconds /1.0/instances/instancename/state?project=project grabbing for eth0.address !empty ?