1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/terremark/vcloud.rb

98 lines
2.4 KiB
Ruby

module Fog
module Terremark
module Vcloud
module Bin
end
extend Fog::Terremark::Shared
def self.new(options={})
unless @required
shared_requires
@required = true
end
check_shared_options(options)
if Fog.mocking?
Fog::Terremark::Vcloud::Mock.new(options)
else
Fog::Terremark::Vcloud::Real.new(options)
end
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]
@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
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
ips.first['href'].split('/').last.to_i
else
nil
end
end
else
nil
end
end
end
class Mock
include Fog::Terremark::Shared::Mock
include Fog::Terremark::Shared::Parser
end
end
end
end