1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

added datacenters models

This commit is contained in:
nightshade427 2011-03-01 12:00:48 -05:00 committed by Nicholas Ricketts
parent 6fb039d3e8
commit 57188adf91
3 changed files with 40 additions and 0 deletions

View file

@ -15,6 +15,8 @@ module Fog
collection :servers
model :kernel
collection :kernels
model :data_center
collection :data_centers
request_path 'fog/compute/requests/linode'
request :avail_datacenters

View file

@ -0,0 +1,12 @@
require 'fog/core/model'
module Fog
module Linode
class Compute
class DataCenter < Fog::Model
identity :id
attribute :location
end
end
end
end

View file

@ -0,0 +1,26 @@
require 'fog/core/collection'
require 'fog/compute/models/linode/data_center'
module Fog
module Linode
class Compute
class DataCenters < Fog::Collection
model Fog::Linode::Compute::DataCenter
def all
load datacenters
end
private
def datacenters(id=nil)
connection.avail_datacenters.body['DATA'].tap { |data| map_datacenters data }
end
def map_datacenters(datacenters)
datacenters.map! { |datacenter| datacenter.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v } }
datacenters.each { |datacenter| datacenter.merge! :id => datacenter[:datacenterid], :name => datacenter[:location] }
end
end
end
end
end