mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
32 lines
762 B
Ruby
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
|