Class: Landrush::Action::Setup

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/landrush/action/setup.rb

Constant Summary

Constants included from Common

Common::SUPPORTED_PROVIDERS

Instance Method Summary collapse

Methods included from Common

#enabled?, #global_config, #handle_action_stack, included, #info, #initialize, #machine, #machine_hostname, #provider, #virtualbox?, #vmware?

Instance Method Details

#add_prerequisite_network_interfaceObject



28
29
30
31
32
33
# File 'lib/landrush/action/setup.rb', line 28

def add_prerequisite_network_interface
  return unless virtualbox? && !private_network_exists?

  info 'virtualbox requires an additional private network; adding it'
  machine.config.vm.network :private_network, type: :dhcp
end

#call(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/landrush/action/setup.rb', line 6

def call(env)
  handle_action_stack(env) do
    pre_boot_setup if enabled?
  end

  # This is after the middleware stack returns, which, since we're right
  # before the Network action, should mean that all interfaces are good
  # to go.
  record_machine_dns_entry if enabled?
end

#pre_boot_setupObject



17
18
19
20
21
22
# File 'lib/landrush/action/setup.rb', line 17

def pre_boot_setup
  record_dependent_vm
  add_prerequisite_network_interface
  start_server
  setup_static_dns
end

#private_network_exists?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/landrush/action/setup.rb', line 57

def private_network_exists?
  machine.config.vm.networks.any? { |type, _| type == :private_network }
end

#record_dependent_vmObject



24
25
26
# File 'lib/landrush/action/setup.rb', line 24

def record_dependent_vm
  DependentVMs.add(machine_hostname)
end

#record_machine_dns_entryObject



49
50
51
52
53
54
55
# File 'lib/landrush/action/setup.rb', line 49

def record_machine_dns_entry
  ip_address = machine.guest.capability(:read_host_visible_ip_address)

  info "adding machine entry: #{machine_hostname} => #{ip_address}"

  Store.hosts.set(machine_hostname, ip_address)
end

#setup_static_dnsObject



42
43
44
45
46
47
# File 'lib/landrush/action/setup.rb', line 42

def setup_static_dns
  global_config.landrush.hosts.each do |hostname, dns_value|
    info "adding static entry: #{hostname} => #{dns_value}"
    Store.hosts.set hostname, dns_value
  end
end

#start_serverObject



35
36
37
38
39
40
# File 'lib/landrush/action/setup.rb', line 35

def start_server
  return if Server.running?

  info 'starting dns server'
  Server.start
end