mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[terremark] cleaner mocking/dependencies
This commit is contained in:
parent
10db608eb1
commit
f08f98f6bf
7 changed files with 93 additions and 108 deletions
|
@ -1,71 +1,80 @@
|
|||
require 'fog/terremark/requests/get_catalog'
|
||||
require 'fog/terremark/requests/get_catalog_item'
|
||||
require 'fog/terremark/requests/get_organization'
|
||||
require 'fog/terremark/requests/get_organizations'
|
||||
require 'fog/terremark/requests/get_vapp_template'
|
||||
require 'fog/terremark/requests/get_vdc'
|
||||
|
||||
module Fog
|
||||
class Terremark
|
||||
module Terremark
|
||||
|
||||
def self.dependencies
|
||||
[
|
||||
'fog/terremark/parsers/get_catalog.rb',
|
||||
'fog/terremark/parsers/get_catalog_item.rb',
|
||||
'fog/terremark/parsers/get_organization.rb',
|
||||
'fog/terremark/parsers/get_organizations.rb',
|
||||
'fog/terremark/parsers/get_vapp_template.rb',
|
||||
'fog/terremark/parsers/get_vdc.rb',
|
||||
'fog/terremark/requests/get_catalog.rb',
|
||||
'fog/terremark/requests/get_catalog_item.rb',
|
||||
'fog/terremark/requests/get_organization.rb',
|
||||
'fog/terremark/requests/get_organizations.rb',
|
||||
'fog/terremark/requests/get_vapp_template.rb',
|
||||
'fog/terremark/requests/get_vdc.rb'
|
||||
]
|
||||
end
|
||||
|
||||
def self.reload
|
||||
self.dependencies.each {|dependency| load(dependency)}
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
unless @terremark_password = options[:terremark_password]
|
||||
def self.new(options={})
|
||||
unless options[:terremark_password]
|
||||
raise ArgumentError.new('terremark_password is required to access terremark')
|
||||
end
|
||||
unless @terremark_username = options[:terremark_username]
|
||||
unless options[:terremark_username]
|
||||
raise ArgumentError.new('terremark_username is required to access terremark')
|
||||
end
|
||||
@host = options[:host] || "services.vcloudexpress.terremark.com"
|
||||
@path = options[:path] || "/api/v0.8"
|
||||
@port = options[:port] || 443
|
||||
@scheme = options[:scheme] || 'https'
|
||||
|
||||
@cookie = get_organizations.headers['Set-Cookie']
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request(params)
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
||||
headers = {}
|
||||
if @cookie
|
||||
headers.merge!('Cookie' => @cookie)
|
||||
if Fog.mocking?
|
||||
Fog::Slicehost::Mock.new(options)
|
||||
else
|
||||
Fog::Slicehost::Real.new(options)
|
||||
end
|
||||
response = @connection.request({
|
||||
:body => params[:body],
|
||||
:expects => params[:expects],
|
||||
:headers => headers.merge!(params[:headers] || {}),
|
||||
:host => @host,
|
||||
:method => params[:method],
|
||||
:parser => params[:parser],
|
||||
:path => "#{@path}/#{params[:path]}"
|
||||
})
|
||||
end
|
||||
|
||||
if Fog.mocking?
|
||||
class Mock
|
||||
|
||||
srand(Time.now.to_i)
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {}
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def self.reset_data(keys=data.keys)
|
||||
for key in [*keys]
|
||||
data.delete(key)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
@terremark_username = options[:terremark_username]
|
||||
@data = self.class.data[@terremark_username]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Real
|
||||
|
||||
def initialize(options={})
|
||||
@terremark_password = options[:terremark_password]
|
||||
@terremark_username = options[:terremark_username]
|
||||
@host = options[:host] || "services.vcloudexpress.terremark.com"
|
||||
@path = options[:path] || "/api/v0.8"
|
||||
@port = options[:port] || 443
|
||||
@scheme = options[:scheme] || 'https'
|
||||
@cookie = get_organizations.headers['Set-Cookie']
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request(params)
|
||||
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
||||
headers = {}
|
||||
if @cookie
|
||||
headers.merge!('Cookie' => @cookie)
|
||||
end
|
||||
response = @connection.request({
|
||||
:body => params[:body],
|
||||
:expects => params[:expects],
|
||||
:headers => headers.merge!(params[:headers] || {}),
|
||||
:host => @host,
|
||||
:method => params[:method],
|
||||
:parser => params[:parser],
|
||||
:path => "#{@path}/#{params[:path]}"
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Fog::Terremark.reload
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
unless Fog.mocking?
|
||||
module Fog
|
||||
module Terremark
|
||||
class Real
|
||||
|
||||
module Fog
|
||||
class Terremark
|
||||
require 'fog/terremark/parsers/get_catalog'
|
||||
|
||||
# Get details of a catalog
|
||||
#
|
||||
|
@ -27,12 +28,8 @@ unless Fog.mocking?
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
class Terremark
|
||||
class Mock
|
||||
|
||||
def get_catalog(vdc_id)
|
||||
raise MockNotImplemented.new("Contributions welcome!")
|
||||
|
@ -40,5 +37,4 @@ else
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
unless Fog.mocking?
|
||||
module Fog
|
||||
module Terremark
|
||||
class Real
|
||||
|
||||
module Fog
|
||||
class Terremark
|
||||
require 'fog/terremark/parsers/get_catalog_item'
|
||||
|
||||
# Get details of a catalog item
|
||||
#
|
||||
|
@ -30,12 +31,8 @@ unless Fog.mocking?
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
class Terremark
|
||||
class Mock
|
||||
|
||||
def get_catalog_item(catalog_item_id)
|
||||
raise MockNotImplemented.new("Contributions welcome!")
|
||||
|
@ -43,5 +40,4 @@ else
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
unless Fog.mocking?
|
||||
module Fog
|
||||
module Terremark
|
||||
class Real
|
||||
|
||||
module Fog
|
||||
class Terremark
|
||||
require 'fog/terremark/parsers/get_organization'
|
||||
|
||||
# Get details of an organization
|
||||
#
|
||||
|
@ -29,12 +30,8 @@ unless Fog.mocking?
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
class Terremark
|
||||
class Mock
|
||||
|
||||
def get_organization(organization_id)
|
||||
raise MockNotImplemented.new("Contributions welcome!")
|
||||
|
@ -42,5 +39,4 @@ else
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
unless Fog.mocking?
|
||||
module Fog
|
||||
module Terremark
|
||||
class Real
|
||||
|
||||
module Fog
|
||||
class Terremark
|
||||
require 'fog/terremark/parsers/get_organizations'
|
||||
|
||||
# Get list of organizations
|
||||
#
|
||||
|
@ -25,12 +26,8 @@ unless Fog.mocking?
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
class Terremark
|
||||
class Mock
|
||||
|
||||
def get_organizations
|
||||
raise MockNotImplemented.new("Contributions welcome!")
|
||||
|
@ -38,5 +35,4 @@ else
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
unless Fog.mocking?
|
||||
module Fog
|
||||
module Terremark
|
||||
class Real
|
||||
|
||||
module Fog
|
||||
class Terremark
|
||||
require 'fog/terremark/parsers/get_vapp_template'
|
||||
|
||||
# Get details of a vapp template
|
||||
#
|
||||
|
@ -30,12 +31,8 @@ unless Fog.mocking?
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
class Terremark
|
||||
class Mock
|
||||
|
||||
def get_vapp_template(vapp_template_id)
|
||||
raise MockNotImplemented.new("Contributions welcome!")
|
||||
|
@ -43,5 +40,4 @@ else
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
unless Fog.mocking?
|
||||
module Fog
|
||||
module Terremark
|
||||
class Real
|
||||
|
||||
module Fog
|
||||
class Terremark
|
||||
require 'fog/terremark/parsers/get_vdc'
|
||||
|
||||
# Get details of a vdc
|
||||
#
|
||||
|
@ -30,12 +31,8 @@ unless Fog.mocking?
|
|||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
module Fog
|
||||
class Terremark
|
||||
class Mock
|
||||
|
||||
def get_vdc(vdc_id)
|
||||
raise MockNotImplemented.new("Contributions welcome!")
|
||||
|
@ -43,5 +40,4 @@ else
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue