Sha256: a6b21f0dfdec59785506a3517a24ed356b480a762bc234899b17f00af1e3b926
Contents?: true
Size: 1.07 KB
Versions: 2
Compression:
Stored size: 1.07 KB
Contents
require 'zmq' module VagrantDns UI = Vagrant::UI::Colored.new('dns') class NetworkBinder def bind(vm) (host,ip) = host_ip(vm) Status.new.report(host,ip,:up) end def unbind(vm) (host,ip) = host_ip(vm) Status.new.report(host,ip,:down) end private def host_ip(vm) networks = vm.config.vm.networks.find_all do |type,network_parameters| type == :hostonly end ips = networks.map {|type,params| params.first} host = vm.config.vm.host_name [host,ips.first] end end class Status # if socket is created on middleware initialization vagrant will get stuck def report(host,ip,status) url = CONF.get('zmq_url') if(port_open?('localhost',url.split(':')[-1])) context = ZMQ::Context.new pub = context.socket(ZMQ::PUB) pub.connect(url) UI.say(:debug,"connection made") res = pub.send("#{CHANNEL} #{host} #{ip} #{status.to_s}", ZMQ::NOBLOCK) UI.say(:info,"notifying dns server with #{status} status") pub.close else UI.say(:debug,"dns server isn't up, skiping notifying #{status} status") end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
vagrant-dns-server-0.3 | lib/vagrant_dns/middleware/network_binder.rb |
vagrant-dns-server-0.2 | lib/vagrant_dns/middleware/network_binder.rb |