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:
parent
6fb039d3e8
commit
57188adf91
3 changed files with 40 additions and 0 deletions
|
@ -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
|
||||
|
|
12
lib/fog/compute/models/linode/data_center.rb
Normal file
12
lib/fog/compute/models/linode/data_center.rb
Normal 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
|
26
lib/fog/compute/models/linode/data_centers.rb
Normal file
26
lib/fog/compute/models/linode/data_centers.rb
Normal 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
|
Loading…
Add table
Reference in a new issue