2010-04-16 03:20:02 -04:00
|
|
|
module Fog
|
|
|
|
module Terremark
|
|
|
|
module Vcloud
|
|
|
|
|
|
|
|
module Bin
|
|
|
|
end
|
|
|
|
|
2010-04-28 16:26:18 -04:00
|
|
|
module Defaults
|
|
|
|
HOST = 'services.vcloudexpress.terremark.com'
|
2012-04-28 13:05:06 -04:00
|
|
|
PATH = '/api/v0.8a-ext1.6'
|
|
|
|
#PATH = '/api/'
|
2010-04-28 16:26:18 -04:00
|
|
|
PORT = 443
|
|
|
|
SCHEME = 'https'
|
|
|
|
end
|
|
|
|
|
2010-04-16 03:20:02 -04:00
|
|
|
extend Fog::Terremark::Shared
|
|
|
|
|
|
|
|
def self.new(options={})
|
2011-10-19 15:49:34 -04:00
|
|
|
Fog::Logger.deprecation("Fog::Terremark::Vcloud is deprecated, to be replaced with Vcloud 1.0 someday/maybe [light_black](#{caller.first})[/]")
|
2010-04-16 03:20:02 -04:00
|
|
|
|
|
|
|
unless @required
|
|
|
|
shared_requires
|
|
|
|
@required = true
|
|
|
|
end
|
|
|
|
|
|
|
|
check_shared_options(options)
|
|
|
|
|
|
|
|
if Fog.mocking?
|
|
|
|
Fog::Terremark::Vcloud::Mock.new(options)
|
2010-10-13 04:42:11 -04:00
|
|
|
else
|
2010-04-16 03:20:02 -04:00
|
|
|
Fog::Terremark::Vcloud::Real.new(options)
|
2010-10-13 04:42:11 -04:00
|
|
|
end
|
2010-04-16 03:20:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
include Fog::Terremark::Shared::Real
|
|
|
|
include Fog::Terremark::Shared::Parser
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
@terremark_password = options[:terremark_vcloud_password]
|
|
|
|
@terremark_username = options[:terremark_vcloud_username]
|
2011-09-12 11:01:48 -04:00
|
|
|
@connection_options = options[:connection_options] || {}
|
|
|
|
@host = options[:host] || Fog::Terremark::Vcloud::Defaults::HOST
|
|
|
|
@path = options[:path] || Fog::Terremark::Vcloud::Defaults::PATH
|
|
|
|
@persistent = options[:persistent] || false
|
|
|
|
@port = options[:port] || Fog::Terremark::Vcloud::Defaults::PORT
|
|
|
|
@scheme = options[:scheme] || Fog::Terremark::Vcloud::Defaults::SCHEME
|
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
2010-04-16 03:20:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def default_vdc_id
|
|
|
|
if default_organization_id
|
|
|
|
@default_vdc_id ||= begin
|
|
|
|
vdcs = get_organization(default_organization_id).body['Links'].select {|link|
|
|
|
|
link['type'] == 'application/vnd.vmware.vcloud.vdc+xml'
|
|
|
|
}
|
|
|
|
if vdcs.length == 1
|
|
|
|
vdcs.first['href'].split('/').last.to_i
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_network_id
|
|
|
|
if default_vdc_id
|
|
|
|
@default_network_id ||= begin
|
|
|
|
networks = get_vdc(default_vdc_id).body['AvailableNetworks']
|
|
|
|
if networks.length == 1
|
|
|
|
networks.first['href'].split('/').last.to_i
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_public_ip_id
|
|
|
|
if default_vdc_id
|
|
|
|
@default_public_ip_id ||= begin
|
|
|
|
ips = get_public_ips(default_vdc_id).body['PublicIpAddresses']
|
|
|
|
if ips.length == 1
|
2010-04-25 14:42:35 -04:00
|
|
|
ips.first['href'].split('/').last.to_i
|
2010-04-16 03:20:02 -04:00
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2010-10-13 04:42:11 -04:00
|
|
|
end
|
2010-04-16 03:20:02 -04:00
|
|
|
|
2012-04-29 22:48:06 -04:00
|
|
|
def default_ssh_key
|
|
|
|
if default_ssh_key
|
|
|
|
@default_ssh_key ||= begin
|
|
|
|
keys = get_keys_list(default_organization_id).body["Keys"]
|
|
|
|
keys.find { |item| item["IsDefault"] == "true" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-04-16 03:20:02 -04:00
|
|
|
class Mock
|
|
|
|
include Fog::Terremark::Shared::Mock
|
|
|
|
include Fog::Terremark::Shared::Parser
|
2010-04-27 23:50:23 -04:00
|
|
|
|
|
|
|
def initialize(option = {})
|
|
|
|
super
|
2010-04-28 16:26:18 -04:00
|
|
|
@base_url = Fog::Terremark::Vcloud::Defaults::SCHEME + "://" +
|
|
|
|
Fog::Terremark::Vcloud::Defaults::HOST +
|
|
|
|
Fog::Terremark::Vcloud::Defaults::PATH
|
2011-05-19 18:35:33 -04:00
|
|
|
|
|
|
|
@terremark_username = options[:terremark_vcloud_username]
|
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
self.class.data[@terremark_username]
|
2010-04-27 23:50:23 -04:00
|
|
|
end
|
2011-05-19 18:35:33 -04:00
|
|
|
|
|
|
|
def reset_data
|
|
|
|
self.class.data.delete(@terremark_username)
|
|
|
|
end
|
|
|
|
|
2010-04-16 03:20:02 -04:00
|
|
|
end
|
|
|
|
|
2010-10-13 04:42:11 -04:00
|
|
|
end
|
2010-04-16 03:20:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|