mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[stormondemand|storage] Add Storage service and cluster API
This commit is contained in:
parent
39a4561928
commit
89c569fee2
6 changed files with 165 additions and 1 deletions
|
@ -11,6 +11,9 @@ module Fog
|
|||
when :internetarchive
|
||||
require 'fog/internet_archive/storage'
|
||||
Fog::Storage::InternetArchive.new(attributes)
|
||||
when :stormondemand
|
||||
require 'fog/storm_on_demand/storage'
|
||||
Fog::Storage::StormOnDemand.new(attributes)
|
||||
else
|
||||
if self.providers.include?(provider)
|
||||
require "fog/#{provider}/storage"
|
||||
|
|
|
@ -6,6 +6,7 @@ module Fog
|
|||
extend Fog::Provider
|
||||
|
||||
service(:compute, 'storm_on_demand/compute', 'Compute')
|
||||
service(:storage, 'storm_on_demand/storage', 'Storage')
|
||||
|
||||
end
|
||||
end
|
||||
|
|
20
lib/fog/storm_on_demand/models/storage/cluster.rb
Normal file
20
lib/fog/storm_on_demand/models/storage/cluster.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class StormOnDemand
|
||||
|
||||
class Cluster < Fog::Model
|
||||
identity :id
|
||||
attribute :description
|
||||
attribute :zone
|
||||
|
||||
def initialize(attributes={})
|
||||
super
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
20
lib/fog/storm_on_demand/models/storage/clusters.rb
Normal file
20
lib/fog/storm_on_demand/models/storage/clusters.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/storm_on_demand/models/storage/cluster'
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class StormOnDemand
|
||||
|
||||
class Clusters < Fog::Collection
|
||||
model Fog::Storage::StormOnDemand::Cluster
|
||||
|
||||
def all(options={})
|
||||
data = service.list_clusters(options).body['items']
|
||||
load(data)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
16
lib/fog/storm_on_demand/requests/storage/list_clusters.rb
Normal file
16
lib/fog/storm_on_demand/requests/storage/list_clusters.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
module Fog
|
||||
module Storage
|
||||
class StormOnDemand
|
||||
class Real
|
||||
|
||||
def list_clusters(options={})
|
||||
request(
|
||||
:path => '/Storage/Block/Cluster/list',
|
||||
:body => Fog::JSON.encode(:params => options)
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
104
lib/fog/storm_on_demand/storage.rb
Normal file
104
lib/fog/storm_on_demand/storage.rb
Normal file
|
@ -0,0 +1,104 @@
|
|||
require "fog/storm_on_demand"
|
||||
require "fog/storage"
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
class StormOnDemand < Fog::Service
|
||||
|
||||
API_URL = 'https://api.stormondemand.com'
|
||||
API_VERSION = 'v1'
|
||||
|
||||
requires :storm_on_demand_username, :storm_on_demand_password
|
||||
recognizes :storm_on_demand_auth_url
|
||||
|
||||
model_path 'fog/storm_on_demand/models/storage'
|
||||
model :cluster
|
||||
collection :clusters
|
||||
|
||||
request_path 'fog/storm_on_demand/requests/storage'
|
||||
request :list_clusters
|
||||
|
||||
|
||||
class Mock
|
||||
|
||||
def self.data
|
||||
@data ||= Hash.new
|
||||
end
|
||||
|
||||
def self.reset
|
||||
@data = nil
|
||||
end
|
||||
|
||||
def self.reset_data(keys=data.keys)
|
||||
for key in [*keys]
|
||||
data.delete(key)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
@storm_on_demand_username = options[:storm_on_demand_username]
|
||||
end
|
||||
|
||||
def data
|
||||
self.class.data[@storm_on_demand_username]
|
||||
end
|
||||
|
||||
def reset_data
|
||||
self.class.data.delete(@storm_on_demand_username)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Real
|
||||
|
||||
def initialize(options={})
|
||||
uri = URI.parse(options[:storm_on_demand_auth_url] ||= API_URL)
|
||||
@connection_options = options[:connection_options] || {}
|
||||
@host = uri.host
|
||||
@path = uri.path
|
||||
@persistent = options[:persistent] || false
|
||||
@port = uri.port
|
||||
@scheme = uri.scheme
|
||||
@storm_on_demand_username = options[:storm_on_demand_username]
|
||||
@storm_on_demand_password = options[:storm_on_demand_password]
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
||||
end
|
||||
|
||||
def reload
|
||||
@connection.reset
|
||||
end
|
||||
|
||||
def request(params)
|
||||
begin
|
||||
response = @connection.request(params.merge!({
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Basic ' << Base64.encode64("#{@storm_on_demand_username}:#{@storm_on_demand_password}").chomp
|
||||
}.merge!(params[:headers] || {}),
|
||||
:host => @host,
|
||||
:path => "#{@path}/#{API_VERSION}#{params[:path]}",
|
||||
:expects => 200,
|
||||
:method => :post
|
||||
}))
|
||||
puts response.body
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
raise case error
|
||||
when Excon::Errors::NotFound
|
||||
Fog::StormOnDemand::Compute::NotFound.slurp(error)
|
||||
else
|
||||
error
|
||||
end
|
||||
end
|
||||
unless response.body.empty?
|
||||
response.body = Fog::JSON.decode(response.body)
|
||||
end
|
||||
if response.body.has_key?('full_error')
|
||||
raise(Fog::Compute::StormOnDemand::Error, response.body.inspect)
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue