'Waits for the port\'s device_id to be unset.
:param port_id: The id of the port being detached.
:returns: The final port dict from the show_port response.'

def wait_for_port_detach(self, port_id):

    port = self.ports_client.show_port(port_id)['port']
    device_id = port['device_id']
    start = int(time.time())
    while device_id:
        time.sleep(self.build_interval)
        port = self.ports_client.show_port(port_id)['port']
        device_id = port['device_id']
        timed_out = ((int(time.time()) - start) >= self.build_timeout)
        if (device_id and timed_out):
            message = ('Port    %s    failed    to    detach    (device_id    %s)    within    the    required    time    (%s    s).' % (port_id, device_id, self.build_timeout))
            raise lib_exc.TimeoutException(message)
    return port
