diff --git a/lib/fog/compute/linode.rb b/lib/fog/compute/linode.rb index 222448a44..9ebf7ba76 100644 --- a/lib/fog/compute/linode.rb +++ b/lib/fog/compute/linode.rb @@ -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 diff --git a/lib/fog/compute/models/linode/data_center.rb b/lib/fog/compute/models/linode/data_center.rb new file mode 100644 index 000000000..9fcfab75f --- /dev/null +++ b/lib/fog/compute/models/linode/data_center.rb @@ -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 diff --git a/lib/fog/compute/models/linode/data_centers.rb b/lib/fog/compute/models/linode/data_centers.rb new file mode 100644 index 000000000..9a46d2c9c --- /dev/null +++ b/lib/fog/compute/models/linode/data_centers.rb @@ -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