fog 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -8
- data/Gemfile.lock +3 -3
- data/bin/fog +2 -10
- data/fog.gemspec +45 -20
- data/lib/fog.rb +2 -1
- data/lib/fog/attributes.rb +48 -8
- data/lib/fog/aws/ec2.rb +5 -2
- data/lib/fog/aws/elb.rb +5 -2
- data/lib/fog/aws/models/ec2/server.rb +1 -1
- data/lib/fog/aws/requests/simpledb/put_attributes.rb +43 -12
- data/lib/fog/aws/s3.rb +2 -2
- data/lib/fog/aws/simpledb.rb +15 -3
- data/lib/fog/bin.rb +11 -2
- data/lib/fog/bluebox.rb +5 -1
- data/lib/fog/connection.rb +9 -1
- data/lib/fog/credentials.rb +3 -0
- data/lib/fog/new_servers.rb +89 -0
- data/lib/fog/new_servers/bin.rb +30 -0
- data/lib/fog/new_servers/requests/add_server.rb +39 -0
- data/lib/fog/new_servers/requests/cancel_server.rb +36 -0
- data/lib/fog/new_servers/requests/get_server.rb +42 -0
- data/lib/fog/new_servers/requests/list_images.rb +33 -0
- data/lib/fog/new_servers/requests/list_plans.rb +36 -0
- data/lib/fog/new_servers/requests/list_servers.rb +43 -0
- data/lib/fog/new_servers/requests/reboot_server.rb +30 -0
- data/lib/fog/parser.rb +6 -0
- data/lib/fog/rackspace/files.rb +8 -2
- data/lib/fog/rackspace/models/servers/server.rb +5 -0
- data/lib/fog/rackspace/servers.rb +5 -1
- data/lib/fog/service.rb +6 -1
- data/lib/fog/slicehost.rb +5 -1
- data/lib/fog/terremark/ecloud.rb +1 -0
- data/lib/fog/terremark/shared.rb +4 -1
- data/lib/fog/terremark/vcloud.rb +1 -0
- data/lib/fog/vcloud.rb +150 -141
- data/lib/fog/vcloud/bin.rb +2 -2
- data/lib/fog/vcloud/collection.rb +3 -84
- data/lib/fog/vcloud/extension.rb +44 -0
- data/lib/fog/vcloud/generators.rb +33 -0
- data/lib/fog/vcloud/model.rb +5 -38
- data/lib/fog/vcloud/models/vdc.rb +14 -24
- data/lib/fog/vcloud/models/vdcs.rb +13 -8
- data/lib/fog/vcloud/requests/get_network.rb +4 -11
- data/lib/fog/vcloud/requests/get_organization.rb +4 -11
- data/lib/fog/vcloud/requests/get_vdc.rb +4 -12
- data/lib/fog/vcloud/requests/get_versions.rb +4 -13
- data/lib/fog/vcloud/requests/login.rb +4 -4
- data/lib/fog/vcloud/terremark/ecloud.rb +125 -54
- data/lib/fog/vcloud/terremark/ecloud/models/catalog.rb +30 -0
- data/lib/fog/vcloud/terremark/ecloud/models/catalog_item.rb +31 -0
- data/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb +21 -22
- data/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb +11 -25
- data/lib/fog/vcloud/terremark/ecloud/models/ip.rb +38 -5
- data/lib/fog/vcloud/terremark/ecloud/models/ips.rb +11 -15
- data/lib/fog/vcloud/terremark/ecloud/models/network.rb +52 -11
- data/lib/fog/vcloud/terremark/ecloud/models/networks.rb +14 -13
- data/lib/fog/vcloud/terremark/ecloud/models/node.rb +47 -0
- data/lib/fog/vcloud/terremark/ecloud/models/nodes.rb +30 -0
- data/lib/fog/vcloud/terremark/ecloud/models/public_ip.rb +6 -9
- data/lib/fog/vcloud/terremark/ecloud/models/public_ips.rb +19 -3
- data/lib/fog/vcloud/terremark/ecloud/models/server.rb +203 -0
- data/lib/fog/vcloud/terremark/ecloud/models/servers.rb +43 -0
- data/lib/fog/vcloud/terremark/ecloud/models/task.rb +22 -0
- data/lib/fog/vcloud/terremark/ecloud/models/tasks.rb +30 -0
- data/lib/fog/vcloud/terremark/ecloud/models/vdc.rb +32 -10
- data/lib/fog/vcloud/terremark/ecloud/models/vdcs.rb +5 -6
- data/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb +23 -10
- data/lib/fog/vcloud/terremark/ecloud/requests/add_node.rb +54 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb +14 -12
- data/lib/fog/vcloud/terremark/ecloud/requests/configure_network.rb +53 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/configure_network_ip.rb +52 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/configure_node.rb +42 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/configure_vapp.rb +115 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/delete_internet_service.rb +4 -23
- data/lib/fog/vcloud/terremark/ecloud/requests/delete_node.rb +0 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/delete_vapp.rb +19 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/get_catalog.rb +18 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/get_catalog_item.rb +18 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/get_customization_options.rb +18 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb +9 -16
- data/lib/fog/vcloud/terremark/ecloud/requests/get_network.rb +8 -14
- data/lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb +36 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/get_network_ip.rb +44 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/get_network_ips.rb +11 -12
- data/lib/fog/vcloud/terremark/ecloud/requests/get_node.rb +18 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/get_nodes.rb +18 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/get_public_ip.rb +5 -19
- data/lib/fog/vcloud/terremark/ecloud/requests/get_public_ips.rb +5 -12
- data/lib/fog/vcloud/terremark/ecloud/requests/get_task.rb +18 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/get_task_list.rb +19 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/get_vapp.rb +18 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/get_vdc.rb +7 -15
- data/lib/fog/vcloud/terremark/ecloud/requests/power_off.rb +18 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/power_on.rb +18 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/power_reset.rb +18 -0
- data/lib/fog/vcloud/terremark/ecloud/requests/power_shutdown.rb +18 -0
- data/lib/fog/vcloud/terremark/vcloud.rb +4 -18
- data/lib/fog/vcloud/terremark/vcloud/requests/get_vdc.rb +4 -12
- data/spec/aws/requests/simpledb/put_attributes_spec.rb +18 -0
- data/spec/vcloud/bin_spec.rb +2 -2
- data/spec/vcloud/models/vdc_spec.rb +35 -29
- data/spec/vcloud/requests/get_network_spec.rb +32 -43
- data/spec/vcloud/requests/get_organization_spec.rb +45 -38
- data/spec/vcloud/requests/get_vdc_spec.rb +42 -32
- data/spec/vcloud/requests/get_versions_spec.rb +17 -17
- data/spec/vcloud/requests/login_spec.rb +7 -4
- data/spec/vcloud/spec_helper.rb +137 -46
- data/spec/vcloud/terremark/ecloud/models/internet_service_spec.rb +53 -58
- data/spec/vcloud/terremark/ecloud/models/internet_services_spec.rb +20 -20
- data/spec/vcloud/terremark/ecloud/models/ip_spec.rb +22 -21
- data/spec/vcloud/terremark/ecloud/models/ips_spec.rb +18 -18
- data/spec/vcloud/terremark/ecloud/models/network_spec.rb +55 -51
- data/spec/vcloud/terremark/ecloud/models/networks_spec.rb +16 -15
- data/spec/vcloud/terremark/ecloud/models/public_ip_spec.rb +26 -27
- data/spec/vcloud/terremark/ecloud/models/public_ips_spec.rb +16 -15
- data/spec/vcloud/terremark/ecloud/models/vdc_spec.rb +52 -36
- data/spec/vcloud/terremark/ecloud/models/vdcs_spec.rb +18 -15
- data/spec/vcloud/terremark/ecloud/requests/add_internet_service_spec.rb +46 -43
- data/spec/vcloud/terremark/ecloud/requests/configure_internet_service_spec.rb +37 -32
- data/spec/vcloud/terremark/ecloud/requests/delete_internet_service_spec.rb +26 -23
- data/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb +57 -49
- data/spec/vcloud/terremark/ecloud/requests/get_network_ip_spec.rb +41 -0
- data/spec/vcloud/terremark/ecloud/requests/get_network_ips_spec.rb +39 -34
- data/spec/vcloud/terremark/ecloud/requests/get_network_spec.rb +26 -48
- data/spec/vcloud/terremark/ecloud/requests/get_public_ip_spec.rb +25 -26
- data/spec/vcloud/terremark/ecloud/requests/get_public_ips_spec.rb +35 -27
- data/spec/vcloud/terremark/ecloud/requests/get_vdc_spec.rb +85 -110
- data/spec/vcloud/terremark/ecloud/requests/login_spec.rb +7 -4
- data/spec/vcloud/vcloud_spec.rb +9 -8
- metadata +62 -26
- data/lib/fog/vcloud/parser.rb +0 -42
- data/lib/fog/vcloud/parsers/get_organization.rb +0 -37
- data/lib/fog/vcloud/parsers/get_vdc.rb +0 -62
- data/lib/fog/vcloud/parsers/get_versions.rb +0 -46
- data/lib/fog/vcloud/parsers/login.rb +0 -36
- data/lib/fog/vcloud/parsers/network.rb +0 -53
- data/lib/fog/vcloud/terremark/all.rb +0 -9
- data/lib/fog/vcloud/terremark/ecloud/parsers/get_internet_services.rb +0 -59
- data/lib/fog/vcloud/terremark/ecloud/parsers/get_public_ip.rb +0 -30
- data/lib/fog/vcloud/terremark/ecloud/parsers/get_public_ips.rb +0 -40
- data/lib/fog/vcloud/terremark/ecloud/parsers/get_vdc.rb +0 -59
- data/lib/fog/vcloud/terremark/ecloud/parsers/internet_service.rb +0 -58
- data/lib/fog/vcloud/terremark/ecloud/parsers/network.rb +0 -28
- data/lib/fog/vcloud/terremark/ecloud/parsers/network_ips.rb +0 -31
- data/lib/fog/vcloud/terremark/ecloud/requests/login.rb +0 -27
- data/lib/fog/vcloud/terremark/vcloud/parsers/get_vdc.rb +0 -34
- data/spec/vcloud/terremark/vcloud/requests/get_vdc_spec.rb +0 -74
data/lib/fog/parser.rb
CHANGED
@@ -41,6 +41,8 @@ module Fog
|
|
41
41
|
last = @stack.pop
|
42
42
|
if last.empty? && @value.empty?
|
43
43
|
@stack.last[name.to_sym] = ''
|
44
|
+
elsif last == {:i_nil=>"true"}
|
45
|
+
@stack.last[name.to_sym] = nil
|
44
46
|
elsif !@value.empty?
|
45
47
|
@stack.last[name.to_sym] = @value
|
46
48
|
end
|
@@ -51,6 +53,10 @@ module Fog
|
|
51
53
|
@stack.first
|
52
54
|
end
|
53
55
|
|
56
|
+
def response
|
57
|
+
body
|
58
|
+
end
|
59
|
+
|
54
60
|
def start_element(name, attributes = [])
|
55
61
|
@value = ''
|
56
62
|
parsed_attributes = {}
|
data/lib/fog/rackspace/files.rb
CHANGED
@@ -78,20 +78,27 @@ module Fog
|
|
78
78
|
def initialize(options={})
|
79
79
|
credentials = Fog::Rackspace.authenticate(options)
|
80
80
|
@auth_token = credentials['X-Auth-Token']
|
81
|
+
|
81
82
|
cdn_uri = URI.parse(credentials['X-CDN-Management-Url'])
|
82
83
|
@cdn_host = cdn_uri.host
|
83
84
|
@cdn_path = cdn_uri.path
|
84
85
|
@cdn_port = cdn_uri.port
|
85
86
|
@cdn_scheme = cdn_uri.scheme
|
87
|
+
@cdn_connection = Fog::Connection.new("#{@cdn_scheme}://#{@cdn_host}:#{@cdn_port}", options[:persistent])
|
88
|
+
|
86
89
|
storage_uri = URI.parse(credentials['X-Storage-Url'])
|
87
90
|
@storage_host = storage_uri.host
|
88
91
|
@storage_path = storage_uri.path
|
89
92
|
@storage_port = storage_uri.port
|
90
93
|
@storage_scheme = storage_uri.scheme
|
94
|
+
@storage_connection = Fog::Connection.new("#{@storage_scheme}://#{@storage_host}:#{@storage_port}", options[:persistent])
|
95
|
+
end
|
96
|
+
|
97
|
+
def reload
|
98
|
+
@connection.reset
|
91
99
|
end
|
92
100
|
|
93
101
|
def cdn_request(params)
|
94
|
-
@cdn_connection = Fog::Connection.new("#{@cdn_scheme}://#{@cdn_host}:#{@cdn_port}")
|
95
102
|
response = @cdn_connection.request(params.merge!({
|
96
103
|
:headers => {
|
97
104
|
'Content-Type' => 'application/json',
|
@@ -107,7 +114,6 @@ module Fog
|
|
107
114
|
end
|
108
115
|
|
109
116
|
def storage_request(params, parse_json = true, &block)
|
110
|
-
@storage_connection = Fog::Connection.new("#{@storage_scheme}://#{@storage_host}:#{@storage_port}")
|
111
117
|
response = @storage_connection.request(params.merge!({
|
112
118
|
:headers => {
|
113
119
|
'Content-Type' => 'application/json',
|
@@ -73,10 +73,14 @@ module Fog
|
|
73
73
|
@path = uri.path
|
74
74
|
@port = uri.port
|
75
75
|
@scheme = uri.scheme
|
76
|
+
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
77
|
+
end
|
78
|
+
|
79
|
+
def reload
|
80
|
+
@connection.reset
|
76
81
|
end
|
77
82
|
|
78
83
|
def request(params)
|
79
|
-
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
80
84
|
begin
|
81
85
|
response = @connection.request(params.merge!({
|
82
86
|
:headers => {
|
data/lib/fog/service.rb
CHANGED
@@ -32,11 +32,16 @@ module Fog
|
|
32
32
|
@required = true
|
33
33
|
end
|
34
34
|
|
35
|
-
if Fog.mocking?
|
35
|
+
instance = if Fog.mocking?
|
36
36
|
Mock.new(options)
|
37
37
|
else
|
38
38
|
Real.new(options)
|
39
39
|
end
|
40
|
+
|
41
|
+
if self.respond_to?(:after_new)
|
42
|
+
instance = self.after_new(instance, options)
|
43
|
+
end
|
44
|
+
instance
|
40
45
|
end
|
41
46
|
EOS
|
42
47
|
end
|
data/lib/fog/slicehost.rb
CHANGED
@@ -54,10 +54,14 @@ module Fog
|
|
54
54
|
@host = options[:host] || "api.slicehost.com"
|
55
55
|
@port = options[:port] || 443
|
56
56
|
@scheme = options[:scheme] || 'https'
|
57
|
+
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
58
|
+
end
|
59
|
+
|
60
|
+
def reload
|
61
|
+
@connection.reset
|
57
62
|
end
|
58
63
|
|
59
64
|
def request(params)
|
60
|
-
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
|
61
65
|
params[:headers] ||= {}
|
62
66
|
params[:headers].merge!({
|
63
67
|
'Authorization' => "Basic #{Base64.encode64(@slicehost_password).delete("\r\n")}"
|
data/lib/fog/terremark/ecloud.rb
CHANGED
@@ -42,6 +42,7 @@ module Fog
|
|
42
42
|
@path = options[:path] || Fog::Terremark::Ecloud::Defaults::PATH
|
43
43
|
@port = options[:port] || Fog::Terremark::Ecloud::Defaults::PORT
|
44
44
|
@scheme = options[:scheme] || Fog::Terremark::Ecloud::Defaults::SCHEME
|
45
|
+
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
45
46
|
end
|
46
47
|
|
47
48
|
end
|
data/lib/fog/terremark/shared.rb
CHANGED
data/lib/fog/terremark/vcloud.rb
CHANGED
@@ -42,6 +42,7 @@ module Fog
|
|
42
42
|
@path = options[:path] || Fog::Terremark::Vcloud::Defaults::PATH
|
43
43
|
@port = options[:port] || Fog::Terremark::Vcloud::Defaults::PORT
|
44
44
|
@scheme = options[:scheme] || Fog::Terremark::Vcloud::Defaults::SCHEME
|
45
|
+
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
45
46
|
end
|
46
47
|
|
47
48
|
def default_vdc_id
|
data/lib/fog/vcloud.rb
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require 'fog/vcloud/model'
|
3
|
+
require 'fog/vcloud/collection'
|
4
|
+
require 'fog/vcloud/generators'
|
5
|
+
require 'fog/vcloud/extension'
|
6
|
+
require 'fog/vcloud/terremark/vcloud'
|
7
|
+
require 'fog/vcloud/terremark/ecloud'
|
8
|
+
|
1
9
|
module URI
|
2
10
|
class Generic
|
3
11
|
def host_url
|
@@ -8,19 +16,35 @@ end
|
|
8
16
|
|
9
17
|
module Fog
|
10
18
|
module Vcloud
|
19
|
+
extend Fog::Service
|
20
|
+
|
21
|
+
requires :username, :password, :versions_uri
|
22
|
+
|
23
|
+
model_path 'fog/vcloud/models'
|
24
|
+
model 'vdc'
|
25
|
+
model 'vdcs'
|
26
|
+
|
27
|
+
request_path 'fog/vcloud/requests'
|
28
|
+
request :login
|
29
|
+
request :get_versions
|
30
|
+
request :get_vdc
|
31
|
+
request :get_organization
|
32
|
+
request :get_network
|
33
|
+
|
34
|
+
def self.after_new(instance, options={})
|
35
|
+
if mod = options[:module]
|
36
|
+
instance.extend eval("#{mod}")
|
37
|
+
end
|
38
|
+
instance
|
39
|
+
end
|
11
40
|
|
12
41
|
class UnsupportedVersion < Exception ; end
|
13
42
|
|
14
|
-
module Options
|
15
|
-
REQUIRED = [:versions_uri, :username, :password]
|
16
|
-
OPTIONAL = [:module, :version]
|
17
|
-
ALL = REQUIRED + OPTIONAL
|
18
|
-
end
|
19
|
-
|
20
43
|
class Real
|
44
|
+
extend Fog::Vcloud::Generators
|
21
45
|
|
22
46
|
attr_accessor :login_uri
|
23
|
-
attr_reader :supported_versions
|
47
|
+
attr_reader :supported_versions, :versions_uri
|
24
48
|
|
25
49
|
def initialize(options = {})
|
26
50
|
@connections = {}
|
@@ -30,6 +54,7 @@ module Fog
|
|
30
54
|
@username = options[:username]
|
31
55
|
@password = options[:password]
|
32
56
|
@login_uri = get_login_uri
|
57
|
+
@persistent = options[:persistent]
|
33
58
|
end
|
34
59
|
|
35
60
|
def default_organization_uri
|
@@ -37,39 +62,86 @@ module Fog
|
|
37
62
|
unless @login_results
|
38
63
|
do_login
|
39
64
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
65
|
+
case @login_results.body[:Org]
|
66
|
+
when Array
|
67
|
+
@login_results.body[:Org].first[:href]
|
68
|
+
when Hash
|
69
|
+
@login_results.body[:Org][:href]
|
43
70
|
else
|
44
71
|
nil
|
45
72
|
end
|
46
73
|
end
|
47
74
|
end
|
48
75
|
|
76
|
+
def reload
|
77
|
+
@connections.each_value { |k,v| v.reset if v }
|
78
|
+
end
|
79
|
+
|
80
|
+
# If the cookie isn't set, do a get_organizations call to set it
|
81
|
+
# and try the request.
|
82
|
+
# If we get an Unauthorized error, we assume the token expired, re-auth and try again
|
83
|
+
def request(params)
|
84
|
+
unless @cookie
|
85
|
+
do_login
|
86
|
+
end
|
87
|
+
begin
|
88
|
+
do_request(params)
|
89
|
+
rescue Excon::Errors::Unauthorized => e
|
90
|
+
do_login
|
91
|
+
do_request(params)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
49
96
|
private
|
50
97
|
|
51
|
-
def
|
52
|
-
|
98
|
+
def ensure_parsed(uri)
|
99
|
+
if uri.is_a?(String)
|
100
|
+
URI.parse(uri)
|
101
|
+
else
|
102
|
+
uri
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def ensure_unparsed(uri)
|
107
|
+
if uri.is_a?(String)
|
108
|
+
uri
|
109
|
+
else
|
110
|
+
uri.to_s
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def supported_version_numbers
|
115
|
+
case @supported_versions
|
116
|
+
when Array
|
117
|
+
@supported_versions.map { |version| version[:Version] }
|
118
|
+
when Hash
|
119
|
+
@supported_versions[:Version]
|
120
|
+
end
|
53
121
|
end
|
54
122
|
|
55
123
|
def get_login_uri
|
56
124
|
check_versions
|
57
|
-
URI.parse
|
125
|
+
URI.parse case @supported_versions
|
126
|
+
when Array
|
127
|
+
@supported_versions.detect {|version| version[:Version] == @version }[:LoginUrl]
|
128
|
+
when Hash
|
129
|
+
@supported_versions[:LoginUrl]
|
130
|
+
end
|
58
131
|
end
|
59
132
|
|
60
133
|
# Load up @all_versions and @supported_versions from the provided :versions_uri
|
61
134
|
# If there are no supported versions raise an error
|
62
135
|
# And choose a default version is none is specified
|
63
136
|
def check_versions
|
64
|
-
@
|
65
|
-
@supported_versions = @all_versions.select { |version| version.supported == true }
|
137
|
+
@supported_versions = get_versions(@versions_uri).body[:VersionInfo]
|
66
138
|
|
67
139
|
if @supported_versions.empty?
|
68
140
|
raise UnsupportedVersion.new("No supported versions found @ #{@version_uri}")
|
69
141
|
end
|
70
142
|
|
71
143
|
unless @version
|
72
|
-
@version =
|
144
|
+
@version = supported_version_numbers.first
|
73
145
|
end
|
74
146
|
end
|
75
147
|
|
@@ -90,39 +162,48 @@ module Fog
|
|
90
162
|
@cookie = @login_results.headers['Set-Cookie']
|
91
163
|
end
|
92
164
|
|
93
|
-
# If the cookie isn't set, do a get_organizations call to set it
|
94
|
-
# and try the request.
|
95
|
-
# If we get an Unauthoried error, we assume the token expired, re-auth and try again
|
96
|
-
def request(params)
|
97
|
-
unless @cookie
|
98
|
-
do_login
|
99
|
-
end
|
100
|
-
begin
|
101
|
-
do_request(params)
|
102
|
-
rescue Excon::Errors::Unauthorized => e
|
103
|
-
do_login
|
104
|
-
do_request(params)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
165
|
# Actually do the request
|
109
166
|
def do_request(params)
|
167
|
+
# Convert the uri to a URI if it's a string.
|
110
168
|
if params[:uri].is_a?(String)
|
111
169
|
params[:uri] = URI.parse(params[:uri])
|
112
170
|
end
|
113
|
-
|
171
|
+
|
172
|
+
# Hash connections on the host_url ... There's nothing to say we won't get URI's that go to
|
173
|
+
# different hosts.
|
174
|
+
@connections[params[:uri].host_url] ||= Fog::Connection.new(params[:uri].host_url, @persistent)
|
175
|
+
|
176
|
+
# Set headers to an empty hash if none are set.
|
114
177
|
headers = params[:headers] || {}
|
178
|
+
|
179
|
+
# Add our auth cookie to the headers
|
115
180
|
if @cookie
|
116
181
|
headers.merge!('Cookie' => @cookie)
|
117
182
|
end
|
118
|
-
|
119
|
-
|
120
|
-
|
183
|
+
|
184
|
+
# Make the request
|
185
|
+
response = @connections[params[:uri].host_url].request({
|
186
|
+
:body => params[:body] || '',
|
187
|
+
:expects => params[:expects] || 200,
|
121
188
|
:headers => headers,
|
122
|
-
:method => params[:method],
|
123
|
-
:parser => params[:parser],
|
189
|
+
:method => params[:method] || 'GET',
|
124
190
|
:path => params[:uri].path
|
125
191
|
})
|
192
|
+
|
193
|
+
# Parse the response body into a hash
|
194
|
+
#puts response.body
|
195
|
+
unless response.body.empty?
|
196
|
+
if params[:parse]
|
197
|
+
document = Fog::ToHashDocument.new
|
198
|
+
parser = Nokogiri::XML::SAX::PushParser.new(document)
|
199
|
+
parser << response.body
|
200
|
+
parser.finish
|
201
|
+
|
202
|
+
response.body = document.body
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
response
|
126
207
|
end
|
127
208
|
end
|
128
209
|
|
@@ -135,7 +216,7 @@ module Fog
|
|
135
216
|
@mock_data = nil
|
136
217
|
end
|
137
218
|
|
138
|
-
def self.data
|
219
|
+
def self.data( base_url = self.base_url )
|
139
220
|
@mock_data ||=
|
140
221
|
{
|
141
222
|
:versions => [
|
@@ -166,32 +247,35 @@ module Fog
|
|
166
247
|
:name => "Boom Inc.",
|
167
248
|
},
|
168
249
|
:vdcs => [
|
250
|
+
|
169
251
|
{ :href => "#{base_url}/vdc/21",
|
170
|
-
:id => 21,
|
252
|
+
:id => "21",
|
171
253
|
:name => "Boomstick",
|
172
|
-
:storage => { :used => 105, :allocated => 200 },
|
173
|
-
:cpu => { :allocated => 10000 },
|
174
|
-
:memory => { :allocated => 20480 },
|
254
|
+
:storage => { :used => "105", :allocated => "200" },
|
255
|
+
:cpu => { :allocated => "10000" },
|
256
|
+
:memory => { :allocated => "20480" },
|
175
257
|
:networks => [
|
176
|
-
{ :
|
258
|
+
{ :id => "31",
|
259
|
+
:href => "#{base_url}/network/31",
|
177
260
|
:name => "1.2.3.0/24",
|
178
261
|
:subnet => "1.2.3.0/24",
|
179
262
|
:gateway => "1.2.3.1",
|
180
263
|
:netmask => "255.255.255.0",
|
181
264
|
:dns => "8.8.8.8",
|
182
265
|
:features => [
|
183
|
-
{ :type => :
|
266
|
+
{ :type => :FenceMode, :value => "isolated" }
|
184
267
|
],
|
185
268
|
:ips => { "1.2.3.3" => "Broom 1", "1.2.3.4" => "Broom 2", "1.2.3.10" => "Email" }
|
186
269
|
},
|
187
|
-
{ :
|
270
|
+
{ :id => "32",
|
271
|
+
:href => "#{base_url}/network/32",
|
188
272
|
:name => "4.5.6.0/24",
|
189
273
|
:subnet => "4.5.6.0/24",
|
190
274
|
:gateway => "4.5.6.1",
|
191
275
|
:netmask => "255.255.255.0",
|
192
276
|
:dns => "8.8.8.8",
|
193
277
|
:features => [
|
194
|
-
{ :type => :
|
278
|
+
{ :type => :FenceMode, :value => "isolated" }
|
195
279
|
],
|
196
280
|
:ips => { }
|
197
281
|
},
|
@@ -206,43 +290,24 @@ module Fog
|
|
206
290
|
{ :href => "#{base_url}/vap/43",
|
207
291
|
:name => "Email!"
|
208
292
|
}
|
209
|
-
],
|
210
|
-
:public_ips => [
|
211
|
-
{ :id => 51,
|
212
|
-
:name => "99.1.2.3",
|
213
|
-
:services => [
|
214
|
-
{ :id => 71, :port => 80, :protocol => 'HTTP', :enabled => true, :timeout => 2, :name => 'Web Site', :description => 'Web Servers' },
|
215
|
-
{ :id => 72, :port => 7000, :protocol => 'HTTP', :enabled => true, :timeout => 2, :name => 'An SSH Map', :description => 'SSH 1' }
|
216
|
-
]
|
217
|
-
},
|
218
|
-
{ :id => 52,
|
219
|
-
:name => "99.1.2.4",
|
220
|
-
:services => [
|
221
|
-
{ :id => 73, :port => 80, :protocol => 'HTTP', :enabled => true, :timeout => 2, :name => 'Web Site', :description => 'Web Servers' },
|
222
|
-
{ :id => 74, :port => 7000, :protocol => 'HTTP', :enabled => true, :timeout => 2, :name => 'An SSH Map', :description => 'SSH 2' }
|
223
|
-
]
|
224
|
-
},
|
225
|
-
{ :id => 53,
|
226
|
-
:name => "99.1.9.7",
|
227
|
-
:services => []
|
228
|
-
}
|
229
293
|
]
|
230
294
|
},
|
231
295
|
{ :href => "#{base_url}/vdc/22",
|
232
|
-
:id => 22,
|
233
|
-
:storage => { :used => 40, :allocated => 150 },
|
234
|
-
:cpu => { :allocated => 1000 },
|
235
|
-
:memory => { :allocated => 2048 },
|
296
|
+
:id => "22",
|
297
|
+
:storage => { :used => "40", :allocated => "150" },
|
298
|
+
:cpu => { :allocated => "1000" },
|
299
|
+
:memory => { :allocated => "2048" },
|
236
300
|
:name => "Rock-n-Roll",
|
237
301
|
:networks => [
|
238
|
-
{ :
|
302
|
+
{ :id => "33",
|
303
|
+
:href => "#{base_url}/network/33",
|
239
304
|
:name => "7.8.9.0/24",
|
240
305
|
:subnet => "7.8.9.0/24",
|
241
306
|
:gateway => "7.8.9.1",
|
242
307
|
:dns => "8.8.8.8",
|
243
308
|
:netmask => "255.255.255.0",
|
244
309
|
:features => [
|
245
|
-
{ :type => :
|
310
|
+
{ :type => :FenceMode, :value => "isolated" }
|
246
311
|
],
|
247
312
|
:ips => { "7.8.9.10" => "Master Blaster" }
|
248
313
|
}
|
@@ -251,12 +316,6 @@ module Fog
|
|
251
316
|
{ :href => "#{base_url}/vap/44",
|
252
317
|
:name => "Master Blaster"
|
253
318
|
}
|
254
|
-
],
|
255
|
-
:public_ips => [
|
256
|
-
{ :id => 54,
|
257
|
-
:name => "99.99.99.99",
|
258
|
-
:services => []
|
259
|
-
}
|
260
319
|
]
|
261
320
|
}
|
262
321
|
]
|
@@ -265,17 +324,17 @@ module Fog
|
|
265
324
|
}
|
266
325
|
end
|
267
326
|
|
268
|
-
def
|
327
|
+
def vdc_from_uri(uri)
|
269
328
|
match = Regexp.new(%r:.*/vdc/(\d+):).match(uri.to_s)
|
270
329
|
if match
|
271
|
-
|
330
|
+
mock_data[:organizations].map { |org| org[:vdcs] }.flatten.detect { |vdc| vdc[:id] == match[1] }
|
272
331
|
end
|
273
332
|
end
|
274
333
|
|
275
|
-
def
|
334
|
+
def ip_from_uri(uri)
|
276
335
|
match = Regexp.new(%r:.*/publicIp/(\d+):).match(uri.to_s)
|
277
336
|
if match
|
278
|
-
|
337
|
+
mock_data[:organizations].map { |org| org[:vdcs] }.flatten.map { |vdc| vdc[:public_ips] }.flatten.compact.detect { |public_ip| public_ip[:id] == match[1] }
|
279
338
|
end
|
280
339
|
end
|
281
340
|
|
@@ -290,16 +349,16 @@ module Fog
|
|
290
349
|
"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema" }
|
291
350
|
end
|
292
351
|
|
293
|
-
def mock_it(
|
352
|
+
def mock_it(status, mock_data, mock_headers = {})
|
294
353
|
response = Excon::Response.new
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
354
|
+
|
355
|
+
#Parse the response body into a hash
|
356
|
+
document = Fog::ToHashDocument.new
|
357
|
+
parser = Nokogiri::XML::SAX::PushParser.new(document)
|
358
|
+
parser << mock_data
|
359
|
+
parser.finish
|
360
|
+
response.body = document.body
|
361
|
+
|
303
362
|
response.status = status
|
304
363
|
response.headers = mock_headers
|
305
364
|
response
|
@@ -314,55 +373,5 @@ module Fog
|
|
314
373
|
end
|
315
374
|
|
316
375
|
end
|
317
|
-
|
318
|
-
class <<self
|
319
|
-
def new(credentials = {})
|
320
|
-
unless @required
|
321
|
-
require 'fog/vcloud/model'
|
322
|
-
require 'fog/vcloud/collection'
|
323
|
-
require 'fog/vcloud/parser'
|
324
|
-
require 'fog/vcloud/models/vdc'
|
325
|
-
require 'fog/vcloud/models/vdcs'
|
326
|
-
require 'fog/vcloud/terremark/vcloud'
|
327
|
-
require 'fog/vcloud/terremark/ecloud'
|
328
|
-
require 'fog/vcloud/requests/get_network'
|
329
|
-
require 'fog/vcloud/requests/get_organization'
|
330
|
-
require 'fog/vcloud/requests/get_vdc'
|
331
|
-
require 'fog/vcloud/requests/get_versions'
|
332
|
-
require 'fog/vcloud/requests/login'
|
333
|
-
require 'fog/vcloud/parsers/get_organization'
|
334
|
-
require 'fog/vcloud/parsers/get_vdc'
|
335
|
-
require 'fog/vcloud/parsers/get_versions'
|
336
|
-
require 'fog/vcloud/parsers/login'
|
337
|
-
require 'fog/vcloud/parsers/network'
|
338
|
-
|
339
|
-
require 'builder'
|
340
|
-
|
341
|
-
Struct.new("VcloudLink", :rel, :href, :type, :name)
|
342
|
-
Struct.new("VcloudVdc", :links, :resource_entities, :networks, :cpu_capacity, :storage_capacity, :memory_capacity, :href, :type, :name, :xmlns,
|
343
|
-
:allocation_model, :network_quota, :nic_quota, :vm_quota, :enabled, :description)
|
344
|
-
Struct.new("VcloudOrganization", :links, :name, :href, :type, :xmlns, :description)
|
345
|
-
Struct.new("VcloudVersion", :version, :login_url, :supported)
|
346
|
-
Struct.new("VcloudOrgList", :organizations, :xmlns)
|
347
|
-
Struct.new("VcloudXCapacity", :units, :allocated, :used, :limit)
|
348
|
-
Struct.new("VcloudNetwork", :features, :configuration, :href, :type, :name, :xmlns, :description)
|
349
|
-
Struct.new("VcloudNetworkConfiguration", :gateway, :netmask, :dns)
|
350
|
-
Struct.new("VcloudNetworkFenceMode", :mode)
|
351
|
-
@required = true
|
352
|
-
end
|
353
|
-
|
354
|
-
instance = if Fog.mocking?
|
355
|
-
Fog::Vcloud::Mock.new(credentials)
|
356
|
-
else
|
357
|
-
Fog::Vcloud::Real.new(credentials)
|
358
|
-
end
|
359
|
-
|
360
|
-
if mod = credentials[:module]
|
361
|
-
instance.extend eval("#{mod}")
|
362
|
-
end
|
363
|
-
|
364
|
-
instance
|
365
|
-
end
|
366
|
-
end
|
367
376
|
end
|
368
377
|
end
|