Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'fog'
  4. require 'awesome_print'
  5. class Array
  6. def to_csv(csv_filename="hash.csv")
  7. require 'csv'
  8. CSV.open(csv_filename, "wb") do |csv|
  9. csv << first.keys # adds the attributes name on the first line
  10. self.each do |hash|
  11. csv << hash.values
  12. end
  13. end
  14. end
  15. end
  16.  
  17. Servers = []
  18. Costs = {"2"=> 21.90, "3"=> 43.80, "4"=>87.60, "5"=>175.20, "6"=>350.40 , "7"=> 700.80, "8"=> 1314.00, "compute1-15"=> 233.60, "compute1-30"=> 467.20, "compute1-4"=> 58.40, "compute1-60"=> 934.40, "compute1-8"=> 116.80, "general1-1"=> 23.36, "general1-2"=> 46.72, "general1-4"=> 93.44, "general1-8"=> 186.88, "io1-120"=> 2803.20, "io1-15"=> 350.40, "io1-30"=> 700.80, "io1-60"=>1401.60, "io1-90"=>2102.40, "memory1-120"=> 1051.20, "memory1-15"=> 131.40, "memory1-240"=> 2102.40, "memory1-30"=> 262.80, "memory1-60"=> 525.60, "performance1-1"=> 29.20, "performance1-2"=> 58.40, "performance1-4"=> 116.80, "performance1-8"=> 233.60, "performance2-120"=>3971.20, "performance2-15"=> 496.40, "performance2-30"=> 992.80, "performance2-60"=> 1985.60, "performance2-90"=> 2978.40}
  19. [:ord].each do |region|
  20. @service = Fog::Compute.new({
  21. :provider => 'Rackspace', # Rackspace Fog provider
  22. :rackspace_username => ENV['RACKSPACE_USERNAME'], # Your Rackspace Username
  23. :rackspace_api_key => ENV['RACKSPACE_API_KEY'], # Your Rackspace API key
  24. :version => :v2, # Use Next Gen Cloud Servers
  25. :rackspace_region => :ord, # Defaults to :dfw
  26. :connection_options => {} # Optional
  27. })
  28. @service.servers.each do |server|
  29. @stats = {
  30. 'region' => region.to_s.upcase,
  31. 'host_name' => server.name,
  32. 'ip_public' => server.addresses['public'].find{|i| i['version'] == 4}['addr'],
  33. 'ip_private' => server.addresses['private'].find{|i| i['version'] == 4}['addr'],
  34. 'flavor' => server.flavor_id,
  35. 'cost' => Costs[server.flavor_id],
  36. 'cpus' => server.flavor.vcpus,
  37. 'ram' => server.flavor.ram,
  38. 'image' => (server.image ? server.image.name : 'nil')
  39. }
  40. Servers << @stats
  41. end
  42. end
  43. Servers.to_csv 'reports/rackspace_servers.csv'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement