Sha256: 22c86bd4166ff110ab1b50be5af880efc5b9f2e3a7b824d11ad9bff6f723fab3

Contents?: true

Size: 1.23 KB

Versions: 6

Compression:

Stored size: 1.23 KB

Contents

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

        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant::lxc::action::fetch_ip_with_lxc_info")
        end

        def call(env)
          env[:machine_ip] ||= assigned_ip(env)
        ensure
          @app.call(env)
        end

        def assigned_ip(env)
          config = env[:machine].provider_config
          fetch_ip_tries = config.fetch_ip_tries
          driver = env[:machine].provider.driver
          ip = ''
          retryable(:on => LXC::Errors::ExecuteError, :tries => fetch_ip_tries, :sleep => 3) do
            unless ip = get_container_ip_from_ip_addr(driver)
              # retry
              raise LXC::Errors::ExecuteError, :command => "lxc-info"
            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(driver)
          output = driver.info '-iH'
          if output =~ /^([0-9.]+)/
            return $1.to_s
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
vagrant-lxc-1.4.2 lib/vagrant-lxc/action/fetch_ip_with_lxc_info.rb
vagrant-lxc-1.4.1 lib/vagrant-lxc/action/fetch_ip_with_lxc_info.rb
vagrant-lxc-2.1-patch-1.4.0 lib/vagrant-lxc/action/fetch_ip_with_lxc_info.rb
vagrant-lxc-1.4.0 lib/vagrant-lxc/action/fetch_ip_with_lxc_info.rb
vagrant-lxc-1.3.1 lib/vagrant-lxc/action/fetch_ip_with_lxc_info.rb
vagrant-lxc-1.3.0 lib/vagrant-lxc/action/fetch_ip_with_lxc_info.rb