Module: NexusSW::LXD::Driver::Mixins::Helpers::WaitMixin

Included in:
CLI, Rest
Defined in:
lib/nexussw/lxd/driver/mixins/helpers/wait.rb

Instance Method Summary collapse

Instance Method Details

#check_for_ip(driver, container_name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# 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) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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