The association of a Nova instance to an Ironic node represents the "ownership" of that node. This is currently updated by sending a PATCH request to the API service, which will replace the current value of `nodes`.`instance_uuid` with the supplied value. Because this a node property, not a nested property, it is not possible to remove it; instance_uuid can only be replaced.
Even if the Nova driver implements a LBYL approach -- first, GET the node and check that instance_uuid is empty, then PATCH the new value -- it would still be possible for another client (another instance of nova-compute) to PATCH at the same time, leading to unexpected behavior.
Since Ironic does not return an exception when overwriting the instance_uuid, it is not currently possible for the Nova driver to implement a EAFP approach, and there is no way to avoid a race condition here.
For reference, I solved this in the nova baremetal code with the db.api method bm_node_ associate_ and_update, here:
http:// git.openstack. org/cgit/ openstack/ nova/tree/ nova/virt/ baremetal/ db/sqlalchemy/ api.py# n190