chef-provisioning-fog 0.26.1 → 0.26.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +29 -8
- data/Rakefile +23 -12
- data/chef-provisioning-fog.gemspec +24 -27
- data/lib/chef/provider/fog_key_pair.rb +49 -53
- data/lib/chef/provider/scaleway_volume.rb +46 -48
- data/lib/chef/provisioning/driver_init/fog.rb +1 -1
- data/lib/chef/provisioning/fog_driver/driver.rb +646 -653
- data/lib/chef/provisioning/fog_driver/providers/aws.rb +411 -422
- data/lib/chef/provisioning/fog_driver/providers/aws/credentials.rb +88 -90
- data/lib/chef/provisioning/fog_driver/providers/cloudstack.rb +32 -34
- data/lib/chef/provisioning/fog_driver/providers/digitalocean.rb +98 -100
- data/lib/chef/provisioning/fog_driver/providers/google.rb +27 -34
- data/lib/chef/provisioning/fog_driver/providers/joyent.rb +53 -55
- data/lib/chef/provisioning/fog_driver/providers/openstack.rb +139 -146
- data/lib/chef/provisioning/fog_driver/providers/rackspace.rb +40 -44
- data/lib/chef/provisioning/fog_driver/providers/scaleway.rb +183 -189
- data/lib/chef/provisioning/fog_driver/providers/softlayer.rb +61 -64
- data/lib/chef/provisioning/fog_driver/providers/vcair.rb +72 -78
- data/lib/chef/provisioning/fog_driver/providers/xenserver.rb +56 -69
- data/lib/chef/provisioning/fog_driver/recipe_dsl.rb +11 -12
- data/lib/chef/provisioning/fog_driver/version.rb +1 -1
- data/lib/chef/resource/fog_key_pair.rb +8 -8
- data/lib/chef/resource/scaleway_volume.rb +8 -8
- data/spec/spec_helper.rb +7 -7
- data/spec/support/chef/provisioning/fog_driver/providers/testdriver.rb +3 -3
- data/spec/unit/chef/provisioning/fog_driver/driver_spec.rb +39 -38
- data/spec/unit/fog_driver_spec.rb +6 -8
- data/spec/unit/providers/aws/credentials_spec.rb +10 -10
- data/spec/unit/providers/rackspace_spec.rb +5 -6
- data/spec/unit/providers/scaleway_spec.rb +9 -9
- data/spec/unit/providers/softlayer.rb +7 -7
- metadata +6 -36
- data/README.md +0 -357
@@ -1,11 +1,10 @@
|
|
1
|
-
#fog:XenServer:<XenServer IP>
|
1
|
+
# fog:XenServer:<XenServer IP>
|
2
2
|
class Chef
|
3
3
|
module Provisioning
|
4
4
|
module FogDriver
|
5
5
|
module Providers
|
6
6
|
class XenServer < FogDriver::Driver
|
7
|
-
|
8
|
-
Driver.register_provider_class('XenServer', FogDriver::Providers::XenServer)
|
7
|
+
Driver.register_provider_class("XenServer", FogDriver::Providers::XenServer)
|
9
8
|
|
10
9
|
def creator
|
11
10
|
compute_options[:xenserver_username]
|
@@ -13,15 +12,14 @@ class Chef
|
|
13
12
|
|
14
13
|
def bootstrap_options_for(machine_spec, machine_options)
|
15
14
|
bootstrap_options = super
|
16
|
-
bootstrap_options[:tags] = bootstrap_options[:tags].map {|k,v| "#{k}: #{v}" }
|
15
|
+
bootstrap_options[:tags] = bootstrap_options[:tags].map { |k, v| "#{k}: #{v}" }
|
17
16
|
bootstrap_options
|
18
17
|
end
|
19
18
|
|
20
|
-
def ssh_options_for(
|
21
|
-
{ auth_methods: [
|
19
|
+
def ssh_options_for(_machine_spec, machine_options, _server)
|
20
|
+
{ auth_methods: ["password"],
|
22
21
|
timeout: (machine_options[:ssh_timeout] || 600),
|
23
|
-
password: machine_options[:ssh_password]
|
24
|
-
}.merge(machine_options[:ssh_options] || {})
|
22
|
+
password: machine_options[:ssh_password] }.merge(machine_options[:ssh_options] || {})
|
25
23
|
end
|
26
24
|
|
27
25
|
def self.compute_options_for(provider, id, config)
|
@@ -29,12 +27,12 @@ class Chef
|
|
29
27
|
new_compute_options[:provider] = provider
|
30
28
|
new_config = { driver_options: { compute_options: new_compute_options } }
|
31
29
|
new_defaults = {
|
32
|
-
|
33
|
-
|
30
|
+
driver_options: { compute_options: {} },
|
31
|
+
machine_options: { bootstrap_options: { affinity: id } }
|
34
32
|
}
|
35
33
|
result = Cheffish::MergedConfig.new(new_config, config, new_defaults)
|
36
34
|
|
37
|
-
new_compute_options[:xenserver_url] = id if id && id !=
|
35
|
+
new_compute_options[:xenserver_url] = id if id && id != ""
|
38
36
|
credential = Fog.credentials
|
39
37
|
|
40
38
|
new_compute_options[:xenserver_username] ||= credential[:xenserver_username]
|
@@ -50,9 +48,7 @@ class Chef
|
|
50
48
|
|
51
49
|
def server_for(machine_spec)
|
52
50
|
if machine_spec.reference
|
53
|
-
compute.servers.get(compute.get_by_uuid(machine_spec.reference[
|
54
|
-
else
|
55
|
-
nil
|
51
|
+
compute.servers.get(compute.get_by_uuid(machine_spec.reference["server_id"], "VM"))
|
56
52
|
end
|
57
53
|
end
|
58
54
|
|
@@ -60,10 +56,10 @@ class Chef
|
|
60
56
|
result = {}
|
61
57
|
specs_and_options.each do |machine_spec, _machine_options|
|
62
58
|
if machine_spec.reference
|
63
|
-
if machine_spec.reference[
|
59
|
+
if machine_spec.reference["driver_url"] != driver_url
|
64
60
|
raise "Switching a machine's driver from #{machine_spec.reference['driver_url']} to #{driver_url} for is not currently supported! Use machine :destroy and then re-create the machine on the new driver."
|
65
61
|
end
|
66
|
-
result[machine_spec] = compute.servers.get(compute.get_by_uuid(machine_spec.reference[
|
62
|
+
result[machine_spec] = compute.servers.get(compute.get_by_uuid(machine_spec.reference["server_id"], "VM"))
|
67
63
|
else
|
68
64
|
result[machine_spec] = nil
|
69
65
|
end
|
@@ -72,29 +68,28 @@ class Chef
|
|
72
68
|
end
|
73
69
|
|
74
70
|
def create_many_servers(num_servers, bootstrap_options, parallelizer)
|
75
|
-
parallelizer.parallelize(1.upto(num_servers)) do |
|
71
|
+
parallelizer.parallelize(1.upto(num_servers)) do |_i|
|
76
72
|
compute.default_template = bootstrap_options[:template] if bootstrap_options[:template]
|
77
|
-
raise
|
73
|
+
raise "No server can be created without a template, please set a template name as bootstrap_options" unless compute.default_template
|
78
74
|
server = compute.default_template.clone bootstrap_options[:name]
|
79
75
|
|
80
76
|
if bootstrap_options[:affinity]
|
81
77
|
host = compute.hosts.all.select { |h| h.address == bootstrap_options[:affinity] }.first
|
82
|
-
|
78
|
+
unless host
|
83
79
|
raise "Host with ID #{bootstrap_options[:affinity]} not found."
|
84
80
|
end
|
85
81
|
server.affinity = host.reference
|
86
82
|
end
|
87
83
|
|
88
|
-
|
89
84
|
unless bootstrap_options[:memory].nil?
|
90
85
|
mem = (bootstrap_options[:memory].to_i * 1024 * 1024).to_s
|
91
|
-
server.set_attribute
|
86
|
+
server.set_attribute "memory_limits", mem, mem, mem, mem
|
92
87
|
end
|
93
88
|
|
94
89
|
unless bootstrap_options[:cpus].nil?
|
95
90
|
cpus = (bootstrap_options[:cpus]).to_s
|
96
|
-
server.set_attribute
|
97
|
-
server.set_attribute
|
91
|
+
server.set_attribute "VCPUs_max", cpus
|
92
|
+
server.set_attribute "VCPUs_at_startup", cpus
|
98
93
|
end
|
99
94
|
|
100
95
|
# network configuration through xenstore
|
@@ -103,33 +98,30 @@ class Chef
|
|
103
98
|
network = bootstrap_options[:network]
|
104
99
|
net_names = network[:vifs]
|
105
100
|
if net_names
|
106
|
-
server.vifs.each
|
101
|
+
server.vifs.each(&:destroy)
|
107
102
|
compute.networks.select { |net| Array(net_names).include? net.name }.each do |net|
|
108
103
|
compute.vifs.create vm: server, network: net, device: "0"
|
109
104
|
end
|
110
105
|
end
|
111
|
-
attrs[
|
112
|
-
attrs[
|
113
|
-
attrs[
|
114
|
-
attrs[
|
115
|
-
attrs[
|
116
|
-
|
117
|
-
server.set_attribute 'xenstore_data', attrs
|
118
|
-
end
|
106
|
+
attrs["vm-data/ip"] = network[:vm_ip] if network[:vm_ip]
|
107
|
+
attrs["vm-data/gw"] = network[:vm_gateway] if network[:vm_gateway]
|
108
|
+
attrs["vm-data/nm"] = network[:vm_netmask] if network[:vm_netmask]
|
109
|
+
attrs["vm-data/ns"] = network[:vm_dns] if network[:vm_dns]
|
110
|
+
attrs["vm-data/dm"] = network[:vm_domain] if network[:vm_domain]
|
111
|
+
server.set_attribute "xenstore_data", attrs unless attrs.empty?
|
119
112
|
end
|
120
113
|
|
121
114
|
userdevice = 1
|
122
|
-
(bootstrap_options[:additional_disks] ||
|
115
|
+
(bootstrap_options[:additional_disks] || {}).each do |name, data|
|
123
116
|
sr_name = data[:sr]
|
124
117
|
storage_repository = compute.storage_repositories.find { |sr| sr.name == sr_name }
|
125
|
-
raise
|
126
|
-
raise
|
118
|
+
raise "You must specify sr name to add additional disks" unless storage_repository
|
119
|
+
raise "You must specify size to add additional disk" unless data[:size]
|
127
120
|
|
128
121
|
gb = 1_073_741_824
|
129
122
|
size = data[:size].to_i * gb
|
130
123
|
|
131
|
-
|
132
|
-
vdi_params = { name: name}
|
124
|
+
vdi_params = { name: name }
|
133
125
|
vdi_params[:storage_repository] = storage_repository
|
134
126
|
vdi_params[:description] == data[:description] if data[:description]
|
135
127
|
vdi_params[:virtual_size] = size.to_s
|
@@ -137,7 +129,6 @@ class Chef
|
|
137
129
|
|
138
130
|
compute.vbds.create vm: server, vdi: vdi, userdevice: userdevice.to_s, bootable: false
|
139
131
|
userdevice += 1
|
140
|
-
|
141
132
|
end
|
142
133
|
|
143
134
|
server.provision
|
@@ -147,10 +138,10 @@ class Chef
|
|
147
138
|
end
|
148
139
|
|
149
140
|
def start_server(action_handler, machine_spec, server)
|
150
|
-
if server.state ==
|
141
|
+
if server.state == "Halted"
|
151
142
|
action_handler.perform_action "start machine #{machine_spec.name} (#{server.id} on #{driver_url})" do
|
152
143
|
server.start
|
153
|
-
machine_spec.reference[
|
144
|
+
machine_spec.reference["started_at"] = Time.now.to_i
|
154
145
|
end
|
155
146
|
machine_spec.save(action_handler)
|
156
147
|
end
|
@@ -165,9 +156,8 @@ class Chef
|
|
165
156
|
end
|
166
157
|
end
|
167
158
|
|
168
|
-
|
169
159
|
# Add methods required by the fog driver to XenServer's Server class
|
170
|
-
require
|
160
|
+
require "fog/compute/models/server"
|
171
161
|
module Fog
|
172
162
|
module Compute
|
173
163
|
class XenServer
|
@@ -182,15 +172,15 @@ module Fog
|
|
182
172
|
end
|
183
173
|
|
184
174
|
def public_ip_address
|
185
|
-
if xenstore_data[
|
186
|
-
xenstore_data[
|
175
|
+
if xenstore_data["vm-data/ip"]
|
176
|
+
xenstore_data["vm-data/ip"]
|
187
177
|
else
|
188
178
|
wait_for { tools_installed? }
|
189
179
|
if tools_installed?
|
190
180
|
guest_metrics.networks.first[1]
|
191
181
|
else
|
192
|
-
|
193
|
-
|
182
|
+
raise "Unable to return IP address. Virtual machine does not " \
|
183
|
+
"have XenTools installed or a timeout occurred."
|
194
184
|
end
|
195
185
|
end
|
196
186
|
end
|
@@ -213,36 +203,33 @@ end
|
|
213
203
|
module Fog
|
214
204
|
module XenServer
|
215
205
|
class Connection
|
216
|
-
require
|
206
|
+
require "xmlrpc/client"
|
217
207
|
attr_reader :credentials
|
218
208
|
|
219
209
|
def request(options, *params)
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
210
|
+
parser = options.delete(:parser)
|
211
|
+
method = options.delete(:method)
|
212
|
+
|
213
|
+
if params.empty?
|
214
|
+
response = @factory.call_async(method, @credentials)
|
215
|
+
else
|
216
|
+
if params.length.eql?(1) && params.first.is_a?(Hash)
|
217
|
+
response = @factory.call_async(method, @credentials, params.first)
|
218
|
+
elsif params.length.eql?(2) && params.last.is_a?(Array)
|
219
|
+
response = @factory.call_async(method, @credentials, params.first, params.last)
|
226
220
|
else
|
227
|
-
|
228
|
-
response = @factory.call_async(method, @credentials, params.first)
|
229
|
-
elsif params.length.eql?(2) and params.last.is_a?(Array)
|
230
|
-
response = @factory.call_async(method, @credentials, params.first, params.last)
|
231
|
-
else
|
232
|
-
response = eval("@factory.call_async('#{method}', '#{@credentials}', #{params.map { |p| p.is_a?(String) ? "'#{p}'" : p }.join(',')})")
|
233
|
-
end
|
221
|
+
response = eval("@factory.call_async('#{method}', '#{@credentials}', #{params.map { |p| p.is_a?(String) ? "'#{p}'" : p }.join(',')})")
|
234
222
|
end
|
235
|
-
raise RequestFailed.new("#{method}: " + response["ErrorDescription"].to_s) unless response["Status"].eql? "Success"
|
236
|
-
if parser
|
237
|
-
parser.parse(response["Value"])
|
238
|
-
response = parser.response
|
239
|
-
end
|
240
|
-
|
241
|
-
response
|
242
223
|
end
|
224
|
+
raise RequestFailed, "#{method}: " + response["ErrorDescription"].to_s unless response["Status"].eql? "Success"
|
225
|
+
if parser
|
226
|
+
parser.parse(response["Value"])
|
227
|
+
response = parser.response
|
228
|
+
end
|
229
|
+
|
230
|
+
response
|
243
231
|
end
|
244
232
|
end
|
245
|
-
|
246
233
|
end
|
247
234
|
end
|
248
235
|
|
@@ -250,7 +237,7 @@ module Fog
|
|
250
237
|
class Logger
|
251
238
|
def self.deprecation(message)
|
252
239
|
# Silence...ahh
|
253
|
-
Chef::Log.debug(
|
240
|
+
Chef::Log.debug("Fog: " + message)
|
254
241
|
end
|
255
242
|
end
|
256
243
|
end
|
@@ -1,38 +1,37 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "chef/provisioning/fog_driver/driver"
|
2
|
+
require "chef/resource/fog_key_pair"
|
3
|
+
require "chef/provider/fog_key_pair"
|
4
|
+
require "chef/resource/scaleway_volume"
|
5
|
+
require "chef/provider/scaleway_volume"
|
6
6
|
|
7
7
|
class Chef
|
8
8
|
module DSL
|
9
9
|
module Recipe
|
10
10
|
def with_fog_driver(provider, driver_options = nil, &block)
|
11
|
-
config = Cheffish::MergedConfig.new({ :
|
11
|
+
config = Cheffish::MergedConfig.new({ driver_options: driver_options }, run_context.config)
|
12
12
|
driver = Driver.from_provider(provider, config)
|
13
13
|
run_context.chef_provisioning.with_driver(driver, &block)
|
14
14
|
end
|
15
15
|
|
16
16
|
def with_fog_ec2_driver(driver_options = nil, &block)
|
17
|
-
with_fog_driver(
|
17
|
+
with_fog_driver("AWS", driver_options, &block)
|
18
18
|
end
|
19
19
|
|
20
20
|
def with_fog_openstack_driver(driver_options = nil, &block)
|
21
|
-
with_fog_driver(
|
21
|
+
with_fog_driver("OpenStack", driver_options, &block)
|
22
22
|
end
|
23
23
|
|
24
24
|
def with_fog_rackspace_driver(driver_options = nil, &block)
|
25
|
-
with_fog_driver(
|
25
|
+
with_fog_driver("Rackspace", driver_options, &block)
|
26
26
|
end
|
27
27
|
|
28
28
|
def with_fog_vcair_driver(driver_options = nil, &block)
|
29
|
-
with_fog_driver(
|
29
|
+
with_fog_driver("vcair", driver_options, &block)
|
30
30
|
end
|
31
31
|
|
32
32
|
def with_fog_scaleway_driver(driver_options = nil, &block)
|
33
|
-
with_fog_driver(
|
33
|
+
with_fog_driver("Scaleway", driver_options, &block)
|
34
34
|
end
|
35
|
-
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "chef/provisioning"
|
2
2
|
|
3
3
|
class Chef::Resource::FogKeyPair < Chef::Resource::LWRPBase
|
4
|
-
self.resource_name =
|
4
|
+
self.resource_name = "fog_key_pair"
|
5
5
|
|
6
6
|
def initialize(*args)
|
7
7
|
super
|
@@ -13,14 +13,14 @@ class Chef::Resource::FogKeyPair < Chef::Resource::LWRPBase
|
|
13
13
|
|
14
14
|
attribute :driver
|
15
15
|
# Private key to use as input (will be generated if it does not exist)
|
16
|
-
attribute :private_key_path, :
|
16
|
+
attribute :private_key_path, kind_of: String
|
17
17
|
# Public key to use as input (will be generated if it does not exist)
|
18
|
-
attribute :public_key_path, :
|
18
|
+
attribute :public_key_path, kind_of: String
|
19
19
|
# List of parameters to the private_key resource used for generation of the key
|
20
|
-
attribute :private_key_options, :
|
20
|
+
attribute :private_key_options, kind_of: Hash
|
21
21
|
|
22
|
-
# TODO what is the right default for this?
|
23
|
-
attribute :allow_overwrite, :
|
22
|
+
# TODO: what is the right default for this?
|
23
|
+
attribute :allow_overwrite, kind_of: [TrueClass, FalseClass], default: false
|
24
24
|
|
25
25
|
# Proc that runs after the resource completes. Called with (resource, private_key, public_key)
|
26
26
|
def after(&block)
|
@@ -28,7 +28,7 @@ class Chef::Resource::FogKeyPair < Chef::Resource::LWRPBase
|
|
28
28
|
end
|
29
29
|
|
30
30
|
# We are not interested in Chef's cloning behavior here.
|
31
|
-
def load_prior_resource(*
|
31
|
+
def load_prior_resource(*_args)
|
32
32
|
Chef::Log.debug("Overloading #{resource_name}.load_prior_resource with NOOP")
|
33
33
|
end
|
34
34
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "chef/provisioning"
|
2
2
|
|
3
3
|
class Chef::Resource::ScalewayVolume < Chef::Resource::LWRPBase
|
4
|
-
self.resource_name =
|
4
|
+
self.resource_name = "scaleway_volume"
|
5
5
|
|
6
6
|
def initialize(*args)
|
7
7
|
super
|
@@ -18,15 +18,15 @@ class Chef::Resource::ScalewayVolume < Chef::Resource::LWRPBase
|
|
18
18
|
attribute :volume_options
|
19
19
|
|
20
20
|
def add_volume_options(options)
|
21
|
-
if @volume_options
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
@volume_options = if @volume_options
|
22
|
+
Cheffish::MergedConfig.new(options, @volume_options)
|
23
|
+
else
|
24
|
+
options
|
25
|
+
end
|
26
26
|
end
|
27
27
|
|
28
28
|
# We are not interested in Chef's cloning behavior here.
|
29
|
-
def load_prior_resource(*
|
29
|
+
def load_prior_resource(*_args)
|
30
30
|
Chef::Log.debug("Overloading #{resource_name}.load_prior_resource with NOOP")
|
31
31
|
end
|
32
32
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift File.expand_path("support", __dir__)
|
3
|
+
require "fog"
|
4
|
+
require "chef/provisioning"
|
5
|
+
require "chef/provisioning/fog_driver/driver"
|
6
|
+
require "simplecov"
|
7
7
|
|
8
8
|
SimpleCov.start do
|
9
9
|
# add_filter do |source_file|
|
@@ -20,7 +20,7 @@ RSpec.configure do |config|
|
|
20
20
|
# order dependency and want to debug it, you can fix the order by providing
|
21
21
|
# the seed, which is printed after each run.
|
22
22
|
# --seed 1234
|
23
|
-
config.order =
|
23
|
+
config.order = "random"
|
24
24
|
end
|
25
25
|
|
26
26
|
Fog.mock!
|
@@ -3,15 +3,15 @@ class Chef
|
|
3
3
|
module FogDriver
|
4
4
|
module Providers
|
5
5
|
class TestDriver < FogDriver::Driver
|
6
|
-
Driver.register_provider_class(
|
6
|
+
Driver.register_provider_class("TestDriver", Chef::Provisioning::FogDriver::Providers::TestDriver)
|
7
7
|
|
8
8
|
attr_reader :config
|
9
9
|
def initialize(driver_url, config)
|
10
10
|
super
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.compute_options_for(
|
14
|
-
[config,
|
13
|
+
def self.compute_options_for(_provider, _id, config)
|
14
|
+
[config, "test"]
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "chef/provisioning/fog_driver/driver"
|
2
2
|
|
3
3
|
describe Chef::Provisioning::FogDriver::Driver do
|
4
4
|
let(:driver) { Chef::Provisioning::FogDriver::Driver.new("fog:OpenStack", {}) }
|
@@ -8,102 +8,103 @@ describe Chef::Provisioning::FogDriver::Driver do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "#determine_remote_host" do
|
11
|
-
let(:machine_spec) { double("machine_spec", :
|
12
|
-
let(:server) { double("server", :
|
11
|
+
let(:machine_spec) { double("machine_spec", reference: reference, name: "name") }
|
12
|
+
let(:server) { double("server", private_ip_address: "private", public_ip_address: "public", ip_addresses: ["first_ip_address"]) }
|
13
13
|
|
14
14
|
context "when 'use_private_ip_for_ssh' is specified in the machine_spec.reference" do
|
15
|
-
let(:reference) { {
|
15
|
+
let(:reference) { { "use_private_ip_for_ssh" => true } }
|
16
16
|
it "returns the private ip" do
|
17
|
-
expect(driver.determine_remote_host(machine_spec, server)).to eq(
|
18
|
-
expect(reference).to eq(
|
17
|
+
expect(driver.determine_remote_host(machine_spec, server)).to eq("private")
|
18
|
+
expect(reference).to eq("transport_address_location" => :private_ip)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
context "when 'transport_address_location' is set to :private_ip" do
|
23
|
-
let(:reference) { {
|
23
|
+
let(:reference) { { "transport_address_location" => :private_ip } }
|
24
24
|
it "returns the private ip" do
|
25
|
-
expect(driver.determine_remote_host(machine_spec, server)).to eq(
|
25
|
+
expect(driver.determine_remote_host(machine_spec, server)).to eq("private")
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
context "when 'transport_address_location' is set to :ip_addresses" do
|
30
|
-
let(:reference) { {
|
30
|
+
let(:reference) { { "transport_address_location" => :ip_addresses } }
|
31
31
|
it "returns the first ip_address from array" do
|
32
|
-
expect(driver.determine_remote_host(machine_spec, server)).to eq(
|
32
|
+
expect(driver.determine_remote_host(machine_spec, server)).to eq("first_ip_address")
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
context "when 'transport_address_location' is set to :public_ip" do
|
37
|
-
let(:reference) { {
|
37
|
+
let(:reference) { { "transport_address_location" => :public_ip } }
|
38
38
|
it "returns the public ip" do
|
39
|
-
expect(driver.determine_remote_host(machine_spec, server)).to eq(
|
39
|
+
expect(driver.determine_remote_host(machine_spec, server)).to eq("public")
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
context "when machine_spec.reference does not specify the transport type" do
|
44
|
-
let(:reference) {
|
44
|
+
let(:reference) { {} }
|
45
45
|
|
46
46
|
context "when the machine does not have a public_ip_address" do
|
47
|
-
let(:server) { double("server", :
|
47
|
+
let(:server) { double("server", private_ip_address: "private", public_ip_address: nil, ip_addresses: ["first_ip_address"]) }
|
48
48
|
|
49
49
|
it "returns the private ip" do
|
50
|
-
expect(driver.determine_remote_host(machine_spec, server)).to eq(
|
50
|
+
expect(driver.determine_remote_host(machine_spec, server)).to eq("private")
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
context "when the machine has a public_ip_address" do
|
55
|
-
let(:server) { double("server", :
|
55
|
+
let(:server) { double("server", private_ip_address: "private", public_ip_address: "public", ip_addresses: ["first_ip_address"]) }
|
56
56
|
|
57
57
|
it "returns the public ip" do
|
58
|
-
expect(driver.determine_remote_host(machine_spec, server)).to eq(
|
58
|
+
expect(driver.determine_remote_host(machine_spec, server)).to eq("public")
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
context "when the machine does not have a public_ip_address or private_ip_address" do
|
63
|
-
let(:server) { double("server", :
|
63
|
+
let(:server) { double("server", private_ip_address: nil, public_ip_address: nil, ip_addresses: ["first_ip_address"], id: "id") }
|
64
64
|
|
65
65
|
it "raises an error" do
|
66
|
-
expect {driver.determine_remote_host(machine_spec, server)}.to raise_error("Server #{server.id} has no private or public IP address!")
|
66
|
+
expect { driver.determine_remote_host(machine_spec, server) }.to raise_error("Server #{server.id} has no private or public IP address!")
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
describe
|
73
|
-
let(:machine_spec) { double(
|
74
|
-
let(:machine_options) { { bootstrap_options:
|
72
|
+
describe "#private_key_for" do
|
73
|
+
let(:machine_spec) { double("machine_spec", reference: {}, name: "my_machine") }
|
74
|
+
let(:machine_options) { { bootstrap_options: bootstrap_options } }
|
75
75
|
|
76
|
-
context
|
77
|
-
let(:bootstrap_options) { { key_path:
|
76
|
+
context "when the machine has a key path in bootstrap options" do
|
77
|
+
let(:bootstrap_options) { { key_path: "/tmp/test_private_key_file" } }
|
78
78
|
|
79
|
-
it
|
80
|
-
allow(IO).to receive(:read).and_return
|
81
|
-
expect(driver.private_key_for(machine_spec, machine_options, nil)).to eq
|
79
|
+
it "reads the key file" do
|
80
|
+
allow(IO).to receive(:read).and_return "test_private_key"
|
81
|
+
expect(driver.private_key_for(machine_spec, machine_options, nil)).to eq "test_private_key"
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
context
|
86
|
-
let(:bootstrap_options) { { key_name:
|
85
|
+
context "when the machine has a key name in bootstrap options" do
|
86
|
+
let(:bootstrap_options) { { key_name: "test_private_key_name" } }
|
87
87
|
|
88
|
-
it
|
89
|
-
expect(driver).to receive(:get_private_key).with(
|
90
|
-
expect(driver.private_key_for(machine_spec, machine_options, nil)).to eq
|
88
|
+
it "calls get_private_key" do
|
89
|
+
expect(driver).to receive(:get_private_key).with("test_private_key_name").and_return "test_private_key"
|
90
|
+
expect(driver.private_key_for(machine_spec, machine_options, nil)).to eq "test_private_key"
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
context
|
95
|
-
it
|
94
|
+
context "when the machine has no bootstrap options" do
|
95
|
+
it "raises an error" do
|
96
96
|
expect { driver.private_key_for(machine_spec, {}, nil) }
|
97
|
-
.to raise_error(RuntimeError,
|
97
|
+
.to raise_error(RuntimeError, "No key found to connect to my_machine ({}) : machine_options -> ({})!")
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
context
|
101
|
+
context "when the machine has no key path or key name bootstrap options" do
|
102
102
|
let(:bootstrap_options) { {} }
|
103
103
|
|
104
|
-
it
|
104
|
+
it "raises an error" do
|
105
105
|
expect { driver.private_key_for(machine_spec, machine_options, nil) }.to raise_error(
|
106
|
-
RuntimeError,
|
106
|
+
RuntimeError, "No key found to connect to my_machine ({}) : machine_options -> ({:bootstrap_options=>{}})!"
|
107
|
+
)
|
107
108
|
end
|
108
109
|
end
|
109
110
|
end
|