Sha256: d4d9c7e1bec2d4c0b6ec3c5dfa87e8b5788a5c6bc900fcfdb0b11db70771fbc3

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

module NexusSW
  module LXD
    class Driver
      module Mixins
        module Helpers
          module WaitMixin
            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

            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
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lxd-common-0.9.8 lib/nexussw/lxd/driver/mixins/helpers/wait.rb
lxd-common-0.9.7 lib/nexussw/lxd/driver/mixins/helpers/wait.rb
lxd-common-0.9.6 lib/nexussw/lxd/driver/mixins/helpers/wait.rb