diff --git a/lib/fog/ibm/compute.rb b/lib/fog/ibm/compute.rb index db19c4f33..76dcc0288 100644 --- a/lib/fog/ibm/compute.rb +++ b/lib/fog/ibm/compute.rb @@ -18,6 +18,8 @@ module Fog collection :addresses model :key collection :keys + model :location + collection :locations request_path 'fog/ibm/requests/compute' @@ -53,6 +55,9 @@ module Fog request :get_keys request :get_key + request :get_location + request :get_locations + class Real def initialize(options={}) @connection = Fog::IBM::Connection.new(options[:ibm_user_id], options[:ibm_password]) diff --git a/lib/fog/ibm/models/compute/location.rb b/lib/fog/ibm/models/compute/location.rb new file mode 100644 index 000000000..b53f46ec5 --- /dev/null +++ b/lib/fog/ibm/models/compute/location.rb @@ -0,0 +1,15 @@ +require 'fog/core/model' + +module Fog + module Compute + class IBM + class Location < Fog::Model + identity :id + attribute :name + attribute :location + attribute :capabilities + attribute :description + end + end + end +end diff --git a/lib/fog/ibm/models/compute/locations.rb b/lib/fog/ibm/models/compute/locations.rb new file mode 100644 index 000000000..03bd4f439 --- /dev/null +++ b/lib/fog/ibm/models/compute/locations.rb @@ -0,0 +1,27 @@ +require 'fog/core/collection' +require 'fog/ibm/models/compute/location' + +module Fog + module Compute + class IBM + + class Locations < Fog::Collection + + model Fog::Compute::IBM::Location + + def all + load(connection.get_locations.body['locations']) + end + + def get(location_id) + begin + new(connection.get_location(location_id).body) + rescue Fog::Compute::IBM::NotFound + nil + end + end + + end + end + end +end diff --git a/lib/fog/ibm/requests/compute/get_location.rb b/lib/fog/ibm/requests/compute/get_location.rb new file mode 100644 index 000000000..30ad38536 --- /dev/null +++ b/lib/fog/ibm/requests/compute/get_location.rb @@ -0,0 +1,23 @@ +module Fog + module Compute + class IBM + class Real + + # Get a location + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash> + # TODO: docs + def get_location(location_id) + request( + :method => 'GET', + :expects => 200, + :path => "/locations/#{location_id}" + ) + end + + end + end + end +end diff --git a/lib/fog/ibm/requests/compute/get_locations.rb b/lib/fog/ibm/requests/compute/get_locations.rb new file mode 100644 index 000000000..a969d172e --- /dev/null +++ b/lib/fog/ibm/requests/compute/get_locations.rb @@ -0,0 +1,23 @@ +module Fog + module Compute + class IBM + class Real + + # Get all locations + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash> + # TODO: docs + def get_locations + request( + :method => 'GET', + :expects => 200, + :path => "/locations" + ) + end + + end + end + end +end