Sha256: 326202c71d00ddef2e1f47ba423d5e084ae392f232c31824feee09985f676540

Contents?: true

Size: 900 Bytes

Versions: 6

Compression:

Stored size: 900 Bytes

Contents

module Vagrant
  module LXC
    class Driver
      module FetchIpWithAttach
        # Include this so we can use `Subprocess` more easily.
        include Vagrant::Util::Retryable

        def assigned_ip
          ip = ''
          retryable(:on => LXC::Errors::ExecuteError, :tries => 10, :sleep => 3) do
            unless ip = get_container_ip_from_ip_addr
              # retry
              raise LXC::Errors::ExecuteError, :command => "lxc-attach"
            end
          end
          ip
        end

        # From: https://github.com/lxc/lxc/blob/staging/src/python-lxc/lxc/__init__.py#L371-L385
        def get_container_ip_from_ip_addr
          output = @cli.attach '/sbin/ip', '-4', 'addr', 'show', 'scope', 'global', 'eth0', namespaces: 'network'
          if output =~ /^\s+inet ([0-9.]+)\/[0-9]+\s+/
            return $1.to_s
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vagrant-lxc-0.4.0 lib/vagrant-lxc/driver/fetch_ip_with_attach.rb
vagrant-lxc-0.3.4 lib/vagrant-lxc/driver/fetch_ip_with_attach.rb
vagrant-lxc-0.3.3 lib/vagrant-lxc/driver/fetch_ip_with_attach.rb
vagrant-lxc-0.3.2 lib/vagrant-lxc/driver/fetch_ip_with_attach.rb
vagrant-lxc-0.3.1 lib/vagrant-lxc/driver/fetch_ip_with_attach.rb
vagrant-lxc-0.3.0 lib/vagrant-lxc/driver/fetch_ip_with_attach.rb