Class: VagrantPlugins::DNS::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-dns/command.rb

Constant Summary collapse

INSTALL_PATH =
"/etc/resolver".freeze

Instance Method Summary collapse

Instance Method Details

#executeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vagrant-dns/command.rb', line 6

def execute
  tmp_dns_path = File.join @env.tmp_path, DNS.namespace
  options      = {}

  opts = OptionParser.new do |o|
    o.banner = "Usage: vagrant destroy [vm-name]"
    o.separator ""

    o.on("-f", "--install", "Install dns resolver on mac.") do |f|
      begin
        if File.directory?(INSTALL_PATH)
          @env.ui.info "Existed install dir #{INSTALL_PATH}"
        else
          @env.ui.info "Creating install dir #{INSTALL_PATH}"
          FileUtils.mkdir_p(INSTALL_PATH)
        end

        registered_resolvers = Dir[File.join(tmp_dns_path, "resolver", "*")]

        @env.ui.info "Installing DNS resolvers #{registered_resolvers} to #{INSTALL_PATH}"

        FileUtils.ln_s(registered_resolvers, INSTALL_PATH, force: true)

      rescue Errno::EACCES => e
        @env.ui.error "vagrant-dns needs superuser access to manipulate DNS settings"
        @env.ui.error "DNS resolvers not installed"

      rescue Errno::EEXIST => e
        @env.ui.error "#{INSTALL_PATH} exists. Please remove it first to force override"
      end
    end
  end

  # Parse the options
  argv = parse_options(opts)
end