module NexusSW::LXD::Driver::Mixins::Helpers::WaitMixin

Public Instance Methods

check_for_ip(driver, container_name) click to toggle source
# File lib/nexussw/lxd/driver/mixins/helpers/wait.rb, line 7
def check_for_ip(driver, container_name)
  cc = driver.container(container_name)
  state = driver.container_state(container_name)
  cc[:expanded_devices].each do |nic, data|
    next unless data[:type] == "nic"
    state[:network][nic][:addresses].each do |address|
      return address[:address] if address[:family] == "inet" && address[:address] && !address[:address].empty?
    end
  end
  nil
end
wait_for(container_name, what, timeout = 60) click to toggle source
# File lib/nexussw/lxd/driver/mixins/helpers/wait.rb, line 19
def wait_for(container_name, what, timeout = 60)
  Timeout.timeout timeout do
    loop do
      retval = nil
      case what
      when :cloud_init
        retval = !transport_for(container_name).execute("test -f /run/cloud-init/result.json").error?
      when :ip
        retval = check_for_ip(self, container_name)
      else
        raise "unrecognized option"
      end
      return retval if retval
      sleep 0.5
    end
  end
end