Class: VagrantRubydns::ResolverConfig

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

Class Method Summary collapse

Class Method Details

.config_fileObject



16
17
18
# File 'lib/vagrant-rubydns/resolver_config.rb', line 16

def self.config_file
  Pathname('/etc/resolver/vagrant.dev')
end

.contents_match?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/vagrant-rubydns/resolver_config.rb', line 20

def self.contents_match?
  config_file.exist? && File.read(config_file) == desired_contents
end

.desired_contentsObject



5
6
7
8
9
10
# File 'lib/vagrant-rubydns/resolver_config.rb', line 5

def self.desired_contents; <<-EOS.gsub(/^      /, '')
  # Generated by vagrant-rubydns
  nameserver 127.0.0.1
  port 10053
  EOS
end

.ensure_config_existsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vagrant-rubydns/resolver_config.rb', line 35

def self.ensure_config_exists
  unless osx?
    puts "Not an OSX machine, so skipping host DNS resolver config."
    return
  end

  if contents_match?
    puts "Host DNS resolver config looks good."
  else
    puts "Need to configure the host."
    write_config
  end
end

.osx?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/vagrant-rubydns/resolver_config.rb', line 12

def self.osx?
  `uname`.chomp == 'Darwin'
end

.puts(str) ⇒ Object



49
50
51
# File 'lib/vagrant-rubydns/resolver_config.rb', line 49

def self.puts(str)
  Kernel.puts("[vagrant-rubydns] #{str}")
end

.write_configObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrant-rubydns/resolver_config.rb', line 24

def self.write_config
  puts "Mometarily using sudo to put the host config in place..."
  Tempfile.open('vagrant_rubydns_host_config') do |f|
    f.write(desired_contents)
    f.close
    `sudo cp #{f.path} /etc/resolver/vagrant.dev`
    `sudo chown root:wheel /etc/resolver/vagrant.dev`
    `sudo chmod 644 /etc/resolver/vagrant.dev`
  end
end