Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'fog'
- require 'awesome_print'
- class Array
- def to_csv(csv_filename="hash.csv")
- require 'csv'
- CSV.open(csv_filename, "wb") do |csv|
- csv << first.keys # adds the attributes name on the first line
- self.each do |hash|
- csv << hash.values
- end
- end
- end
- end
- Servers = []
- 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}
- [:ord].each do |region|
- @service = Fog::Compute.new({
- :provider => 'Rackspace', # Rackspace Fog provider
- :rackspace_username => ENV['RACKSPACE_USERNAME'], # Your Rackspace Username
- :rackspace_api_key => ENV['RACKSPACE_API_KEY'], # Your Rackspace API key
- :version => :v2, # Use Next Gen Cloud Servers
- :rackspace_region => :ord, # Defaults to :dfw
- :connection_options => {} # Optional
- })
- @service.servers.each do |server|
- @stats = {
- 'region' => region.to_s.upcase,
- 'host_name' => server.name,
- 'ip_public' => server.addresses['public'].find{|i| i['version'] == 4}['addr'],
- 'ip_private' => server.addresses['private'].find{|i| i['version'] == 4}['addr'],
- 'flavor' => server.flavor_id,
- 'cost' => Costs[server.flavor_id],
- 'cpus' => server.flavor.vcpus,
- 'ram' => server.flavor.ram,
- 'image' => (server.image ? server.image.name : 'nil')
- }
- Servers << @stats
- end
- end
- Servers.to_csv 'reports/rackspace_servers.csv'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement