Skip to content

Instantly share code, notes, and snippets.

@sustr4
Created December 2, 2015 09:54
Show Gist options
  • Save sustr4/29003d10fef03ef78cb1 to your computer and use it in GitHub Desktop.
Save sustr4/29003d10fef03ef78cb1 to your computer and use it in GitHub Desktop.
Convert hierarchical YAML from Clouditor to sequential CSV for further processing in spreadsheets. Each run segment on a separate line.
require 'yaml'
data = YAML.load_file("vm_records_export.yml")
puts "id,user,group,name,memory,vcpu,cpu,hostname,start_time,end_time,host_info.vcpu,host_info.memory,host_info.model"
data.each { |rec|
rec["runtime"].each { |runtime|
puts "#{rec["id"]},#{rec["user"]},#{rec["group"]},#{rec["name"]},#{rec["memory"]},#{rec["vcpu"]},#{rec["cpu"]},#{runtime["hostname"]},#{runtime["start_time"]},#{runtime["end_time"]},#{runtime["host_info"]["vcpu"]},#{runtime["host_info"]["memory"]},#{runtime["host_info"]["model"]}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment