Class: VagrantPlugins::DnsUpdater::Action::SetDnsRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-dns-updater/action/set_dns_record.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ SetDnsRecord

Returns a new instance of SetDnsRecord.



6
7
8
9
# File 'lib/vagrant-dns-updater/action/set_dns_record.rb', line 6

def initialize(app, env)
  @app = app
  @machine = env[:machine]
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vagrant-dns-updater/action/set_dns_record.rb', line 11

def call(env)
  config = @machine.config.dnsupdater
  unless config.registrar.nil?
    interface = config.interface
    registrar = Registrar::Registrar.load config
    @machine.communicate.execute("ip addr show #{interface} | awk '/inet/ && /#{interface}/{sub(/\\/.*$/,\"\",$2); print $2}'") do |type, output|
      raise Vagrant::Errors::VagrantError.new, output if type.to_s == 'stderr'
      ip = output
      @machine.ui.info("Pointing #{config.subdomain}.#{config.zone} to #{ip}")
      registrar.set_dns_record ip
    end
  end
end