How to determine time of Instance obtaining IP

lxd v. 4.12
dnsmasq on non-managed bridge br1

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:

  1. launch an instance from image.
  2. start instance and follow up the operation: /1.0/operations//wait
  3. 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 ?

Yeah, as mentioned in your other post, there is indeed no current way for us to namespace instances within dnsmasq so parsing the lease file indeed won’t work.

Hitting /1.0/instances/NAME/state?project=project every second or so until you get an address is your best option. LXD itself doesn’t get notified when an instance got an address so there’s no event that LXD can send out, it’s all done externally.