mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[stormondemand] fix typo bugs and move shared code into shared.rb module
This commit is contained in:
parent
1a8ddf379b
commit
dccc11d7a8
6 changed files with 64 additions and 141 deletions
|
@ -1,13 +1,11 @@
|
|||
require 'fog/storm_on_demand'
|
||||
require 'fog/compute'
|
||||
require 'fog/storm_on_demand/shared'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
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
|
||||
|
||||
|
@ -171,51 +169,7 @@ module Fog
|
|||
|
||||
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
|
||||
}))
|
||||
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?('error_class')
|
||||
raise(Fog::Compute::StormOnDemand::Error, response.body.inspect)
|
||||
end
|
||||
response
|
||||
end
|
||||
include Fog::StormOnDemand::RealShared
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'fog/storm_on_demand'
|
||||
require 'fog/dns'
|
||||
require 'fog/storm_on_demand/shared'
|
||||
|
||||
module Fog
|
||||
module DNS
|
||||
|
@ -75,51 +76,7 @@ module Fog
|
|||
|
||||
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
|
||||
}))
|
||||
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?('error_class')
|
||||
raise(Fog::Compute::StormOnDemand::Error, response.body.inspect)
|
||||
end
|
||||
response
|
||||
end
|
||||
include Fog::StormOnDemand::RealShared
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'fog/core/collections'
|
||||
require 'fog/core/collection'
|
||||
require 'fog/storm_on_demand/models/compute/firewall'
|
||||
|
||||
module Fog
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'fog/code/model'
|
||||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class StormOnDemand
|
||||
|
||||
class NetworkIP < Fog::model
|
||||
class NetworkIP < Fog::Model
|
||||
identity :id
|
||||
|
||||
attribute :broadcast
|
||||
|
|
55
lib/fog/storm_on_demand/shared.rb
Normal file
55
lib/fog/storm_on_demand/shared.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
module Fog
|
||||
module StormOnDemand
|
||||
module RealShared
|
||||
|
||||
API_URL = 'https://api.stormondemand.com'
|
||||
API_VERSION = 'v1'
|
||||
|
||||
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
|
||||
}))
|
||||
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?('error_class')
|
||||
raise(Fog::Compute::StormOnDemand::Error, response.body.inspect)
|
||||
end
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,6 @@
|
|||
require "fog/storm_on_demand"
|
||||
require "fog/storage"
|
||||
require "fog/storm_on_demand/shared"
|
||||
|
||||
module Fog
|
||||
module Storage
|
||||
|
@ -60,51 +61,7 @@ module Fog
|
|||
|
||||
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
|
||||
}))
|
||||
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?('error_class')
|
||||
raise(Fog::Compute::StormOnDemand::Error, response.body.inspect)
|
||||
end
|
||||
response
|
||||
end
|
||||
include Fog::StormOnDemand::RealShared
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue