Skip to content

Instantly share code, notes, and snippets.

@rcreasey
Created June 12, 2010 00:28
Show Gist options
  • Select an option

  • Save rcreasey/435239 to your computer and use it in GitHub Desktop.

Select an option

Save rcreasey/435239 to your computer and use it in GitHub Desktop.
#!/bin/env ruby
vm_label = ARGV[0]
if vm_label.nil?
puts "You need to specify a new vm label."
puts "new_vm.rb <label> <path to json>"
exit
end
node_json = ARGV[1]
if node_json.nil?
puts "You need to specify a node json file."
puts "new_vm.rb <label> <path to json>"
exit
end
sr_uuid = "5161bc49-a423-346a-efc3-059288f5b07c"
network_uuid = "3009d235-1b04-91c0-b27a-8ffda6865a29"
template_name = "baseline-centos-5-64"
waitress_url = "http://10.93.10.39/"
puts "Scanning pool for optimal placement..."
vm_uuid = %x{xe vm-install template="#{template_name}" new-name-label=#{vm_label} sr_uuid=#{sr_uuid}}.chomp
puts "Attaching to the build vlan..."
vif_uuid = %x{xe vif-create mac=random device=0 network-uuid=#{network_uuid} vm-uuid=#{vm_uuid}}.chomp
mac_address = %x{xe vif-param-get param-name=MAC uuid=#{vif_uuid}}.chomp.gsub(/:/, "-").upcase
%x{xe vm-param-set name-description="" name-label="#{vm_label}" uuid=#{vm_uuid}}
node_data = File.open( node_json, 'r' ) {|f| f.read}
puts "Placing order with waitress..."
%x{curl -s -d 'mac_address=#{mac_address}&node=#{node_data}' #{waitress_url}}
puts "Starting VM."
%x{xe vm-start uuid=#{vm_uuid}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment