chef-provisioning-opennebula 0.4.4 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +273 -4
- data/lib/chef/provider/one_flow_service.rb +346 -0
- data/lib/chef/provider/one_flow_template.rb +175 -0
- data/lib/chef/provider/one_image.rb +6 -6
- data/lib/chef/provider/one_template.rb +4 -6
- data/lib/chef/provider/one_user.rb +11 -14
- data/lib/chef/provider/one_vnet.rb +6 -9
- data/lib/chef/provider/one_vnet_lease.rb +3 -3
- data/lib/chef/provisioning/driver_init/opennebula.rb +1 -1
- data/lib/chef/provisioning/driver_init/server_version.rb +28 -0
- data/lib/chef/provisioning/opennebula_driver.rb +1 -1
- data/lib/chef/provisioning/opennebula_driver/credentials.rb +2 -2
- data/lib/chef/provisioning/opennebula_driver/driver.rb +132 -34
- data/lib/chef/provisioning/opennebula_driver/flow_lib.rb +491 -0
- data/lib/chef/provisioning/opennebula_driver/one_lib.rb +39 -49
- data/lib/chef/provisioning/opennebula_driver/resources.rb +2 -2
- data/lib/chef/provisioning/opennebula_driver/version.rb +2 -2
- data/lib/chef/resource/one_flow_service.rb +61 -0
- data/lib/chef/resource/one_flow_template.rb +53 -0
- data/lib/chef/resource/one_image.rb +2 -2
- data/lib/chef/resource/one_template.rb +1 -1
- data/lib/chef/resource/one_user.rb +1 -1
- data/lib/chef/resource/one_vnet.rb +2 -2
- data/lib/chef/resource/one_vnet_lease.rb +1 -1
- data/spec/config_sample.rb +12 -3
- data/spec/integration/test_all_integration_spec.rb +6 -272
- data/spec/integration/test_one_driver.rb +177 -0
- data/spec/integration/test_one_flow.rb +546 -0
- data/spec/recipes/OneDriver/{instantiate_one_template_spec.rb → allocate_change_profile.rb} +5 -7
- data/spec/recipes/OneDriver/{converge_back_two_vm_spec.rb → attach_one_image.rb} +4 -5
- data/spec/recipes/OneDriver/create_one_image.rb +20 -0
- data/spec/recipes/OneDriver/{create_one_template_int_spec.rb → create_one_template_ints.rb} +21 -4
- data/spec/recipes/OneDriver/create_one_template_mix.rb +51 -0
- data/spec/recipes/OneDriver/{create_one_image_spec.rb → create_one_template_strings.rb} +18 -7
- data/spec/recipes/OneDriver/{converge_back_one_vm_spec.rb → create_one_vnet.rb} +5 -5
- data/spec/recipes/OneDriver/delete/{OpenNebula-tpl-1-vm.rb → OpenNebula-test-img.rb} +2 -4
- data/spec/recipes/OneDriver/delete/{OpenNebula-back-1-vm.rb → OpenNebula-test-snap-img.rb} +2 -4
- data/spec/recipes/OneDriver/delete/OpenNebula-test-tpl-ints.rb +2 -4
- data/spec/recipes/OneDriver/delete/{OpenNebula-test-tpl.rb → OpenNebula-test-tpl-mix.rb} +2 -4
- data/spec/recipes/OneDriver/delete/OpenNebula-test-tpl-strings.rb +17 -0
- data/spec/recipes/OneDriver/delete/{OpenNebula-back-2-vm.rb → OpenNebula-test-vm-vnet.rb} +2 -4
- data/spec/recipes/OneDriver/delete/{OpenNebula-bootstrap-vm.rb → OpenNebula-test-vm.rb} +2 -4
- data/spec/recipes/OneDriver/delete/OpenNebula-test-vnet.rb +17 -0
- data/spec/recipes/OneDriver/{attach_back_one_vm_spec.rb → instantiate_one_template.rb} +7 -6
- data/spec/recipes/OneDriver/{converge_bootstrap_vm_spec.rb → instantiate_one_template_vnet.rb} +10 -8
- data/spec/recipes/OneDriver/snapshot_one_image.rb +19 -0
- data/spec/recipes/OneFlowService/action/boot.rb +19 -0
- data/spec/recipes/OneFlowService/action/delete.rb +18 -0
- data/spec/recipes/OneFlowService/action/delete_recreate.rb +18 -0
- data/spec/recipes/OneFlowService/action/hold.rb +19 -0
- data/spec/recipes/OneFlowService/action/poweroff.rb +18 -0
- data/spec/recipes/OneFlowService/action/poweroff_hard.rb +18 -0
- data/spec/recipes/OneFlowService/action/reboot.rb +18 -0
- data/spec/recipes/OneFlowService/action/reboot_hard.rb +18 -0
- data/spec/recipes/OneFlowService/action/release.rb +19 -0
- data/spec/recipes/OneFlowService/action/resume.rb +18 -0
- data/spec/recipes/OneFlowService/action/scale.rb +19 -0
- data/spec/recipes/OneFlowService/action/shutdown.rb +18 -0
- data/spec/recipes/OneFlowService/action/shutdown_hard.rb +18 -0
- data/spec/recipes/OneFlowService/action/shutdown_service.rb +17 -0
- data/spec/recipes/OneFlowService/action/snapshot_create.rb +18 -0
- data/spec/recipes/OneFlowService/action/stop.rb +18 -0
- data/spec/recipes/OneFlowService/action/suspend.rb +18 -0
- data/spec/recipes/OneFlowService/action/undeploy.rb +18 -0
- data/spec/recipes/OneFlowService/action/undeploy_hard.rb +18 -0
- data/spec/recipes/OneFlowService/chmod_simple_by_name.rb +19 -0
- data/spec/recipes/OneFlowService/chmod_simple_by_name_2.rb +18 -0
- data/spec/recipes/OneFlowService/chmod_tpl_opts.rb +31 -0
- data/spec/recipes/OneFlowService/delete/test_instance_template_options.rb +17 -0
- data/spec/recipes/OneFlowService/delete/test_role_action.rb +17 -0
- data/spec/recipes/OneFlowService/delete/test_simple_instance.rb +17 -0
- data/spec/recipes/OneFlowService/delete/test_simple_instance_by_id.rb +17 -0
- data/spec/recipes/{OneDriver/create_bootstrap_vm_spec.rb → OneFlowService/instance_role_action.rb} +19 -11
- data/spec/recipes/OneFlowService/instance_simple_by_id.rb +20 -0
- data/spec/recipes/OneFlowService/instance_simple_by_name.rb +18 -0
- data/spec/recipes/OneFlowService/instance_tpl_opts.rb +30 -0
- data/spec/recipes/OneFlowTemplate/chmod_simple_from_hash.rb +17 -0
- data/spec/recipes/OneFlowTemplate/chmod_update_simple_from_file.rb +19 -0
- data/spec/recipes/OneFlowTemplate/create_branch_from_one_id.rb +43 -0
- data/spec/recipes/OneFlowTemplate/create_branch_from_one_name.rb +20 -0
- data/spec/recipes/OneFlowTemplate/create_role_action_instance.rb +99 -0
- data/spec/recipes/OneFlowTemplate/create_simple_from_file.rb +18 -0
- data/spec/recipes/{OneDriver/attach_back_two_vm_spec.rb → OneFlowTemplate/create_simple_from_hash.rb} +8 -6
- data/spec/recipes/OneFlowTemplate/create_simple_from_web.rb +17 -0
- data/spec/recipes/{OneDriver/attach_one_image_spec.rb → OneFlowTemplate/create_simple_instance_tpl.rb} +8 -6
- data/spec/recipes/OneFlowTemplate/create_tpl_opts_from_file.rb +30 -0
- data/spec/recipes/OneFlowTemplate/create_tpl_opts_from_hash.rb +35 -0
- data/spec/recipes/OneFlowTemplate/delete/branch_from_one_id.rb +17 -0
- data/spec/recipes/OneFlowTemplate/delete/branch_from_one_name.rb +17 -0
- data/spec/recipes/OneFlowTemplate/delete/role_action_instance.rb +17 -0
- data/spec/recipes/OneFlowTemplate/delete/simple_from_file.rb +17 -0
- data/spec/recipes/OneFlowTemplate/delete/simple_from_hash.rb +17 -0
- data/spec/recipes/OneFlowTemplate/delete/simple_from_web.rb +17 -0
- data/spec/recipes/OneFlowTemplate/delete/simple_instance_tpl.rb +17 -0
- data/spec/recipes/OneFlowTemplate/delete/tpl_opts_from_file.rb +17 -0
- data/spec/recipes/OneFlowTemplate/delete/tpl_opts_from_hash.rb +17 -0
- data/spec/recipes/OneFlowTemplate/update_simple_from_hash.rb +57 -0
- data/spec/recipes/{driver_options_spec.rb → common.rb} +9 -3
- data/spec/spec_helper.rb +22 -17
- data/spec/support/opennebula_support.rb +75 -45
- metadata +114 -27
- data/spec/recipes/OneDriver/create_back_one_vm_spec.rb +0 -20
- data/spec/recipes/OneDriver/create_back_two_vm_spec.rb +0 -20
- data/spec/recipes/OneDriver/create_one_template_spec.rb +0 -21
- data/spec/recipes/OneDriver/delete/OpenNebula-bootstrap-img.rb +0 -19
- data/spec/recipes/OneDriver/delete/OpenNebula-snap-1-img.rb +0 -19
- data/spec/recipes/OneDriver/delete/OpenNebula-snap-2-img.rb +0 -19
- data/spec/recipes/OneDriver/snapshot_one_image_spec.rb +0 -21
- data/spec/recipes/OneDriver/snapshot_two_image_spec.rb +0 -21
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2016, BlackBerry Limited
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -12,10 +12,6 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require 'opennebula'
|
16
|
-
|
17
|
-
require 'opennebula/document'
|
18
|
-
|
19
15
|
#
|
20
16
|
# Sample Document definition.
|
21
17
|
#
|
@@ -50,30 +46,14 @@ class Chef
|
|
50
46
|
# Implementation.
|
51
47
|
#
|
52
48
|
class OneLib
|
53
|
-
|
49
|
+
attr_reader :client, :version_ge_4_14
|
54
50
|
|
55
51
|
def initialize(args)
|
56
|
-
|
57
|
-
endpoint = args[:endpoint]
|
58
|
-
options = args[:options] || {}
|
59
|
-
if args[:driver_url]
|
60
|
-
scan = args[:driver_url].match(%r/(opennebula):(https?:\/\/[^:\/]+ (?::[0-9]{2,5})? (?:\/[^:\s]+) ) :?([^:\s]+)?/x)
|
61
|
-
endpoint = scan[2]
|
62
|
-
profile = scan[3]
|
63
|
-
fail "'driver_url' option has invalid format: #{args[:driver_url]}" if endpoint.nil? || profile.nil?
|
64
|
-
one_profile = Chef::Provisioning::OpenNebulaDriver::Credentials.new[profile]
|
65
|
-
credentials = one_profile[:credentials]
|
66
|
-
options = one_profile[:options] || {}
|
67
|
-
end
|
68
|
-
@client = OpenNebula::Client.new(credentials, endpoint, options)
|
52
|
+
@client = OpenNebula::Client.new(args[:credentials], args[:endpoint], args[:options])
|
69
53
|
rc = @client.get_version
|
70
54
|
raise OpenNebulaException, rc.message if OpenNebula.is_error?(rc)
|
71
|
-
|
72
|
-
server_version = rc.split('.').map(&:to_i)
|
73
|
-
gem_version = Gem.loaded_specs["opennebula"].version.to_s.split('.').map(&:to_i)
|
55
|
+
gem_version = Gem.loaded_specs['opennebula'].version.to_s.split('.').map(&:to_i)
|
74
56
|
@version_ge_4_14 = gem_version[0] > 4 || (gem_version[0] == 4 && gem_version[1] >= 14)
|
75
|
-
|
76
|
-
version_mismatch_warning(server_version, gem_version) if server_version != gem_version
|
77
57
|
end
|
78
58
|
|
79
59
|
# This function provides a more readable way to return a
|
@@ -172,7 +152,7 @@ class Chef
|
|
172
152
|
next if filter[:uname] && res.to_hash[hash_key]['UNAME'] != filter[:uname]
|
173
153
|
resources << res
|
174
154
|
end
|
175
|
-
return nil if resources.
|
155
|
+
return nil if resources.empty?
|
176
156
|
return resources[0] if resources.size == 1
|
177
157
|
resources
|
178
158
|
end
|
@@ -191,15 +171,38 @@ class Chef
|
|
191
171
|
end_state ||= 'RUNNING'
|
192
172
|
vm = get_resource(:virtualmachine, :id => id)
|
193
173
|
fail "Did not find VM with ID: #{id}" unless vm
|
194
|
-
|
174
|
+
|
175
|
+
# Wait up to 10 min for the VM to be ready
|
176
|
+
rc = retryable_operation("wait for VM #{id} to be ready", 600, 2) do
|
195
177
|
vm.info
|
196
|
-
|
197
|
-
|
198
|
-
|
178
|
+
if vm.lcm_state_str != 'LCM_INIT'
|
179
|
+
short_lcm = OpenNebula::VirtualMachine::SHORT_LCM_STATES[vm.lcm_state_str]
|
180
|
+
fail "'#{vm.name}'' failed. Current state: #{vm.lcm_state_str}" if short_lcm == 'fail'
|
181
|
+
end
|
182
|
+
fail "'#{vm.name}'' failed. Current state: #{vm.state_str}" if vm.state_str == 'FAILED'
|
183
|
+
Chef::Log.info("current state: '#{vm.lcm_state_str}' short: '#{short_lcm}'")
|
184
|
+
OpenNebula::Error.new("Waiting") unless vm.lcm_state_str.casecmp(end_state) == 0
|
199
185
|
end
|
186
|
+
fail "wait_for_vm timed out: '#{id}'" if rc.nil?
|
200
187
|
vm
|
201
188
|
end
|
202
189
|
|
190
|
+
# Retry an OpenNebula operation until the timeout expires. Will always try at least once.
|
191
|
+
def retryable_operation(msg = "operation", timeout = 15, delay = 2)
|
192
|
+
return nil unless block_given?
|
193
|
+
start = Time.now
|
194
|
+
rc = nil
|
195
|
+
loop do
|
196
|
+
rc = yield
|
197
|
+
return true unless OpenNebula.is_error?(rc)
|
198
|
+
Chef::Log.info(msg)
|
199
|
+
sleep delay
|
200
|
+
break if (Time.now - start) > timeout
|
201
|
+
end
|
202
|
+
Chef::Log.info("Timed out waiting for OpenNebula operation. Got error #{rc.message} from OpenNebula.")
|
203
|
+
nil
|
204
|
+
end
|
205
|
+
|
203
206
|
def rename_vm(res, name)
|
204
207
|
rc = res.rename(name)
|
205
208
|
raise OpenNebulaException, rc.message if OpenNebula.is_error?(rc)
|
@@ -265,7 +268,8 @@ DEV_PREFIX = #{img_config[:prefix]}
|
|
265
268
|
image = nil
|
266
269
|
state = 'INIT'
|
267
270
|
pool = get_pool(:image)
|
268
|
-
|
271
|
+
|
272
|
+
retryable_operation("wait for IMAGE #{img_id} to be ready", 600, 2) do
|
269
273
|
pool.info!(-2, img_id, img_id)
|
270
274
|
pool.each do |img|
|
271
275
|
next unless img.id == img_id
|
@@ -275,7 +279,7 @@ DEV_PREFIX = #{img_config[:prefix]}
|
|
275
279
|
state = cur_state
|
276
280
|
break
|
277
281
|
end
|
278
|
-
|
282
|
+
OpenNebula::Error.new("Waiting") if state == 'INIT' || state == 'LOCKED'
|
279
283
|
end
|
280
284
|
fail "Failed to create #{name} image. State = '#{state}'" if state != 'READY'
|
281
285
|
Chef::Log.info("Image #{name} is in READY state")
|
@@ -384,7 +388,7 @@ DEV_PREFIX = #{img_config[:prefix]}
|
|
384
388
|
t_hash = nil
|
385
389
|
doc = OpenNebula::CustomObject.new(OpenNebula::CustomObject.build_xml, @client)
|
386
390
|
unless OpenNebula.is_error?(doc)
|
387
|
-
rc = doc.allocate(
|
391
|
+
rc = doc.allocate(File.read(options[:template_file]).to_s)
|
388
392
|
fail "Failed to allocate OpenNebula document: #{rc.message}" if OpenNebula.is_error?(rc)
|
389
393
|
doc.info!
|
390
394
|
t_hash = doc.to_hash['DOCUMENT']['TEMPLATE']
|
@@ -399,7 +403,7 @@ DEV_PREFIX = #{img_config[:prefix]}
|
|
399
403
|
|
400
404
|
#
|
401
405
|
# This method will create a VM template from parameters provided
|
402
|
-
# in the 't' Hash.
|
406
|
+
# in the 't' Hash. The hash must have equivalent structure as the
|
403
407
|
# VM template.
|
404
408
|
#
|
405
409
|
# We considered using OpenNebulaHelper::create_template for this,
|
@@ -470,28 +474,14 @@ DEV_PREFIX = #{img_config[:prefix]}
|
|
470
474
|
else
|
471
475
|
comma = (index < count) && level > 0
|
472
476
|
level.times { tpl << " " }
|
473
|
-
|
474
|
-
|
475
|
-
elsif v.is_a?(String)
|
476
|
-
# Fix for: template does not support embedded quotation marks
|
477
|
-
# Escaping of " only happens if " is not already escaped, preceded by \\
|
478
|
-
tpl << "#{k} = \"#{v.gsub(/(?<!\\)\"/, '\"')}\""
|
479
|
-
else # any other type
|
480
|
-
# convert to string and print it
|
481
|
-
tpl << "#{k} = \"#{v}\""
|
482
|
-
end
|
477
|
+
txt = v.is_a?(String) ? "#{k} = \"#{v.gsub(/(?<!\\)\"/, '\"')}\"" : "#{k} = \"#{v}\""
|
478
|
+
tpl << txt
|
483
479
|
tpl << (comma ? ",\n" : "\n")
|
484
480
|
index += 1
|
485
481
|
end
|
486
482
|
end
|
487
483
|
tpl
|
488
484
|
end
|
489
|
-
|
490
|
-
def version_mismatch_warning(server, gem)
|
491
|
-
Chef::Log.warn('GEM / SERVER VERSION MISMATCH')
|
492
|
-
Chef::Log.warn("Your gem version is #{gem.join('.')} and the server version is #{server.join('.')}")
|
493
|
-
Chef::Log.warn('Users may experience issues with this gem.')
|
494
|
-
end
|
495
485
|
end
|
496
486
|
end
|
497
487
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2016, BlackBerry Limited
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -12,7 +12,7 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
resources = %w( image template vnet vnet_lease user )
|
15
|
+
resources = %w( image template vnet vnet_lease user flow_template flow_service )
|
16
16
|
|
17
17
|
resources.each do |r|
|
18
18
|
Chef::Log.debug "OpenNebula driver loading resource: one_#{r}"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2016, BlackBerry Limited
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -24,7 +24,7 @@ class Chef
|
|
24
24
|
# Extending module.
|
25
25
|
#
|
26
26
|
module OpenNebulaDriver
|
27
|
-
VERSION = '0.4.
|
27
|
+
VERSION = '0.4.6'.freeze
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Copyright 2016, BlackBerry Limited
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'chef/provider/one_flow_service'
|
16
|
+
|
17
|
+
#
|
18
|
+
# Implementation of Resource class.
|
19
|
+
#
|
20
|
+
class Chef
|
21
|
+
#
|
22
|
+
# Implementation of Resource class.
|
23
|
+
#
|
24
|
+
class Resource
|
25
|
+
#
|
26
|
+
# Implementation of Resource class.
|
27
|
+
#
|
28
|
+
class OneFlowService < Chef::Resource::LWRPBase
|
29
|
+
resource_name :one_flow_service
|
30
|
+
|
31
|
+
attribute :name, :kind_of => String, :name_attribute => true
|
32
|
+
attribute :template, :kind_of => [Fixnum, String], :default => nil
|
33
|
+
attribute :template_options, :kind_of => Hash, :default => {}
|
34
|
+
attribute :mode, :regex => [/^[0-7]{3}$/], :default => '600'
|
35
|
+
attribute :role, :regex => [/^\w+$/], :default => nil
|
36
|
+
attribute :cardinality, :kind_of => Fixnum, :default => -1
|
37
|
+
attribute :period, :kind_of => Fixnum, :default => nil
|
38
|
+
attribute :number, :kind_of => Fixnum, :default => nil
|
39
|
+
attribute :force_scale, :kind_of => [TrueClass, FalseClass], :default => false
|
40
|
+
attribute :override_failsafe, :kind_of => [TrueClass, FalseClass], :default => false
|
41
|
+
|
42
|
+
attribute :driver
|
43
|
+
attribute :flow_url
|
44
|
+
|
45
|
+
attr_accessor :exists, :equal, :template_equal, :mode_equal, :in_running_state
|
46
|
+
|
47
|
+
actions :instantiate, :recover, :delete, :shutdown, :scale,
|
48
|
+
:shutdown_hard, :undeploy, :undeploy_hard, :hold,
|
49
|
+
:release, :stop, :suspend, :resume, :boot,
|
50
|
+
:delete_recreate, :reboot, :reboot_hard, :poweroff,
|
51
|
+
:poweroff_hard, :snapshot_create
|
52
|
+
|
53
|
+
default_action :instantiate
|
54
|
+
|
55
|
+
def initialize(*args)
|
56
|
+
super
|
57
|
+
@driver = run_context.chef_provisioning.current_driver
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Copyright 2016, BlackBerry Limited
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'chef/provider/one_flow_template'
|
16
|
+
|
17
|
+
#
|
18
|
+
# Implementation of Resource class.
|
19
|
+
#
|
20
|
+
class Chef
|
21
|
+
#
|
22
|
+
# Implementation of Resource class.
|
23
|
+
#
|
24
|
+
class Resource
|
25
|
+
#
|
26
|
+
# Implementation of Resource class.
|
27
|
+
#
|
28
|
+
class OneFlowTemplate < Chef::Resource::LWRPBase
|
29
|
+
resource_name :one_flow_template
|
30
|
+
|
31
|
+
attribute :name, :kind_of => String, :name_attribute => true
|
32
|
+
|
33
|
+
attribute :template, :kind_of => [Hash, String, Fixnum], :default => nil
|
34
|
+
attribute :template_options, :kind_of => Hash, :default => {}
|
35
|
+
|
36
|
+
attribute :service_name, :kind_of => String, :default => nil
|
37
|
+
attribute :mode, :regex => [/^[0-7]{3}$/], :default => '600'
|
38
|
+
|
39
|
+
attribute :driver
|
40
|
+
attribute :flow_url
|
41
|
+
|
42
|
+
attr_accessor :exists, :equal, :template_equal, :mode_equal
|
43
|
+
|
44
|
+
actions :create, :delete
|
45
|
+
default_action :create
|
46
|
+
|
47
|
+
def initialize(*args)
|
48
|
+
super
|
49
|
+
@driver = run_context.chef_provisioning.current_driver
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2016, BlackBerry Limited
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -42,7 +42,7 @@ class Chef
|
|
42
42
|
attribute :prefix, :kind_of => String, :equal_to => %w(vd xvd sd hd)
|
43
43
|
attribute :persistent, :kind_of => [TrueClass, FalseClass]
|
44
44
|
attribute :public, :kind_of => [TrueClass, FalseClass]
|
45
|
-
attribute :mode, :regex => [
|
45
|
+
attribute :mode, :regex => [/^[0-7]{3}$/]
|
46
46
|
attribute :disk_type, :kind_of => String
|
47
47
|
attribute :source, :kind_of => String
|
48
48
|
attribute :target, :kind_of => String
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2016, BlackBerry Limited
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -36,7 +36,7 @@ class Chef
|
|
36
36
|
attribute :ar_id, :kind_of => Integer
|
37
37
|
attribute :template_file, :kind_of => String
|
38
38
|
attribute :cluster_id, :kind_of => Integer
|
39
|
-
attribute :mode, :regex => [
|
39
|
+
attribute :mode, :regex => [/^[0-7]{3}$/]
|
40
40
|
|
41
41
|
attribute :driver
|
42
42
|
|
data/spec/config_sample.rb
CHANGED
@@ -3,15 +3,24 @@
|
|
3
3
|
## Feel free to modify any variables to your needs. ##
|
4
4
|
#######################################################
|
5
5
|
|
6
|
-
#
|
7
|
-
|
6
|
+
# your driver url, opennebula:<endpoint_url>:<profile>
|
7
|
+
DRIVER_URL = 'opennebula:http://1.2.3.4:443/api:boggi'
|
8
|
+
|
9
|
+
# test for profile moving, set nil to skip
|
10
|
+
DRIVER_URL_2 = 'opennebula:http://1.2.3.4:443/api:gary'
|
11
|
+
|
12
|
+
# set this to nil if you do not want to test OneFlow
|
13
|
+
ONE_FLOW_URL = 'http://gary.1.2.3.4:9876'
|
8
14
|
|
9
15
|
# the path to your local chef repo, an empty folder would work, if the folder does not exist, one will be automatically created
|
10
16
|
CHEF_REPO_PATH = '/home/gary/test-repo'
|
11
17
|
|
12
|
-
# required for recipes
|
18
|
+
# required for recipes involving allocating datablocks
|
13
19
|
DATASTORE_ID = 103
|
14
20
|
|
21
|
+
# required for recipes involving allocating vnets
|
22
|
+
VNET_ID = 394
|
23
|
+
|
15
24
|
VM_TEMPLATE = {
|
16
25
|
# the base URL from which files are downloaded eg. chef-client.deb, init.sh, service.gz etc.
|
17
26
|
'HTTPBASE' => 'http://my.server.com',
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2016, BlackBerry
|
1
|
+
# Copyright 2016, BlackBerry Limited
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -12,276 +12,10 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require
|
16
|
-
require 'chef/provisioning/opennebula_driver'
|
15
|
+
require "#{File.dirname(__FILE__)}/../config.rb"
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
test_helper(
|
21
|
-
'create_one_template_spec.rb',
|
22
|
-
'OneDriver/create_one_template_spec.rb',
|
23
|
-
"create template 'OpenNebula-test-tpl'"
|
24
|
-
)
|
25
|
-
end
|
17
|
+
# Test OneDriver
|
18
|
+
require_relative 'test_one_driver'
|
26
19
|
|
27
|
-
|
28
|
-
|
29
|
-
'create_one_template_int_spec.rb',
|
30
|
-
'OneDriver/create_one_template_int_spec.rb',
|
31
|
-
"create template 'OpenNebula-test-tpl-ints'"
|
32
|
-
)
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'instantiate_one_template_spec.rb' do
|
36
|
-
it do
|
37
|
-
is_expected.to converge_test_recipe(
|
38
|
-
'OneDriver/instantiate_one_template_spec.rb',
|
39
|
-
"created vm 'OpenNebula-tpl-1-vm'"
|
40
|
-
)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe 'create_bootstrap_vm_spec.rb' do
|
45
|
-
it do
|
46
|
-
is_expected.to converge_test_recipe(
|
47
|
-
'OneDriver/create_bootstrap_vm_spec.rb',
|
48
|
-
"created vm 'OpenNebula-bootstrap-vm'"
|
49
|
-
)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe 'create_one_image_spec.rb' do
|
54
|
-
it do
|
55
|
-
is_expected.to converge_test_recipe(
|
56
|
-
'OneDriver/create_one_image_spec.rb',
|
57
|
-
/allocated image 'OpenNebula-bootstrap-img'.*?wait for image 'OpenNebula-bootstrap-img' to be READY/m
|
58
|
-
)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
describe 'create_one_image_spec.rb' do
|
62
|
-
it do
|
63
|
-
is_expected.to converge_test_recipe(
|
64
|
-
'OneDriver/create_one_image_spec.rb',
|
65
|
-
/image 'OpenNebula-bootstrap-img' already exists - nothing to do.*?image 'OpenNebula-bootstrap-img' is already in READY state - nothing to do/m
|
66
|
-
)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe 'attach_one_image_spec.rb' do
|
71
|
-
it do
|
72
|
-
is_expected.to converge_test_recipe(
|
73
|
-
'OneDriver/attach_one_image_spec.rb',
|
74
|
-
/disk not attached, attaching.*?attached disk OpenNebula-bootstrap-img to OpenNebula-bootstrap-vm/m
|
75
|
-
)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
describe 'attach_one_image_spec.rb' do
|
79
|
-
it do
|
80
|
-
is_expected.to converge_test_recipe(
|
81
|
-
'OneDriver/attach_one_image_spec.rb',
|
82
|
-
/disk is already attached.*?attached disk OpenNebula-bootstrap-img to OpenNebula-bootstrap-vm/m
|
83
|
-
)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe 'snapshot_one_image_spec.rb' do
|
88
|
-
it do
|
89
|
-
is_expected.to converge_test_recipe(
|
90
|
-
'OneDriver/snapshot_one_image_spec.rb',
|
91
|
-
"created snapshot from 'OpenNebula-bootstrap-vm'"
|
92
|
-
)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe 'converge_bootstrap_vm_spec.rb' do
|
97
|
-
it do
|
98
|
-
is_expected.to converge_test_recipe(
|
99
|
-
'OneDriver/converge_bootstrap_vm_spec.rb',
|
100
|
-
/vm 'OpenNebula-bootstrap-vm' is ready.*?create client OpenNebula-bootstrap-vm at clients.*?run 'chef-client -l info' on OpenNebula-bootstrap-vm/m
|
101
|
-
)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
# deploys two test backend VM's
|
106
|
-
describe 'snapshot_two_image_spec.rb' do
|
107
|
-
it do
|
108
|
-
is_expected.to converge_test_recipe(
|
109
|
-
'OneDriver/snapshot_two_image_spec.rb',
|
110
|
-
"created snapshot from 'OpenNebula-bootstrap-vm'"
|
111
|
-
)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe 'create_back_one_vm_spec.rb' do
|
116
|
-
it do
|
117
|
-
is_expected.to converge_test_recipe(
|
118
|
-
'OneDriver/create_back_one_vm_spec.rb',
|
119
|
-
/created vm 'OpenNebula-back-1-vm'.*?create node OpenNebula-back-1-vm.*?vm 'OpenNebula-back-1-vm' is ready.*?update node OpenNebula-back-1-vm/m
|
120
|
-
)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe 'attach_back_one_vm_spec.rb' do
|
125
|
-
it do
|
126
|
-
is_expected.to converge_test_recipe(
|
127
|
-
'OneDriver/attach_back_one_vm_spec.rb',
|
128
|
-
/disk not attached, attaching.*?attached disk OpenNebula-snap-1-img to OpenNebula-back-1-vm/m
|
129
|
-
)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
describe 'attach_back_one_vm_spec.rb' do
|
133
|
-
it do
|
134
|
-
is_expected.to converge_test_recipe(
|
135
|
-
'OneDriver/attach_back_one_vm_spec.rb',
|
136
|
-
/disk is already attached.*?attached disk OpenNebula-snap-1-img to OpenNebula-back-1-vm/m
|
137
|
-
)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe 'converge_back_one_vm_spec.rb' do
|
142
|
-
it do
|
143
|
-
is_expected.to converge_test_recipe(
|
144
|
-
'OneDriver/converge_back_one_vm_spec.rb',
|
145
|
-
/vm 'OpenNebula-back-1-vm' is ready.*?create client OpenNebula-back-1-vm at clients.*?run 'chef-client -l info' on OpenNebula-back-1-vm/m
|
146
|
-
)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe 'create_back_two_vm_spec.rb' do
|
151
|
-
it do
|
152
|
-
is_expected.to converge_test_recipe(
|
153
|
-
'OneDriver/create_back_two_vm_spec.rb',
|
154
|
-
/created vm 'OpenNebula-back-2-vm'.*?create node OpenNebula-back-2-vm.*?vm 'OpenNebula-back-2-vm' is ready.*?update node OpenNebula-back-2-vm/m
|
155
|
-
)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
describe 'attach_back_two_vm_spec.rb' do
|
160
|
-
it do
|
161
|
-
is_expected.to converge_test_recipe(
|
162
|
-
'OneDriver/attach_back_two_vm_spec.rb',
|
163
|
-
/disk not attached, attaching.*?attached disk OpenNebula-snap-2-img to OpenNebula-back-2-vm/m
|
164
|
-
)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
describe 'attach_back_two_vm_spec.rb' do
|
168
|
-
it do
|
169
|
-
is_expected.to converge_test_recipe(
|
170
|
-
'OneDriver/attach_back_two_vm_spec.rb',
|
171
|
-
/disk is already attached.*?attached disk OpenNebula-snap-2-img to OpenNebula-back-2-vm/m
|
172
|
-
)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe 'converge_back_two_vm_spec.rb' do
|
177
|
-
it do
|
178
|
-
is_expected.to converge_test_recipe(
|
179
|
-
'OneDriver/converge_back_two_vm_spec.rb',
|
180
|
-
/vm 'OpenNebula-back-2-vm' is ready.*?create client OpenNebula-back-2-vm at clients.*?run 'chef-client -l info' on OpenNebula-back-2-vm/m
|
181
|
-
)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
#############
|
186
|
-
## CLEANUP ##
|
187
|
-
#############
|
188
|
-
|
189
|
-
describe 'delete OpenNebula-test-tpl' do
|
190
|
-
test_helper(
|
191
|
-
'delete OpenNebula-test-tpl',
|
192
|
-
'OneDriver/delete/OpenNebula-test-tpl.rb',
|
193
|
-
"delete template 'OpenNebula-test-tpl'"
|
194
|
-
)
|
195
|
-
end
|
196
|
-
|
197
|
-
describe 'delete OpenNebula-test-tpl-ints' do
|
198
|
-
test_helper(
|
199
|
-
'delete OpenNebula-test-tpl-ints',
|
200
|
-
'OneDriver/delete/OpenNebula-test-tpl-ints.rb',
|
201
|
-
"delete template 'OpenNebula-test-tpl-ints'"
|
202
|
-
)
|
203
|
-
end
|
204
|
-
|
205
|
-
describe 'delete OpenNebula-tpl-1-vm' do
|
206
|
-
test_helper(
|
207
|
-
'delete OpenNebula-tpl-1-vm',
|
208
|
-
'OneDriver/delete/OpenNebula-tpl-1-vm.rb',
|
209
|
-
/destroyed machine OpenNebula-tpl-1-vm.*?delete node OpenNebula-tpl-1-vm.*?delete client OpenNebula-tpl-1-vm at clients/m
|
210
|
-
)
|
211
|
-
end
|
212
|
-
|
213
|
-
describe 'delete OpenNebula-bootstrap-vm' do
|
214
|
-
test_helper(
|
215
|
-
'delete OpenNebula-bootstrap-vm',
|
216
|
-
'OneDriver/delete/OpenNebula-bootstrap-vm.rb',
|
217
|
-
/destroyed machine OpenNebula-bootstrap-vm.*?delete node OpenNebula-bootstrap-vm.*?delete client OpenNebula-bootstrap-vm at clients/m
|
218
|
-
)
|
219
|
-
end
|
220
|
-
|
221
|
-
describe 'delete OpenNebula-bootstrap-img' do
|
222
|
-
it do
|
223
|
-
is_expected.to converge_test_recipe(
|
224
|
-
'OneDriver/delete/OpenNebula-bootstrap-img.rb',
|
225
|
-
"deleted image 'OpenNebula-bootstrap-img'"
|
226
|
-
)
|
227
|
-
end
|
228
|
-
end
|
229
|
-
describe 'delete OpenNebula-bootstrap-img' do
|
230
|
-
it do
|
231
|
-
is_expected.to converge_test_recipe(
|
232
|
-
'OneDriver/delete/OpenNebula-bootstrap-img.rb',
|
233
|
-
"image 'OpenNebula-bootstrap-img' does not exist - nothing to do"
|
234
|
-
)
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
describe 'delete OpenNebula-back-1-vm' do
|
239
|
-
test_helper(
|
240
|
-
'delete OpenNebula-back-1-vm',
|
241
|
-
'OneDriver/delete/OpenNebula-back-1-vm.rb',
|
242
|
-
/destroyed machine OpenNebula-back-1-vm.*?delete node OpenNebula-back-1-vm.*?delete client OpenNebula-back-1-vm at clients/m
|
243
|
-
)
|
244
|
-
end
|
245
|
-
|
246
|
-
describe 'delete OpenNebula-back-2-vm' do
|
247
|
-
test_helper(
|
248
|
-
'delete OpenNebula-back-2-vm',
|
249
|
-
'OneDriver/delete/OpenNebula-back-2-vm.rb',
|
250
|
-
/destroyed machine OpenNebula-back-2-vm.*?delete node OpenNebula-back-2-vm.*?delete client OpenNebula-back-2-vm at clients/m
|
251
|
-
)
|
252
|
-
end
|
253
|
-
|
254
|
-
describe 'delete OpenNebula-snap-1-img' do
|
255
|
-
it do
|
256
|
-
is_expected.to converge_test_recipe(
|
257
|
-
'OneDriver/delete/OpenNebula-snap-1-img.rb',
|
258
|
-
"deleted image 'OpenNebula-snap-1-img'"
|
259
|
-
)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
describe 'delete OpenNebula-snap-1-img' do
|
263
|
-
it do
|
264
|
-
is_expected.to converge_test_recipe(
|
265
|
-
'OneDriver/delete/OpenNebula-snap-1-img.rb',
|
266
|
-
"image 'OpenNebula-snap-1-img' does not exist - nothing to do"
|
267
|
-
)
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
describe 'delete OpenNebula-snap-2-img' do
|
272
|
-
it do
|
273
|
-
is_expected.to converge_test_recipe(
|
274
|
-
'OneDriver/delete/OpenNebula-snap-2-img.rb',
|
275
|
-
"deleted image 'OpenNebula-snap-2-img'"
|
276
|
-
)
|
277
|
-
end
|
278
|
-
end
|
279
|
-
describe 'delete OpenNebula-snap-2-img' do
|
280
|
-
it do
|
281
|
-
is_expected.to converge_test_recipe(
|
282
|
-
'OneDriver/delete/OpenNebula-snap-2-img.rb',
|
283
|
-
"image 'OpenNebula-snap-2-img' does not exist - nothing to do"
|
284
|
-
)
|
285
|
-
end
|
286
|
-
end
|
287
|
-
end
|
20
|
+
# Test OneFlow
|
21
|
+
require_relative 'test_one_flow' unless ONE_FLOW_URL.nil?
|