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

[ibm] Add Location model and requests

This commit is contained in:
Decklin Foster 2012-01-17 11:19:21 -05:00
parent 65e572805e
commit a9fa42d461
5 changed files with 93 additions and 0 deletions

View file

@ -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])

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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