From 5c83eeefd341b1d0dc92ea6d428b617ef9bcb9b0 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Mon, 14 Jan 2013 14:39:32 -0800 Subject: [PATCH 1/1] include nameservers in Node api responses --- app/models/node.rb | 7 +++++++ config/environments/development.rb | 3 +++ config/environments/production.rb | 2 ++ config/environments/test.rb | 2 ++ config/initializers/net_http.rb | 1 + 5 files changed, 15 insertions(+) create mode 100644 config/initializers/net_http.rb diff --git a/app/models/node.rb b/app/models/node.rb index a8b183cf09..d483b3b1ff 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -16,6 +16,12 @@ class Node < ActiveRecord::Base nil end @@domain = Rails.configuration.compute_node_domain rescue `hostname --domain`.strip + @@nameservers = begin + Rails.configuration.compute_node_nameservers + rescue + [Net::HTTP.get(URI('http://169.254.169.254/latest/meta-data/local-ipv4')). + match(/^[\d\.]+$/)[0]] + end api_accessible :superuser, :extend => :common do |t| t.add :hostname @@ -25,6 +31,7 @@ class Node < ActiveRecord::Base t.add :last_ping_at t.add :info t.add :status + t.add lambda { |x| @@nameservers }, :as => :nameservers end def info diff --git a/config/environments/development.rb b/config/environments/development.rb index c16640d48a..5c59d006bb 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -33,4 +33,7 @@ Server::Application.configure do # config.dnsmasq_conf_dir = '/etc/dnsmasq.d' # config.compute_node_domain = `hostname --domain`.strip + + # config.compute_node_nameservers = [Net::HTTP.get(URI('http://169.254.169.254/latest/meta-data/local-ipv4')).match(/^[\d\.]+$/)[0]] + config.compute_node_nameservers = ['192.168.201.3'] end diff --git a/config/environments/production.rb b/config/environments/production.rb index 8fbf0b18cb..d115fa88fd 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -61,4 +61,6 @@ Server::Application.configure do # config.dnsmasq_conf_dir = '/etc/dnsmasq.d' # config.compute_node_domain = `hostname --domain`.strip + + # config.compute_node_nameservers = [Net::HTTP.get(URI('http://169.254.169.254/latest/meta-data/local-ipv4')).match(/^[\d\.]+$/)[0]] end diff --git a/config/environments/test.rb b/config/environments/test.rb index bab2a60cd4..029588c0f8 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -40,4 +40,6 @@ Server::Application.configure do # config.dnsmasq_conf_dir = '/etc/dnsmasq.d' # config.compute_node_domain = `hostname --domain`.strip + + # config.compute_node_nameservers = [Net::HTTP.get(URI('http://169.254.169.254/latest/meta-data/local-ipv4')).match(/^[\d\.]+$/)[0]] end diff --git a/config/initializers/net_http.rb b/config/initializers/net_http.rb new file mode 100644 index 0000000000..5c4dc010a7 --- /dev/null +++ b/config/initializers/net_http.rb @@ -0,0 +1 @@ +require 'net/http' -- 2.30.2