Class: VagrantRubydns::Action::Teardown

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Teardown

Returns a new instance of Teardown.



4
5
6
# File 'lib/vagrant-rubydns/action/teardown.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/teardown.rb', line 8

def call(env)
  if env[:global_config].rubydns.enabled?
    teardown_static_dns(env)
    teardown_machine_dns(env)

    DependentVMs.remove(env[:machine])
    stop_server_if_necessary(env)
  end
  @app.call(env)
end

#stop_server_if_necessary(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vagrant-rubydns/action/teardown.rb', line 19

def stop_server_if_necessary(env)
  if Server.running?
    if DependentVMs.none?
      env[:ui].info "[rubydns] no dependent vms left, stopping dns server"
      Server.stop
    else
      env[:ui].info "[rubydns] there are dependent vms left, leaving dns server"
    end
  else
    env[:ui].info "[rubydns] dns server already stopped"
  end
end

#teardown_machine_dns(env) ⇒ Object



32
33
34
35
36
# File 'lib/vagrant-rubydns/action/teardown.rb', line 32

def teardown_machine_dns(env)
  hostname = Util.hostname(env[:machine])
  env[:ui].info "[rubydns] removing machine entry: #{hostname}"
  Store.hosts.delete(hostname)
end

#teardown_static_dns(env) ⇒ Object



38
39
40
41
42
43
# File 'lib/vagrant-rubydns/action/teardown.rb', line 38

def teardown_static_dns(env)
  env[:global_config].rubydns.hosts.each do |hostname, _|
    env[:ui].info "[rubydns] removing static entry: #{hostname}"
    Store.hosts.delete hostname
  end
end