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:
parent
65e572805e
commit
a9fa42d461
5 changed files with 93 additions and 0 deletions
|
@ -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])
|
||||
|
|
15
lib/fog/ibm/models/compute/location.rb
Normal file
15
lib/fog/ibm/models/compute/location.rb
Normal 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
|
27
lib/fog/ibm/models/compute/locations.rb
Normal file
27
lib/fog/ibm/models/compute/locations.rb
Normal 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
|
23
lib/fog/ibm/requests/compute/get_location.rb
Normal file
23
lib/fog/ibm/requests/compute/get_location.rb
Normal 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
|
23
lib/fog/ibm/requests/compute/get_locations.rb
Normal file
23
lib/fog/ibm/requests/compute/get_locations.rb
Normal 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
|
Loading…
Add table
Reference in a new issue