Skip to content

Instantly share code, notes, and snippets.

@dpb587
Created March 3, 2015 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpb587/aa09f87fa2ce16ee37c0 to your computer and use it in GitHub Desktop.
Save dpb587/aa09f87fa2ce16ee37c0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'yaml'
lastvm = nil
vms = {}
vmsraw = `cd #{ARGV[0]} && bosh vms #{ARGV[1]}`
vmsraw.scan(/^\|\s([^\|]+)\s+\|\s([^\|]+)\s+\|\s([^\|]+)\s+\|\s([^\|]+)\s+\|$/) do | match |
thisvm = match[0].strip
if '' == thisvm then
vms[lastvm][:ip] = match[3].strip
else
vms[thisvm] = {
:pool => match[2].strip,
:ip => match[3].strip,
}
lastvm = thisvm
end
end
manifest = `cd #{ARGV[0]} && bosh download manifest #{ARGV[1]}`
puts '<project>'
manifest['jobs'].each do | job |
jobtemplates = job['templates'].map do | template |
template['name']
end
for index in 0..(job['instances'] - 1)
name = "#{job['name']}/#{index}"
puts " <node name=\"#{name}\" hostname=\"#{vms[name][:ip]}\" username=\"vcap\" tags=\"#{jobtemplates.join(', ')}\">"
#puts " <attribute name=\"sudo-command-enabled\" value=\"true\"/>"
#puts " <attribute name=\"sudo-password-option\" value=\"option.sshKeyPassphrase\"/>"
puts " <attribute name=\"bosh:resource-pool\" value=\"#{vms[name][:pool]}\"/>"
puts " </node>"
end
end
puts "</project>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment