Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Report monthly Linode cost
#!/usr/bin/env ruby
require 'byebug'
require 'linode'
require 'awesome_print'
# setup API access - key is in file
open('/etc/linode.conf').read =~ /api_key: (.+)/
lin = key).linode
# get generic plans and prices
plans = {}
lin.avail.linodeplans.each { |plan|
plans[plan.planid] = plan
ap plans
# get our plans and prices
nodes = {}
lin.list.each { |node|
group = node[:lpm_displaygroup]
nodes[group] ||= []
nodes[group] << node
# report costs
puts "Monthly Linode costs by server group:"
total_cost = 0
nodes.each_pair { |group, nodes|
ap nodes
cost = { |n| n.planid }.map { |id| id; plans[id].price }.inject(:+).round
total_cost += cost
puts "#{group} $#{cost}"
puts "\nTOTAL: $#{total_cost}/month"
puts "\nThis report was automatically generated"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.