'Private function that waits the datacenter
to transition into the specified state.
:return: Datacenter object on success.
:rtype: :class:`.Datacenter`'

def _wait_for_datacenter_state(self, datacenter, state=NodeState.RUNNING, timeout=300, interval=5):

    wait_time = 0
    attempts = 0
    while (attempts < 5):
        attempts += 1
        try:
            datacenter = self.ex_describe_datacenter(ex_datacenter_id=datacenter.id)
            break
        except BaseHTTPError:
            time.sleep(interval)
    if (datacenter is None):
        raise Exception('Data    center    was    not    ready    in    time    to    complete    this    operation.')
    while (datacenter.extra['provisioning_state'] != state):
        datacenter = self.ex_describe_datacenter(ex_href=datacenter.href)
        if (datacenter.extra['provisioning_state'] == state):
            break
        if (wait_time >= timeout):
            raise Exception(("Datacenter    didn't    transition    to    %s    state    in    %s    seconds" % (state, timeout)))
        wait_time += interval
        time.sleep(interval)
    return datacenter
