Module: Landrush::Action::Common

Included in:
InstallPrerequisites, RedirectDns, Setup, Teardown
Defined in:
lib/landrush/action/common.rb

Overview

A module containing shared functionality for Vagrant middleware classes

Constant Summary collapse

SUPPORTED_PROVIDERS =
{
  'VagrantPlugins::ProviderVirtualBox::Provider' => :virtualbox,
  'VagrantPlugins::ProviderLibvirt::Provider'    => :libvirt,
  'HashiCorp::VagrantVMwarefusion::Provider'     => :vmware_fusion,
  'VagrantPlugins::Parallels::Provider'          => :parallels,
  'VagrantPlugins::HyperV::Provider'             => :hyperv,
  'Landrush::FakeProvider'                       => :fake_provider
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



14
15
16
# File 'lib/landrush/action/common.rb', line 14

def self.included(base)
  base.send :attr_reader, :app, :env
end

Instance Method Details

#configObject



55
56
57
58
59
60
61
62
63
# File 'lib/landrush/action/common.rb', line 55

def config
  if env.key? :global_config
    # < Vagrant 1.5
    env[:global_config].landrush
  else
    # >= Vagrant 1.5
    machine.config.landrush
  end
end

#enabled?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/landrush/action/common.rb', line 75

def enabled?
  config.enabled?
end

#guest_redirect_dns?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/landrush/action/common.rb', line 79

def guest_redirect_dns?
  config.guest_redirect_dns?
end

#info(msg) ⇒ Object



83
84
85
# File 'lib/landrush/action/common.rb', line 83

def info(msg)
  env[:ui].info "[landrush] #{msg}"
end

#initialize(app, env) ⇒ Object



18
19
20
21
# File 'lib/landrush/action/common.rb', line 18

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

#libvirt?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/landrush/action/common.rb', line 27

def libvirt?
  provider == :libvirt
end

#log(level, msg) ⇒ Object



87
88
89
90
91
92
93
94
95
96
# File 'lib/landrush/action/common.rb', line 87

def log(level, msg)
  # Levels from github.com/mitchellh/vagrant/blob/master/lib/vagrant/ui.rb
  valid_levels = [:ask, :detail, :warn, :error, :info, :output, :success]

  if valid_levels.include? level
    env[:ui].send level, "[landrush] #{msg}"
  else
    env[:ui].error "[landrush] (Invalid logging level #{level}) #{msg}"
  end
end

#machineObject



51
52
53
# File 'lib/landrush/action/common.rb', line 51

def machine
  env[:machine]
end

#machine_hostnameObject



65
66
67
# File 'lib/landrush/action/common.rb', line 65

def machine_hostname
  @machine_hostname ||= read_machine_hostname
end

#parallels?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/landrush/action/common.rb', line 35

def parallels?
  provider == :parallels
end

#providerObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/landrush/action/common.rb', line 39

def provider
  provider_name = SUPPORTED_PROVIDERS.fetch(machine.provider.class.name) do |key|
    raise "The landrush plugin does not support the #{key} provider yet!"
  end

  if provider_name == :parallels && Gem::Version.new(VagrantPlugins::Parallels::VERSION) < Gem::Version.new('1.0.3')
    raise "The landrush plugin supports the Parallels provider v1.0.3 and later. Please, update your 'vagrant-parallels' plugin."
  end

  provider_name
end

#read_machine_hostnameObject



69
70
71
72
73
# File 'lib/landrush/action/common.rb', line 69

def read_machine_hostname
  return machine.config.vm.hostname if machine.config.vm.hostname

  "#{Pathname.pwd.basename}.#{config.tld}"
end

#virtualbox?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/landrush/action/common.rb', line 23

def virtualbox?
  provider == :virtualbox
end

#vmware?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/landrush/action/common.rb', line 31

def vmware?
  provider == :vmware_fusion
end