Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require "json"
  4. require "crack"
  5.  
  6. myXML = Crack::XML.parse(File.read( ARGV[0] ))
  7. myJSON = myXML.to_json
  8.  
  9. vAPP = JSON.parse(myJSON)
  10.  
  11. def print_ovf_info(m)
  12. m["ovf:Item"].each do |item|
  13. if item["rasd:Description"] == "Hard disk"
  14. puts item["rasd:ElementName"]
  15. puts item["rasd:HostResource"]["vcloud:capacity"]
  16. end
  17. if item["rasd:Description"] == "Number of Virtual CPUs"
  18. puts item["rasd:ElementName"]
  19. end
  20. if item["rasd:Description"] == "Memory Size"
  21. puts item["rasd:ElementName"]
  22. end
  23. end
  24. end
  25.  
  26.  
  27. vAPP["VApp"]["Children"]["Vm"].each do |machine|
  28. if machine.is_a? Array
  29. machine.each do |m|
  30. if m.is_a? Hash
  31. if !m.keys.grep("ovf:System").empty?
  32. puts "System name = " + m["ovf:System"]["vssd:VirtualSystemIdentifier"]
  33. print_ovf_info(m)
  34. puts ","
  35. end
  36. end
  37. end
  38. else
  39. puts "System name = " + machine["GuestCustomizationSection"]["ComputerName"] if
  40. print_ovf_info(machine["ovf:VirtualHardwareSection"])
  41. puts ","
  42. end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement