Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement