Permalink
Browse files

Use multiple discovery methods for Razor's IP

  • Loading branch information...
1 parent 725a01a commit 4924b9df3cd3567b4080f17dc4a6b434b75d5f70 @GregSutcliffe GregSutcliffe committed Nov 5, 2012
Showing with 48 additions and 2 deletions.
  1. +41 −0 razor_microkernel/rz_network_utils.rb
  2. +7 −1 rz_mk_init.rb
  3. +0 −1 usr/share/udhcpc/dhcp_mk_config.script
@@ -134,5 +134,46 @@ def wait_until_nw_avail
end
+ def discover_rz_server_ip
+ discover_by_pxe or discover_by_dns or discover_by_dhcp
+ end
+
+ def discover_by_pxe
+ begin
+ contents = File.open("/proc/cmdline", 'r') { |f| f.read }
+ server_ip = contents.split.map { |x| $1 if x.match(/razor.ip=(.*)/)}.compact
+ if server_ip.size == 1
+ return server_ip.join
+ else
+ return false
+ end
+ rescue
+ return false
+ end
+ end
+
+ def discover_by_dns
+ begin
+ contents = File.open("/proc/cmdline", 'r') { |f| f.read }
+ server_name = contents.split.map { |x| $1 if x.match(/razor.server=(.*)/)}.compact
+ server_name = server_name.size == 1 ? server_name.join : 'razor'
+
+ require 'socket'
+ return TCPSocket.gethostbyname(server_name)[3..-1].first || false
+ rescue
+ return false
+ end
+ end
+
+ def discover_by_dhcp
+ udhcp_file = "/tmp/nextServerIP.addr"
+ begin
+ contents = File.open(udhcp_file, 'r') { |f| f.read }
+ return contents.strip
+ rescue
+ return false
+ end
+ end
+
end
end
View
@@ -55,14 +55,20 @@
# and proceed with startup of the network-dependent tasks
puts "Network is available, proceeding..."
+ # Discover the IP of the Razor server
+ ip = rz_nw_util.discover_rz_server_ip
+ puts "Discovered Razor Server at: #{ip}"
+ y = YAML.load_file('/tmp/mk_conf.yaml')
+ y["mk_uri"] = "http://#{ip}:8026"
+ File.open('/tmp/mk_conf.yaml', 'w') {|f| f.write(y.to_yaml) }
+
# first, set the hostname for this host to something unique
# (waited until now because didn't want to have eth0 not
# available at this point)
rz_host_util = RazorMicrokernel::RzHostUtils.new
rz_host_util.set_host_name
# next, start the rz_mk_web_server, rz_mk_tce_mirror and rz_mk_controller scripts
-
%x[sudo /usr/local/bin/rz_mk_web_server.rb 2>&1 > /tmp/rz_web_server.out]
%x[sudo /usr/local/bin/rz_mk_tce_mirror.rb 2>&1 > /tmp/rz_mk_tce_mirror.out]
%x[sudo /usr/local/bin/rz_mk_controller.rb start]
@@ -37,7 +37,6 @@ case "$1" in
if [ -n "$siaddr" ] ; then
# added by tjmcs, 28-Feb-2012
echo $siaddr > /tmp/nextServerIP.addr
- sed -i "s/RAZOR_URI_IP_ADDR/$siaddr/" /tmp/mk_conf.yaml
fi
;;
esac

0 comments on commit 4924b9d

Please sign in to comment.