Module: Landrush::Action::Common

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

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



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

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

Instance Method Details

#configObject



61
62
63
64
65
66
67
68
69
# File 'lib/landrush/action/common.rb', line 61

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)


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

def enabled?
  config.enabled?
end

#guest_redirect_dns?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/landrush/action/common.rb', line 87

def guest_redirect_dns?
  config.guest_redirect_dns?
end

#handle_action_stack(env) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/landrush/action/common.rb', line 21

def handle_action_stack(env)
  @env = env

  yield

  app.call(env)
end

#info(msg) ⇒ Object



91
92
93
# File 'lib/landrush/action/common.rb', line 91

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

#initialize(app, env) ⇒ Object



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

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

#libvirt?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/landrush/action/common.rb', line 33

def libvirt?
  provider == :libvirt
end

#log(level, msg) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/landrush/action/common.rb', line 95

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



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

def machine
  env[:machine]
end

#machine_hostnameObject



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

def machine_hostname
  @machine_hostname ||= read_machine_hostname
end

#parallels?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/landrush/action/common.rb', line 41

def parallels?
  provider == :parallels
end

#providerObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/landrush/action/common.rb', line 45

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



75
76
77
78
79
80
81
# File 'lib/landrush/action/common.rb', line 75

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

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

#virtualbox?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/landrush/action/common.rb', line 29

def virtualbox?
  provider == :virtualbox
end

#vmware?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/landrush/action/common.rb', line 37

def vmware?
  provider == :vmware_fusion
end