while in one host,if creating the instance and binding port failed,it will raise the PortBindingailed exception; And in the _build_resource function,will catch the exception and call the _shutdown_instance. In the _shutdown_instance fucntion, it will call the self.volume_api.attachment_delete(context, bdm.attachment_id) to delete the attachment_id, because we have created the volume and attachment_id in the _build_resource fucntion.
If we schedule the instance to another host, we have the volume_id and will not recreate the attachment_id again for the volume, However, the attachment_id of the volume has been deleted in the first host. So, we should optimize the code in block_device.py.
while in one host,if creating the instance and binding port failed,it will raise the PortBindingailed exception; And in the _build_resource function,will catch the exception and call the _shutdown_instance. In the _shutdown_instance fucntion, it will call the self.volume_ api.attachment_ delete( context, bdm.attachment_id) to delete the attachment_id, because we have created the volume and attachment_id in the _build_resource fucntion.
If we schedule the instance to another host, we have the volume_id and will not recreate the attachment_id again for the volume, However, the attachment_id of the volume has been deleted in the first host. So, we should optimize the code in block_device.py.