Class: VagrantRubydns::Action::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-rubydns/action/setup.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Setup

Returns a new instance of Setup.



4
5
6
# File 'lib/vagrant-rubydns/action/setup.rb', line 4

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

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/vagrant-rubydns/action/setup.rb', line 8

def call(env)
  if env[:global_config].rubydns.enabled?
    DependentVMs.add(env[:machine])
    start_server_if_necessary(env)
    setup_machine_dns(env)
    setup_static_dns(env)
    env[:machine].config.vm.provision :rubydns
  end
  @app.call(env)
end

#setup_machine_dns(env) ⇒ Object



28
29
30
31
32
# File 'lib/vagrant-rubydns/action/setup.rb', line 28

def setup_machine_dns(env)
  hostname, ip_address = Util.host_and_ip(env[:machine])
  env[:ui].info "[rubydns] adding machine entry: #{hostname} => #{ip_address}"
  Store.hosts.set(hostname, ip_address)
end

#setup_static_dns(env) ⇒ Object



34
35
36
37
38
39
# File 'lib/vagrant-rubydns/action/setup.rb', line 34

def setup_static_dns(env)
  env[:global_config].rubydns.hosts.each do |hostname, ip_address|
    env[:ui].info "[rubydns] adding static entry: #{hostname} => #{ip_address}"
    Store.hosts.set hostname, ip_address
  end
end

#start_server_if_necessary(env) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/vagrant-rubydns/action/setup.rb', line 19

def start_server_if_necessary(env)
  if Server.running?
    env[:ui].info "[rubydns] dns server already running"
  else
    env[:ui].info "[rubydns] starting dns server"
    Server.start
  end
end