code: def wait_for_machine(num_machines=1, timeout=300):
      
      # You may think this is a hack, and you'd be right. The easiest way
      # to tell what environment we're working in (LXC vs EC2) is to check
      # the dns-name of the first machine. If it's localhost we're in LXC
      # and we can just return here.
      if get_machine_data()[0]['dns-name'] == 'localhost':
          return 1, 0
      start_time = time.time()
      while True:
          # Drop the first machine, since it's the Zookeeper and that's
          # not a machine that we need to wait for. This will only work
          # for EC2 environments, which is why we return early above if
          # we're in LXC.
          machine_data = get_machine_data()
          non_zookeeper_machines = [
              machine_data[key] for key in list(machine_data.keys())[1:]]
          if len(non_zookeeper_machines) >= num_machines:
              all_machines_running = True
              for machine in non_zookeeper_machines:
                  if machine.get('instance-state') != 'running':
                      all_machines_running = False
                      break
              if all_machines_running:
                  break
          if time.time() - start_time >= timeout:
              raise RuntimeError('timeout waiting for service to start')
          time.sleep(SLEEP_AMOUNT)
      return num_machines, time.time() - start_time
docs: Wait `timeout` seconds for `num_machines` machines to come up.
  
      This wait_for... function can be called by other wait_for functions
      whose timeouts might be too short in situations where only a bare
      Juju setup has been bootstrapped.
  
      :return: A tuple of (num_machines, time_taken). This is used for
               testing.