Created
August 24, 2016 13:47
-
-
Save np422/953bf3b3fa88b2223102646002d10793 to your computer and use it in GitHub Desktop.
Small script to parse xml-output from vcloud api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "json" | |
require "crack" | |
myXML = Crack::XML.parse(File.read( ARGV[0] )) | |
myJSON = myXML.to_json | |
vAPP = JSON.parse(myJSON) | |
def print_ovf_info(m) | |
m["ovf:Item"].each do |item| | |
if item["rasd:Description"] == "Hard disk" | |
puts item["rasd:ElementName"] | |
puts item["rasd:HostResource"]["vcloud:capacity"] | |
end | |
if item["rasd:Description"] == "Number of Virtual CPUs" | |
puts item["rasd:ElementName"] | |
end | |
if item["rasd:Description"] == "Memory Size" | |
puts item["rasd:ElementName"] | |
end | |
end | |
end | |
vAPP["VApp"]["Children"]["Vm"].each do |machine| | |
if machine.is_a? Array | |
machine.each do |m| | |
if m.is_a? Hash | |
if !m.keys.grep("ovf:System").empty? | |
puts "System name = " + m["ovf:System"]["vssd:VirtualSystemIdentifier"] | |
print_ovf_info(m) | |
puts "," | |
end | |
end | |
end | |
else | |
puts "System name = " + machine["GuestCustomizationSection"]["ComputerName"] if | |
print_ovf_info(machine["ovf:VirtualHardwareSection"]) | |
puts "," | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment