Class: AutoNetwork::Action::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/auto_network/action/base.rb

Overview

This class is abstract.

Subclass and override #call to implement a new AutoNetwork action.

This is an abstract base class for AutoNetwork actions that provides helper methods for interfacing with a PoolManager object and the Pool instances it manages.

Since:

  • 1.0.0

Direct Known Subclasses

FilterNetworks, LoadPool, Release, Request

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Base

Create a new action instance that is suitable for execution as part of Vagrant middleware.

Parameters:

  • app (#call)

    an instance of an object that responds to call. Typically an object representing a chain of Vagrant actions. Executing call passes execution to the next action in the chain.

  • env (Hash)

    a hash representing the Vagrant state this action executes under. Unfortunately, there are two or three variations of what data can be passed, so Action logic that inspects this parameter is a bit fragile.

Since:

  • 1.0.0



21
22
23
# File 'lib/auto_network/action/base.rb', line 21

def initialize(app, env)
  @app, @env = app, env
end

Instance Method Details

#call(env) ⇒ Object

Raises:

  • (NotImplementedError)

Since:

  • 1.0.0



25
26
27
# File 'lib/auto_network/action/base.rb', line 25

def call(env)
  raise NotImplementedError
end

#filter_private_network(iface, addr) ⇒ void (protected)

This method returns an undefined value.

Convert an auto network to a private network with a static IP address.

This does an in-place modification of the private_network options hash to strip out the auto_network configuration and make this behave like a normal private network interface with a static IP address.

Parameters:

  • iface (Array(Symbol, Hash))
  • addr (String)

    The static IP address to assign to the private network

Since:

  • 1.0.0



61
62
63
64
65
# File 'lib/auto_network/action/base.rb', line 61

def filter_private_network(iface, addr)
  opts = iface[1]
  opts.delete(:auto_network)
  opts[:ip] = addr
end

#machine_auto_networks(machine) ⇒ Array(Symbol, Hash) (protected)

Fetch all private networks that are tagged for auto networking

Parameters:

  • machine (Vagrant::Machine)

Returns:

  • (Array(Symbol, Hash))

    All auto_networks

Since:

  • 1.0.0



45
46
47
48
49
# File 'lib/auto_network/action/base.rb', line 45

def machine_auto_networks(machine)
  machine.config.vm.networks.select do |(net_type, options)|
    net_type == :private_network and options[:auto_network]
  end
end

#machine_has_address?(machine) ⇒ true, false (protected)

Determine if the given machine exists and has an auto_network address

Parameters:

  • machine (Vagrant::Machine)

Returns:

  • (true, false)

Since:

  • 1.0.0



36
37
38
# File 'lib/auto_network/action/base.rb', line 36

def machine_has_address?(machine)
  !!(machine and AutoNetwork.active_pool_manager.address_for(machine))
end