summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Hicks <mhicks@redhat.com>2008-06-09 16:53:09 -0400
committerMatt Hicks <mhicks@redhat.com>2008-06-09 17:21:57 -0400
commit40cbdbedf9436bc8a71bba05d7c1daad12c3bd16 (patch)
tree2b3d98ed1426ceaae118bed4f18a7e4c6f2688e2
parentdcb651c928bfd5ef7e2d8ccd96f92937bac1ae32 (diff)
downloadtools-40cbdbedf9436bc8a71bba05d7c1daad12c3bd16.tar.gz
tools-40cbdbedf9436bc8a71bba05d7c1daad12c3bd16.tar.xz
tools-40cbdbedf9436bc8a71bba05d7c1daad12c3bd16.zip
Current soademo state
-rw-r--r--soademo/lib/.soademo.rb.swpbin0 -> 16384 bytes
-rwxr-xr-xsoademo/lib/bootstrap.rb170
2 files changed, 170 insertions, 0 deletions
diff --git a/soademo/lib/.soademo.rb.swp b/soademo/lib/.soademo.rb.swp
new file mode 100644
index 0000000..90b929d
--- /dev/null
+++ b/soademo/lib/.soademo.rb.swp
Binary files differ
diff --git a/soademo/lib/bootstrap.rb b/soademo/lib/bootstrap.rb
new file mode 100755
index 0000000..7319a6c
--- /dev/null
+++ b/soademo/lib/bootstrap.rb
@@ -0,0 +1,170 @@
+#!/usr/bin/ruby
+
+require 'erb'
+require 'yaml'
+require 'rubygems'
+require 'everest-bootstrap/ddns'
+require 'highline'
+require "highline/import"
+require 'open3'
+require 'net/https'
+
+#http://www.mail-archive.com/capistrano@googlegroups.com/msg01822.html
+HighLine.track_eof = false
+
+####################################################
+# Common boostrapping functions
+####################################################
+module RedHat::Bootstrap
+ # Create machines based on a template
+ def create_machine(qname, template, ddns_user, ddns_password, repo, vol_group)
+ # Generate a DDNS hash for the machine
+ ddns = RedHatDDNS::DDNS.new(ddns_user, ddns_password, ddns(qname)).to_s
+
+ # Execute a command with a handle to stdin to write the yaml file
+ Open3.popen3("everest-bootstrap advanced --repo=#{repo} --fqdn=#{qname} --virt-path=#{vol_group}") do |stdin, stdout, stderr|
+ # Write the generated yaml to the process
+ machine_yaml = ERB.new(File.readlines("#{template}.erb").to_s).result(binding)
+ stdin.puts(machine_yaml)
+ end
+ end
+
+ # Start a set of VMs, but wait if they're currently running
+ def start_vms(prefix, domain, *machines)
+ # Waiting for the provisioning to finish
+ while system("pgrep -f xen.*#{prefix}") do
+ puts "Waiting for VMs to stop..."
+ sleep 15
+ end
+
+ # Start all the instances
+ puts "Starting xen instances..."
+ for machine in machines.keys do
+ for qname in fqdn(machine, prefix, domain) do
+ `xm create #{ddns(qname)}`
+ sleep 1
+ end
+ end
+ end
+
+ # Get the fully qualified domain name for a machine
+ def fqdn(machine_name, prefix, domain, index => 0)
+ if index > 0
+ return "#{prefix}-#{machine_name}-#{index}.#{domain}"
+ else
+ return "#{prefix}-#{machine_name}.#{domain}"
+ end
+ end
+
+ def ddns(fqdn)
+ fqdn.split(".")[0]
+ end
+end
+
+
+##############################################
+# Function to print out a pretty time
+##############################################
+def time_period_to_s time_period
+ out_str = ''
+ interval_array = [ [:weeks, 604800], [:days, 86400], [:hours, 3600], [:mins, 60] ]
+ interval_array.each do |sub|
+ if time_period>= sub[1] then
+ time_val, time_period = time_period.divmod( sub[1] )
+ time_val == 1 ? name = sub[0].to_s.singularize : name = sub[0].to_s
+ ( sub[0] != :mins ? out_str += ", " : out_str += " and " ) if out_str != ''
+ out_str += time_val.to_s + " #{name}"
+ end
+ end
+ return out_str
+end
+
+##############################################
+# Cleanup any reference to the given machine
+##############################################
+def cleanup(machine)
+ puts "Destroying the xen instance..."
+ `xm destroy #{machine}`
+ sleep 1
+
+ puts "Destroying any lingering processes..."
+ `pkill -f #{machine}`
+
+ puts "Destroying the lvm partition..."
+ Dir.glob("/dev/HostVolGroup*/#{machine}-*") do |partition|
+ `lvremove -f #{partition}`
+ end
+
+ puts "Removing xen config file..."
+ `rm -f /etc/xen/#{machine}`
+end
+
+
+##############################################
+# Main application
+##############################################
+
+raise "Must run as root" unless ENV['USER'] == "root"
+
+include RedHat::Bootstrap
+
+# Collect the kerberos username and password to request the DDNS addresses
+user = ask("Enter your kerberos username: ")
+password = ask("Enter your kerberos password to setup DDNS: ") { |q| q.echo = "*" }
+
+# Starting timer
+start_time = Time.now
+
+# Read in the YAML file to figure out which machines to create
+@params = YAML.load_file("bootstrap.yaml")
+
+# Read in the required environment variables
+num_vol_groups = @params["num_vol_groups"]
+repo = @params["repo"]
+multicast = @params["multicast"]
+
+for machine in @params["machines"].keys do
+ machine_count = @params["machines"][machine]
+ for qname in fqdn(machine, @params["machine_prefix"], @params["domain"]) do
+ # Cleanup the machine name
+ puts "Cleaning up #{qname}"
+ cleanup(ddns(qname))
+ sleep 5
+
+ puts "Bootstrapping #{qname}"
+
+ create_machine(qname, template, username, password, repo, "HostVolGroup0#{rand num_vol_groups}")
+ end
+end
+
+start_vms(@params["machine_prefix"], @params["domain"], @params["machines"].keys)
+
+# Wait for SSO to be accessible on each JBoss node
+# Don't the proxy since it will think the JBoss nodes
+# and in a failure state and remove them
+#poll_interval = 30
+#for node in fqdn('jboss') do
+# http = Net::HTTP.new(node, 8081)
+# begin
+# http.start do |http|
+# until http.get('/wapps/sso/login.html').code == "200" do
+# puts "#{node} not available yet..."
+# sleep poll_interval
+# end
+# end
+# rescue
+# puts "#{node} not available yet..."
+# sleep poll_interval
+# retry
+# rescue Timeout::Error
+# puts "#{node} not available yet..."
+# sleep poll_interval
+# retry
+# end
+#end
+
+# Calculate the time
+total_time = Time.now - start_time
+
+puts "Finished in #{time_period_to_s total_time}."
+puts "The machines should be ready in about 25 minutes."