include nameservers in Node api responses
authorTom Clegg <tom@clinicalfuture.com>
Mon, 14 Jan 2013 22:39:32 +0000 (14:39 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Mon, 14 Jan 2013 22:39:32 +0000 (14:39 -0800)
app/models/node.rb
config/environments/development.rb
config/environments/production.rb
config/environments/test.rb
config/initializers/net_http.rb [new file with mode: 0644]

index a8b183cf095f3de4e9989ed51afd428bb42944c3..d483b3b1ff38857f8cb6bc54697845a6fe7ab8f6 100644 (file)
@@ -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
index c16640d48a3f0087d5b85336aa27da2452f9e954..5c59d006bb7839598d1a82e8bcbc3a0e11a21f65 100644 (file)
@@ -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
index 8fbf0b18cb06d5d2099107350171ad2d40f570fe..d115fa88fdd1e272cc7e0254108f046dfcce0116 100644 (file)
@@ -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
index bab2a60cd4b4bd9d4b915dd46f66f16b94a06aa1..029588c0f8f01d85dc55e3faca906a439857b85e 100644 (file)
@@ -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 (file)
index 0000000..5c4dc01
--- /dev/null
@@ -0,0 +1 @@
+require 'net/http'