mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[terremark] More mocking
This commit is contained in:
parent
1bde6e169a
commit
df93720c0d
5 changed files with 120 additions and 24 deletions
|
@ -5,6 +5,13 @@ module Fog
|
|||
module Bin
|
||||
end
|
||||
|
||||
module Defaults
|
||||
HOST = 'services.enterprisecloud.terremark.com'
|
||||
PATH = '/api/v0.8a-ext2.0'
|
||||
PORT = 443
|
||||
SCHEME = 'https'
|
||||
end
|
||||
|
||||
extend Fog::Terremark::Shared
|
||||
|
||||
def self.new(options={})
|
||||
|
@ -31,10 +38,10 @@ module Fog
|
|||
def initialize(options={})
|
||||
@terremark_password = options[:terremark_ecloud_password]
|
||||
@terremark_username = options[:terremark_ecloud_username]
|
||||
@host = options[:host] || "services.enterprisecloud.terremark.com"
|
||||
@path = options[:path] || "/api/v0.8a-ext2.0"
|
||||
@port = options[:port] || 443
|
||||
@scheme = options[:scheme] || 'https'
|
||||
@host = options[:host] || Fog::Terremark::Ecloud::Defaults::HOST
|
||||
@path = options[:path] || Fog::Terremark::Ecloud::Defaults::PATH
|
||||
@port = options[:port] || Fog::Terremark::Ecloud::Defaults::PORT
|
||||
@scheme = options[:scheme] || Fog::Terremark::Ecloud::Defaults::SCHEME
|
||||
@cookie = get_organizations.headers['Set-Cookie']
|
||||
end
|
||||
|
||||
|
@ -46,6 +53,9 @@ module Fog
|
|||
|
||||
def initialize(option = {})
|
||||
super
|
||||
@base_url = Fog::Terremark::Ecloud::Defaults::SCHEME + "://" +
|
||||
Fog::Terremark::Ecloud::Defaults::HOST +
|
||||
Fog::Terremark::Ecloud::Defaults::PATH
|
||||
@data = self.class.data[:terremark_ecloud_username]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,7 +33,50 @@ module Fog
|
|||
module Mock
|
||||
|
||||
def get_organization(organization_id)
|
||||
raise MockNotImplemented.new("Contributions welcome!")
|
||||
response = Excon::Response.new
|
||||
|
||||
if org = @data[:organizations].detect { |org| org[:info][:id] == organization_id }
|
||||
|
||||
body = { "name" => org[:info][:name],
|
||||
"href" => "#{@base_url}/#{org[:info][:id]}",
|
||||
"Links" => [] }
|
||||
|
||||
body["Links"] = case self
|
||||
when Fog::Terremark::Vcloud::Mock
|
||||
_vdc_links(org[:vdcs][0])
|
||||
when Fog::Terremark::Ecloud::Mock
|
||||
org[:vdcs].map do |vdc|
|
||||
_vdc_links(vdc)
|
||||
end.flatten
|
||||
end
|
||||
|
||||
response.status = 200
|
||||
response.body = body
|
||||
response.headers = Fog::Terremark::Shared::Mock.headers(response.body, "application/vnd.vmware.vcloud.org+xml")
|
||||
else
|
||||
response.status = Fog::Terremark::Shared::Mock.unathorized_status
|
||||
response.headers = Fog::Terremark::Shared::Mock.error_headers
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def _vdc_links(vdc)
|
||||
[{ "name" => vdc[:name],
|
||||
"href" => "#{@base_url}/vdc/#{vdc[:id]}",
|
||||
"rel" => "down",
|
||||
"type" => "application/vnd.vmware.vcloud.vdc+xml" },
|
||||
{ "name" => "#{vdc[:name]} Catalog",
|
||||
"href" => "#{@base_url}/vdc/#{vdc[:id]}/catalog",
|
||||
"rel" => "down",
|
||||
"type" => "application/vnd.vmware.vcloud.catalog+xml" },
|
||||
{ "name" => "#{vdc[:name]} Tasks List",
|
||||
"href" => "#{@base_url}/vdc/#{vdc[:id]}/taskslist",
|
||||
"rel" => "down",
|
||||
"type" => "application/vnd.vmware.vcloud.tasksList+xml" }
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -33,11 +33,12 @@ module Fog
|
|||
response = Excon::Response.new
|
||||
org_list = @data[:organizations].map do |organization|
|
||||
{ "name" => organization[:info][:name],
|
||||
"href" => "https://services.enterprisecloud.terremark.com/api/v0.8a-ext2.0/org/#{organization[:info][:id]}",
|
||||
"href" => "#{@base_url}/org/#{organization[:info][:id]}",
|
||||
"type" => "application/vnd.vmware.vcloud.org+xml"
|
||||
}
|
||||
end
|
||||
response.body = { "OrgList" => org_list }
|
||||
response.status = 200
|
||||
response.headers = Fog::Terremark::Shared::Mock.headers(response.body, "application/vnd.vmware.vcloud.orgList+xml")
|
||||
response
|
||||
end
|
||||
|
|
|
@ -2,6 +2,23 @@ module Fog
|
|||
module Terremark
|
||||
module Shared
|
||||
|
||||
# Commond methods shared by Real and Mock
|
||||
module Common
|
||||
|
||||
# TODO: bust cache on organization creation?
|
||||
def default_organization_id
|
||||
@default_organization_id ||= begin
|
||||
org_list = get_organizations.body['OrgList']
|
||||
if org_list.length == 1
|
||||
org_list.first['href'].split('/').last.to_i
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module Parser
|
||||
|
||||
def parse(data)
|
||||
|
@ -16,18 +33,7 @@ module Fog
|
|||
end
|
||||
|
||||
module Real
|
||||
|
||||
# TODO: bust cache on organization creation?
|
||||
def default_organization_id
|
||||
@default_organization_id ||= begin
|
||||
org_list = get_organizations.body['OrgList']
|
||||
if org_list.length == 1
|
||||
org_list.first['href'].split('/').last.to_i
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
include Common
|
||||
|
||||
private
|
||||
|
||||
|
@ -51,6 +57,7 @@ module Fog
|
|||
end
|
||||
|
||||
module Mock
|
||||
include Common
|
||||
|
||||
DATA = {
|
||||
:organizations =>
|
||||
|
@ -58,11 +65,32 @@ module Fog
|
|||
{
|
||||
:info => {
|
||||
:name => "Boom Inc.",
|
||||
:id => "1"
|
||||
}
|
||||
:id => 1
|
||||
},
|
||||
:vdcs => [
|
||||
{ :id => 21,
|
||||
:name => "Boomstick"
|
||||
},
|
||||
{ :id => 22,
|
||||
:name => "Rock-n-Roll"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
def self.error_headers
|
||||
{"X-Powered-By"=>"ASP.NET",
|
||||
"Date"=> Time.now.to_s,
|
||||
"Content-Type"=>"text/html",
|
||||
"Content-Length"=>"0",
|
||||
"Server"=>"Microsoft-IIS/7.0",
|
||||
"Cache-Control"=>"private"}
|
||||
end
|
||||
|
||||
def self.unathorized_status
|
||||
401
|
||||
end
|
||||
|
||||
def self.headers(body, content_type)
|
||||
{"X-Powered-By"=>"ASP.NET",
|
||||
|
@ -74,6 +102,10 @@ module Fog
|
|||
"Cache-Control"=>"private"}
|
||||
end
|
||||
|
||||
def self.status
|
||||
200
|
||||
end
|
||||
|
||||
def initialize(options={})
|
||||
self.class.instance_eval '
|
||||
def self.data
|
||||
|
|
|
@ -5,6 +5,13 @@ module Fog
|
|||
module Bin
|
||||
end
|
||||
|
||||
module Defaults
|
||||
HOST = 'services.vcloudexpress.terremark.com'
|
||||
PATH = '/api/v0.8'
|
||||
PORT = 443
|
||||
SCHEME = 'https'
|
||||
end
|
||||
|
||||
extend Fog::Terremark::Shared
|
||||
|
||||
def self.new(options={})
|
||||
|
@ -31,10 +38,10 @@ module Fog
|
|||
def initialize(options={})
|
||||
@terremark_password = options[:terremark_vcloud_password]
|
||||
@terremark_username = options[:terremark_vcloud_username]
|
||||
@host = options[:host] || "services.vcloudexpress.terremark.com"
|
||||
@path = options[:path] || "/api/v0.8"
|
||||
@port = options[:port] || 443
|
||||
@scheme = options[:scheme] || 'https'
|
||||
@host = options[:host] || Fog::Terremark::Vcloud::Defaults::HOST
|
||||
@path = options[:path] || Fog::Terremark::Vcloud::Defaults::PATH
|
||||
@port = options[:port] || FOG::Terremark::Vcloud::Defaults::PORT
|
||||
@scheme = options[:scheme] || FOG::Terremark::Vcloud::Defaults::SCHEME
|
||||
@cookie = get_organizations.headers['Set-Cookie']
|
||||
end
|
||||
|
||||
|
@ -92,6 +99,9 @@ module Fog
|
|||
|
||||
def initialize(option = {})
|
||||
super
|
||||
@base_url = Fog::Terremark::Vcloud::Defaults::SCHEME + "://" +
|
||||
Fog::Terremark::Vcloud::Defaults::HOST +
|
||||
Fog::Terremark::Vcloud::Defaults::PATH
|
||||
@data = self.class.data[:terremark_vcloud_username]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue