diff options
| author | Matt Hicks <mhicks@redhat.com> | 2008-06-05 21:50:01 -0400 |
|---|---|---|
| committer | Matt Hicks <mhicks@redhat.com> | 2008-06-09 17:21:57 -0400 |
| commit | bf373689b04efd6bb8d7e737f9a79c8680d9f819 (patch) | |
| tree | be8248a6f580e83d438f9ab9ff9fb4b709a26af6 | |
| parent | a126ada41924659fee52ed85f0f9706668d4710e (diff) | |
Sort of working
| -rw-r--r-- | soademo/lib/.bootstrap.swp | bin | 24576 -> 0 bytes | |||
| -rwxr-xr-x | soademo/lib/bootstrap | 177 | ||||
| -rw-r--r-- | soademo/lib/soademo.rb | 174 | ||||
| -rw-r--r-- | soademo/lib/static/style.css | 2 |
4 files changed, 129 insertions, 224 deletions
diff --git a/soademo/lib/.bootstrap.swp b/soademo/lib/.bootstrap.swp Binary files differdeleted file mode 100644 index f4c95c8..0000000 --- a/soademo/lib/.bootstrap.swp +++ /dev/null diff --git a/soademo/lib/bootstrap b/soademo/lib/bootstrap deleted file mode 100755 index eccc8c4..0000000 --- a/soademo/lib/bootstrap +++ /dev/null @@ -1,177 +0,0 @@ -#!/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, *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 @params["machines"].keys do - for qname in fqdn(machine) do - `xm create #{ddns(qname)}` - sleep 1 - end - end - end - - # Get the fully qualified domain name for a machine - def fqdn(machine_name) - machine_count = @params["machines"][machine_name] - - if machine_count > 1 - # We are creating a cluster - fqdn = [] - for index in 1..machine_count - fqdn << "#{@params["machine_prefix"]}-#{machine_name}-#{index}.#{@params["domain"]}" - end - return fqdn - else - # Return the machine name - return "#{@params["machine_prefix"]}-#{machine_name}.#{@params["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 - for qname in fqdn(machine) 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["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." diff --git a/soademo/lib/soademo.rb b/soademo/lib/soademo.rb index 07b2764..295330f 100644 --- a/soademo/lib/soademo.rb +++ b/soademo/lib/soademo.rb @@ -1,10 +1,13 @@ require 'yaml' require 'rubygems' require 'picnic' +#require 'lib/bootstrap' Camping.goes :Soademo #Soademo.picnic! +#include RedHat::Bootstrap + module Soademo::Helpers ############################################## # Cleanup any reference to the given machine @@ -25,50 +28,52 @@ module Soademo::Helpers puts "Removing xen config file..." `rm -f /etc/xen/#{machine}` end - - # Collect the list of available volume groups - def vgs - output = `vgs` - while not $?.success? do - sleep 0.5 - output = `vgs` - end - volume_groups = {} - output.split("\n").each_with_index do |row, index| - if index > 0 then - row_values = row.split(" ") - name = row_values[0] - lvcount = row_values[2] - total_mem = row_values[5] - avail_mem = row_values[6] - volume_groups[name] = {:lvcount => lvcount, :total_memory => total_mem, :available_memory => avail_mem} - end + # 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 - return volume_groups end - def lvs - output = `lvs` - while not $?.success? do - sleep 0.5 - output = `lvs` + # 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 - - state = {} - output.split("\n").each_with_index do |row, index| - if index > 0 then - row_values = row.split(" ") - name = row_values[0] - vol_group = row_values[1] - size = row_values[3] - state[name] = {:vol_group => vol_group, :size => size} + + # 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 - - return state end + # Get the fully qualified domain name for a machine + def fqdn(machine_name, prefix, domain) + if machine_name == "jboss" + index = next_machine(machine_name) + return "#{prefix}-#{index}.#{domain}" + else + return "#{prefix}-#{machine_name}.#{domain}" + end + end + + def ddns(fqdn) + fqdn.split(".")[0] + end + def lvm_path name lvs_output = lvs File.join("/dev", lvs_output[name][:vol_group], name) @@ -88,6 +93,19 @@ module Soademo::Helpers return available_output end + def all_machines + avail_machines = xm_available.keys.collect{|key| xm_name(key)} + return xm_list.keys + avail_machines + end + + def next_machine machine_name + # Warning - This will only work up to 9 machines unless we start moving to 01, 001, etc + machines = all_machines.delete_if{|machine| not machine =~ /#{machine_name}/} + + # Sort the machine (1..9) and pull the digit off the last machine + return machine_name + "-" + (machines.sort.last.split("-")[-1].to_i + 1).to_s + end + def xm_name(lvs_name) lvs_name.split("-disk0")[0] end @@ -115,6 +133,51 @@ module Soademo::Helpers return state end + + # Collect the list of available volume groups + def vgs + output = `vgs` + while not $?.success? do + sleep 0.5 + output = `vgs` + end + + volume_groups = {} + output.split("\n").each_with_index do |row, index| + if index > 0 then + row_values = row.split(" ") + name = row_values[0] + lvcount = row_values[2] + total_mem = row_values[5] + avail_mem = row_values[6] + volume_groups[name] = {:lvcount => lvcount, :total_memory => total_mem, :available_memory => avail_mem} + end + end + return volume_groups + end + + def lvs + output = `lvs` + while not $?.success? do + sleep 0.5 + output = `lvs` + end + + state = {} + output.split("\n").each_with_index do |row, index| + if index > 0 then + row_values = row.split(" ") + name = row_values[0] + vol_group = row_values[1] + size = row_values[3] + state[name] = {:vol_group => vol_group, :size => size} + end + end + + return state + end + + end module Soademo::Controllers @@ -182,20 +245,31 @@ module Soademo::Controllers end end - class Create_From_Templates + class CreateFromTemplates def post - input.keys.each do |key| - if key =~ /template.*/ then - puts "This is a template: #{key}" - else - puts "This is NOT a template: #{key}" - end - end + repo = input['config_repo'] + prefix = input['config_prefix'] + domain = 'usersys.redhat.com' + user = input['config_user'] + password = input['config_password'] + + # Create each VM from the given templates + templates = input.keys.delete_if { |key| not key =~ /template_/ }.collect { |key| key.split("template_")[1] } + + templates.each { |template| + index = next_machine(template) + qname = fqdn(template, prefix, domain) + puts qname + #create_machine(qname, template, '', '', repo, input['config_vg']) + } + + # Kick off a process to wait for the VMs to kickstart, then start up the VMs to bootstrap + #pid = Process.fork { start_vms(prefix, domain, templates) } + #Process.detach(pid) + redirect Template end - def create - end end class AjaxRunning < R '/ajax_running' @@ -268,7 +342,7 @@ module Soademo::Views "then select the machines you want to create from the templates below" end - form.template_form! :action => R(Create_From_Templates), :method => "post" do + form.template_form! :action => R(CreateFromTemplates), :method => "post" do _template_config _templates div do p do input :id => 'create', :type => 'submit', :value => "Create" end end @@ -283,6 +357,14 @@ module Soademo::Views h2 'Base Template Configuration' table do tr do + td "DDNS Username:" + td do input :type => 'text', :name => "config_username", :value => "", :size => "40" end + end + tr do + td "DDNS Password:" + td do input :type => 'password', :name => "config_password", :value => "", :size => "40" end + end + tr do td "Machine Prefix:" td do input :type => 'text', :name => "config_prefix", :value => "#{config['machine_prefix']}", :size => "40" end end diff --git a/soademo/lib/static/style.css b/soademo/lib/static/style.css index 8aec5c1..aa4e563 100644 --- a/soademo/lib/static/style.css +++ b/soademo/lib/static/style.css @@ -46,7 +46,7 @@ ul#nav li a { } ul#nav li a.selected_sidebar { - color: red; + color: #AB0000; } #wrap { |
