1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/compute/models/linode/servers.rb
2011-05-24 18:05:30 -04:00

32 lines
762 B
Ruby

require 'fog/core/collection'
require 'fog/compute/models/linode/server'
module Fog
module Linode
class Compute
class Servers < Fog::Collection
model Fog::Linode::Compute::Server
def all
load servers
end
def get(id)
new servers(id).first
rescue Fog::Linode::Compute::NotFound
nil
end
private
def servers(id=nil)
connection.linode_list(id).body['DATA'].map { |server| map_server server }
end
def map_server(server)
server = server.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
server.merge! :id => server[:linodeid], :name => server[:label]
end
end
end
end
end