summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Hicks <mhicks@redhat.com>2008-06-06 01:28:28 -0400
committerMatt Hicks <mhicks@redhat.com>2008-06-09 17:21:57 -0400
commitdcb651c928bfd5ef7e2d8ccd96f92937bac1ae32 (patch)
treeb925c57224f6159e31b3039fd06ffd66208a3e49
parentbf373689b04efd6bb8d7e737f9a79c8680d9f819 (diff)
downloadtools-dcb651c928bfd5ef7e2d8ccd96f92937bac1ae32.tar.gz
tools-dcb651c928bfd5ef7e2d8ccd96f92937bac1ae32.tar.xz
tools-dcb651c928bfd5ef7e2d8ccd96f92937bac1ae32.zip
working
-rw-r--r--soademo/lib/soademo.rb167
-rw-r--r--soademo/templates/hudson.erb2
-rw-r--r--soademo/templates/jboss.erb4
-rw-r--r--soademo/templates/proxy.erb10
4 files changed, 88 insertions, 95 deletions
diff --git a/soademo/lib/soademo.rb b/soademo/lib/soademo.rb
index 295330f..986a175 100644
--- a/soademo/lib/soademo.rb
+++ b/soademo/lib/soademo.rb
@@ -1,7 +1,9 @@
require 'yaml'
+require 'erb'
require 'rubygems'
require 'picnic'
-#require 'lib/bootstrap'
+require 'everest-bootstrap/ddns'
+require 'open3'
Camping.goes :Soademo
#Soademo.picnic!
@@ -30,20 +32,26 @@ module Soademo::Helpers
end
# Create machines based on a template
- def create_machine(qname, template, ddns_user, ddns_password, repo, vol_group)
+ def create_machine(prefix, domain, multicast, jboss_fqdns, template, ddns_user, ddns_password, repo, vol_group, options = {})
+ qname = options[:fqdn]
+ qname ||= fqdn(template, prefix, domain)
+ puts "Creating machine #{qname}"
+
# 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)
+ machine_yaml = ERB.new(File.readlines("templates/#{template}.erb").to_s).result(binding)
stdin.puts(machine_yaml)
end
+
+ return qname
end
# Start a set of VMs, but wait if they're currently running
- def start_vms(prefix, domain, *machines)
+ def start_vms(prefix, *fqdns)
# Waiting for the provisioning to finish
while system("pgrep -f xen.*#{prefix}") do
puts "Waiting for VMs to stop..."
@@ -52,11 +60,9 @@ module Soademo::Helpers
# 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
+ for qname in fqdns do
+ `xm create #{ddns(qname)}`
+ sleep 1
end
end
@@ -79,6 +85,19 @@ module Soademo::Helpers
File.join("/dev", lvs_output[name][:vol_group], name)
end
+ def xm_list
+ exec_command('xm list', [:name, :id, :mem, :cpus, :status, :time])
+ end
+
+ # Collect the list of available volume groups
+ def vgs
+ exec_command('vgs', [:name, :pvid, :lvid, :sn, :attr, :size, :free])
+ end
+
+ def lvs
+ exec_command('lvs', [:name, :vol_group, :attr, :size])
+ end
+
def xm_available
lvs_output = lvs
xm_output = xm_list
@@ -94,8 +113,13 @@ module Soademo::Helpers
end
def all_machines
- avail_machines = xm_available.keys.collect{|key| xm_name(key)}
- return xm_list.keys + avail_machines
+ avail_machines = xm_available.keys.collect{|key| xm_name(key)}
+ return xm_list.keys + avail_machines
+ end
+
+ # TODO - invoke to disable the template options
+ def exists(prefix, machine_name)
+ all_machines.each { |machine| return true if machine =~ /#{prefix}-#{machine_name}/ }
end
def next_machine machine_name
@@ -110,74 +134,28 @@ module Soademo::Helpers
lvs_name.split("-disk0")[0]
end
- # Collect the states for all xen guests
- def xm_list
- output = `xm list`
+ def exec_command (command, columns, interval = 0.5)
+ output = `#{command}`
+
while not $?.success? do
- sleep 0.5
- output = `xm list`
+ sleep interval
+ output = `#{command}`
end
- state = {}
+ result = {}
output.split("\n").each_with_index do |row, index|
if index > 0 then
row_values = row.split(" ")
- name = row_values[0]
- mem = row_values[2]
- cpus = row_values[3]
- status = row_values[4]
- time = row_values[5]
- state[name] = {:mem => mem, :cpus => cpus, :status => status, :time => time}
- end
- end
-
- 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}
+ values = {}
+ columns.each_with_index do |f, findex|
+ values[f] = row_values[findex]
+ end
+ result[row_values[0]] = values
end
end
-
- return state
+
+ return result
end
-
-
end
module Soademo::Controllers
@@ -250,22 +228,32 @@ module Soademo::Controllers
repo = input['config_repo']
prefix = input['config_prefix']
domain = 'usersys.redhat.com'
- user = input['config_user']
+ user = input['config_username']
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'])
- }
+ jbossNodes = input['config_jboss_nodes'].to_i
+ multicast = input['config_multicast']
+
+ # Build up the jboss array of machines for the proxy
+ jboss_fqdns = (1..jbossNodes).collect { |i| "#{prefix}-jboss-#{i}.#{domain}" }
+ puts "jboss_fqdns #{jboss_fqdns}"
+
+ # Create the set of base machines for this prefix
+ splunk_fqdn = create_machine(prefix, domain, multicast, jboss_fqdns, "splunk", user, password, repo, input['config_vg'])
+ sleep 2
+ hudson_fqdn = create_machine(prefix, domain, multicast, jboss_fqdns, "hudson", user, password, repo, input['config_vg'])
+ sleep 2
+ proxy_fqdn = create_machine(prefix, domain, multicast, jboss_fqdns, "proxy", user, password, repo, input['config_vg'])
+ sleep 2
+
+ # Create the desired number of JBoss nodes
+ for jboss_fqdn in jboss_fqdns
+ create_machine(prefix, domain, multicast, jboss_fqdns, "jboss", user, password, repo, input["config_vg"], :fqdn => jboss_fqdn)
+ sleep 2
+ end
# 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)
+ pid = Process.fork { start_vms(prefix, [splunk_fqdn, hudson_fqdn, proxy_fqdn] + jboss_fqdns) }
+ Process.detach(pid)
redirect Template
end
@@ -344,14 +332,14 @@ module Soademo::Views
form.template_form! :action => R(CreateFromTemplates), :method => "post" do
_template_config
- _templates
+ #_templates
div do p do input :id => 'create', :type => 'submit', :value => "Create" end end
end
end
def _template_config
config = base_config
- vgs_output = vgs
+ vgs_output = vgs
div.template_config! do
h2 'Base Template Configuration'
@@ -377,11 +365,15 @@ module Soademo::Views
td do input :type => 'text', :name => "config_multicast", :value => "#{config['multicast']}", :size => "40" end
end
tr do
+ td "# of JBoss Nodes:"
+ td do input :type => 'text', :name => "config_jboss_nodes", :value => "1", :size => "40" end
+ end
+ tr do
td "Volume Groups:"
td do
select :name => "config_vg" do
vgs_output.keys.sort.each do |key|
- option :value => key do "#{key} (#{vgs_output[key][:available_memory]} left)" end
+ option :value => key do "#{key} (#{vgs_output[key][:free]} left)" end
end
end
end
@@ -392,6 +384,7 @@ module Soademo::Views
def _templates
templates = guest_templates
+ machines = all_machines
div.template! do
h2 'Available templates'
table do
@@ -429,7 +422,7 @@ module Soademo::Views
# Display the list of running xen guests
def _running
div.running! do
- xm_list_output = xm_list
+ xm_list_output = xm_list
form.running_form! :action => R(Shutdown), :method => "post" do
table :cellpadding => 3 do
diff --git a/soademo/templates/hudson.erb b/soademo/templates/hudson.erb
index 4ad9071..5c78df3 100644
--- a/soademo/templates/hudson.erb
+++ b/soademo/templates/hudson.erb
@@ -1,6 +1,6 @@
---
parameters:
- logserver: <%= fqdn("splunk") %>
+ logserver: <%= fqdn("splunk", prefix, domain) %>
user: it
rh_ddns_hash: <%= ddns %>
cobbler: <%= repo %>
diff --git a/soademo/templates/jboss.erb b/soademo/templates/jboss.erb
index 9c30b38..2aaee68 100644
--- a/soademo/templates/jboss.erb
+++ b/soademo/templates/jboss.erb
@@ -3,7 +3,7 @@ parameters:
jboss_mode: none
datastore_server: not-applicable
user: it
- logserver: <%= fqdn("splunk") %>
+ logserver: <%= fqdn("splunk", prefix, domain) %>
multicast_address: <%= multicast %>
env: production
cobbler: <%= repo %>
@@ -39,7 +39,7 @@ parameters:
- redhat-sd-www-app-support
- redhat-sd-www-app-ugc
- redhat-sd-www-endpoint-ugc
- proxy: <%= fqdn("proxy") %>
+ proxy: <%= fqdn("proxy", prefix, domain) %>
everest_machine_type: jboss
classes:
- puppet::client
diff --git a/soademo/templates/proxy.erb b/soademo/templates/proxy.erb
index 0ed326d..b6a0ca5 100644
--- a/soademo/templates/proxy.erb
+++ b/soademo/templates/proxy.erb
@@ -1,6 +1,6 @@
---
parameters:
- logserver: <%= fqdn("splunk") %>
+ logserver: <%= fqdn("splunk", prefix, domain) %>
user: it
rh_ddns_hash: <%= ddns %>
cobbler: <%= repo %>
@@ -8,10 +8,10 @@ parameters:
gitserver: <%= repo %>
cobbler_profile: NormalEverestGuest-RHEL5U2-x86_64
puppetserver: <%= repo %>
- jboss_apps_hosts: <%= fqdn("jboss").is_a?(Array) ? fqdn("jboss").join(",") : fqdn("jboss") %>
- jboss_wapps_hosts: <%= fqdn("jboss").is_a?(Array) ? fqdn("jboss").join(",") : fqdn("jboss") %>
- jboss_wsvc_hosts: <%= fqdn("jboss").is_a?(Array) ? fqdn("jboss").join(",") : fqdn("jboss") %>
- jboss_svc_hosts: <%= fqdn("jboss").is_a?(Array) ? fqdn("jboss").join(",") : fqdn("jboss") %>
+ jboss_apps_hosts: <%= jboss_fqdns.is_a?(Array) ? jboss_fqdns.join(",") : jboss_fqdns %>
+ jboss_wapps_hosts: <%= jboss_fqdns.is_a?(Array) ? jboss_fqdns.join(",") : jboss_fqdns %>
+ jboss_wsvc_hosts: <%= jboss_fqdns.is_a?(Array) ? jboss_fqdns.join(",") : jboss_fqdns %>
+ jboss_svc_hosts: <%= jboss_fqdns.is_a?(Array) ? jboss_fqdns.join(",") : jboss_fqdns %>
everest_machine_type: jboss-proxy
classes:
- puppet::client