chef-provisioning 2.0.0 → 2.0.1
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/CHANGELOG.md +899 -885
- data/Gemfile +17 -17
- data/LICENSE +201 -201
- data/README.md +312 -312
- data/Rakefile +55 -55
- data/chef-provisioning.gemspec +38 -38
- data/lib/chef/provider/load_balancer.rb +75 -75
- data/lib/chef/provider/machine.rb +219 -219
- data/lib/chef/provider/machine_batch.rb +224 -224
- data/lib/chef/provider/machine_execute.rb +36 -35
- data/lib/chef/provider/machine_file.rb +55 -55
- data/lib/chef/provider/machine_image.rb +105 -105
- data/lib/chef/provisioning.rb +110 -110
- data/lib/chef/provisioning/action_handler.rb +68 -68
- data/lib/chef/provisioning/add_prefix_action_handler.rb +35 -35
- data/lib/chef/provisioning/chef_managed_entry_store.rb +128 -128
- data/lib/chef/provisioning/chef_provider_action_handler.rb +74 -74
- data/lib/chef/provisioning/chef_run_data.rb +132 -132
- data/lib/chef/provisioning/convergence_strategy.rb +28 -28
- data/lib/chef/provisioning/convergence_strategy/ignore_convergence_failure.rb +54 -54
- data/lib/chef/provisioning/convergence_strategy/install_cached.rb +188 -188
- data/lib/chef/provisioning/convergence_strategy/install_msi.rb +71 -71
- data/lib/chef/provisioning/convergence_strategy/install_sh.rb +71 -71
- data/lib/chef/provisioning/convergence_strategy/no_converge.rb +35 -35
- data/lib/chef/provisioning/convergence_strategy/precreate_chef_objects.rb +255 -255
- data/lib/chef/provisioning/driver.rb +323 -323
- data/lib/chef/provisioning/load_balancer_spec.rb +14 -14
- data/lib/chef/provisioning/machine.rb +112 -112
- data/lib/chef/provisioning/machine/basic_machine.rb +84 -84
- data/lib/chef/provisioning/machine/unix_machine.rb +288 -288
- data/lib/chef/provisioning/machine/windows_machine.rb +108 -108
- data/lib/chef/provisioning/machine_image_spec.rb +34 -34
- data/lib/chef/provisioning/machine_spec.rb +58 -58
- data/lib/chef/provisioning/managed_entry.rb +121 -121
- data/lib/chef/provisioning/managed_entry_store.rb +136 -136
- data/lib/chef/provisioning/recipe_dsl.rb +99 -99
- data/lib/chef/provisioning/rspec.rb +27 -27
- data/lib/chef/provisioning/transport.rb +100 -100
- data/lib/chef/provisioning/transport/ssh.rb +403 -403
- data/lib/chef/provisioning/transport/winrm.rb +144 -156
- data/lib/chef/provisioning/version.rb +5 -5
- data/lib/chef/resource/chef_data_bag_resource.rb +146 -146
- data/lib/chef/resource/load_balancer.rb +57 -57
- data/lib/chef/resource/machine.rb +128 -128
- data/lib/chef/resource/machine_batch.rb +78 -78
- data/lib/chef/resource/machine_execute.rb +30 -29
- data/lib/chef/resource/machine_file.rb +34 -34
- data/lib/chef/resource/machine_image.rb +35 -35
- data/lib/chef_metal.rb +1 -1
- data/spec/chef/provisioning/convergence_strategy/ignore_convergence_failure_spec.rb +86 -86
- data/spec/spec_helper.rb +27 -27
- metadata +5 -5
@@ -1,68 +1,68 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
#
|
3
|
-
# Author:: Douglas Triggs (<doug@chef.io>)
|
4
|
-
#
|
5
|
-
# Copyright (C) 2014, Chef, Inc.
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
|
19
|
-
# This is the generic action handler
|
20
|
-
class Chef
|
21
|
-
module Provisioning
|
22
|
-
class ActionHandler
|
23
|
-
|
24
|
-
# This should be replaced with whatever records the update; by default it
|
25
|
-
# essentially does nothing here.
|
26
|
-
def updated!
|
27
|
-
@updated = true
|
28
|
-
end
|
29
|
-
|
30
|
-
def should_perform_actions
|
31
|
-
true
|
32
|
-
end
|
33
|
-
|
34
|
-
def report_progress(description)
|
35
|
-
Array(description).each { |d| puts d }
|
36
|
-
end
|
37
|
-
|
38
|
-
def performed_action(description)
|
39
|
-
Array(description).each { |d| puts d }
|
40
|
-
end
|
41
|
-
|
42
|
-
# This should perform the actual action (e.g., converge) if there is an
|
43
|
-
# action that needs to be done.
|
44
|
-
def perform_action(description)
|
45
|
-
if should_perform_actions
|
46
|
-
result = yield
|
47
|
-
else
|
48
|
-
result = nil
|
49
|
-
end
|
50
|
-
performed_action(description)
|
51
|
-
result
|
52
|
-
end
|
53
|
-
|
54
|
-
# Open a stream which can be printed to and closed
|
55
|
-
def open_stream(name)
|
56
|
-
if block_given?
|
57
|
-
yield STDOUT
|
58
|
-
else
|
59
|
-
STDOUT
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# A URL identifying the host node. nil if no such node.
|
64
|
-
def host_node
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Author:: Douglas Triggs (<doug@chef.io>)
|
4
|
+
#
|
5
|
+
# Copyright (C) 2014, Chef, Inc.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
|
19
|
+
# This is the generic action handler
|
20
|
+
class Chef
|
21
|
+
module Provisioning
|
22
|
+
class ActionHandler
|
23
|
+
|
24
|
+
# This should be replaced with whatever records the update; by default it
|
25
|
+
# essentially does nothing here.
|
26
|
+
def updated!
|
27
|
+
@updated = true
|
28
|
+
end
|
29
|
+
|
30
|
+
def should_perform_actions
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
def report_progress(description)
|
35
|
+
Array(description).each { |d| puts d }
|
36
|
+
end
|
37
|
+
|
38
|
+
def performed_action(description)
|
39
|
+
Array(description).each { |d| puts d }
|
40
|
+
end
|
41
|
+
|
42
|
+
# This should perform the actual action (e.g., converge) if there is an
|
43
|
+
# action that needs to be done.
|
44
|
+
def perform_action(description)
|
45
|
+
if should_perform_actions
|
46
|
+
result = yield
|
47
|
+
else
|
48
|
+
result = nil
|
49
|
+
end
|
50
|
+
performed_action(description)
|
51
|
+
result
|
52
|
+
end
|
53
|
+
|
54
|
+
# Open a stream which can be printed to and closed
|
55
|
+
def open_stream(name)
|
56
|
+
if block_given?
|
57
|
+
yield STDOUT
|
58
|
+
else
|
59
|
+
STDOUT
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# A URL identifying the host node. nil if no such node.
|
64
|
+
def host_node
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -1,35 +1,35 @@
|
|
1
|
-
require 'chef/provisioning/action_handler'
|
2
|
-
|
3
|
-
class Chef
|
4
|
-
module Provisioning
|
5
|
-
class AddPrefixActionHandler
|
6
|
-
extend Forwardable
|
7
|
-
|
8
|
-
def initialize(action_handler, prefix)
|
9
|
-
@action_handler = action_handler
|
10
|
-
@prefix = prefix
|
11
|
-
end
|
12
|
-
|
13
|
-
attr_reader :action_handler
|
14
|
-
attr_reader :prefix
|
15
|
-
attr_reader :locally_updated
|
16
|
-
|
17
|
-
def_delegators :@action_handler, :should_perform_actions, :updated!, :open_stream, :host_node
|
18
|
-
|
19
|
-
def report_progress(description)
|
20
|
-
@locally_updated = true
|
21
|
-
action_handler.report_progress(Array(description).flatten.map { |d| "#{prefix}#{d}" })
|
22
|
-
end
|
23
|
-
|
24
|
-
def performed_action(description)
|
25
|
-
@locally_updated = true
|
26
|
-
action_handler.performed_action(Array(description).flatten.map { |d| "#{prefix}#{d}" })
|
27
|
-
end
|
28
|
-
|
29
|
-
def perform_action(description, &block)
|
30
|
-
@locally_updated = true
|
31
|
-
action_handler.perform_action(Array(description).flatten.map { |d| "#{prefix}#{d}" }, &block)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
1
|
+
require 'chef/provisioning/action_handler'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
module Provisioning
|
5
|
+
class AddPrefixActionHandler
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
def initialize(action_handler, prefix)
|
9
|
+
@action_handler = action_handler
|
10
|
+
@prefix = prefix
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :action_handler
|
14
|
+
attr_reader :prefix
|
15
|
+
attr_reader :locally_updated
|
16
|
+
|
17
|
+
def_delegators :@action_handler, :should_perform_actions, :updated!, :open_stream, :host_node
|
18
|
+
|
19
|
+
def report_progress(description)
|
20
|
+
@locally_updated = true
|
21
|
+
action_handler.report_progress(Array(description).flatten.map { |d| "#{prefix}#{d}" })
|
22
|
+
end
|
23
|
+
|
24
|
+
def performed_action(description)
|
25
|
+
@locally_updated = true
|
26
|
+
action_handler.performed_action(Array(description).flatten.map { |d| "#{prefix}#{d}" })
|
27
|
+
end
|
28
|
+
|
29
|
+
def perform_action(description, &block)
|
30
|
+
@locally_updated = true
|
31
|
+
action_handler.perform_action(Array(description).flatten.map { |d| "#{prefix}#{d}" }, &block)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,128 +1,128 @@
|
|
1
|
-
require 'chef/provisioning/managed_entry_store'
|
2
|
-
require 'cheffish'
|
3
|
-
|
4
|
-
class Chef
|
5
|
-
module Provisioning
|
6
|
-
class ChefManagedEntryStore < ManagedEntryStore
|
7
|
-
def initialize(chef_server = Cheffish.default_chef_server)
|
8
|
-
@chef_server = chef_server
|
9
|
-
end
|
10
|
-
|
11
|
-
attr_reader :chef_server
|
12
|
-
|
13
|
-
def chef_api
|
14
|
-
@chef_api ||= Cheffish.chef_server_api(chef_server)
|
15
|
-
end
|
16
|
-
|
17
|
-
#
|
18
|
-
# Get the given data
|
19
|
-
#
|
20
|
-
# @param resource_type [Symbol] The type of thing to retrieve (:machine, :machine_image, :load_balancer, :aws_vpc, :aws_subnet, ...)
|
21
|
-
# @param name [String] The unique identifier of the thing to retrieve
|
22
|
-
#
|
23
|
-
# @return [Hash,Array] The data, or `nil` if the data does not exist. Will be JSON- and YAML-compatible (Hash, Array, String, Integer, Boolean, Nil)
|
24
|
-
#
|
25
|
-
def get_data(resource_type, name)
|
26
|
-
begin
|
27
|
-
if resource_type == :machine
|
28
|
-
chef_api.get("nodes/#{name}")
|
29
|
-
else
|
30
|
-
chef_api.get("data/#{resource_type}/#{name}")
|
31
|
-
end
|
32
|
-
rescue Net::HTTPServerException => e
|
33
|
-
if e.response.code == '404'
|
34
|
-
backcompat_type = ChefManagedEntryStore.type_names_for_backcompat[resource_type]
|
35
|
-
if backcompat_type && backcompat_type != resource_type
|
36
|
-
get_data(backcompat_type, name)
|
37
|
-
else
|
38
|
-
nil
|
39
|
-
end
|
40
|
-
else
|
41
|
-
raise
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
#
|
47
|
-
# Save the given data
|
48
|
-
#
|
49
|
-
# @param resource_type [Symbol] The type of thing to save (:machine, :machine_image, :load_balancer, :aws_vpc, :aws_subnet ...)
|
50
|
-
# @param name [String] The unique identifier of the thing to save
|
51
|
-
# @param data [Hash,Array] The data to save. Must be JSON- and YAML-compatible (Hash, Array, String, Integer, Boolean, Nil)
|
52
|
-
#
|
53
|
-
def save_data(resource_type, name, data, action_handler)
|
54
|
-
_chef_server = self.chef_server
|
55
|
-
Chef::Provisioning.inline_resource(action_handler) do
|
56
|
-
if resource_type == :machine
|
57
|
-
chef_node name do
|
58
|
-
chef_server _chef_server
|
59
|
-
raw_json data
|
60
|
-
end
|
61
|
-
else
|
62
|
-
chef_data_bag resource_type.to_s do
|
63
|
-
chef_server _chef_server
|
64
|
-
end
|
65
|
-
chef_data_bag_item name do
|
66
|
-
chef_server _chef_server
|
67
|
-
data_bag resource_type.to_s
|
68
|
-
raw_data data
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
backcompat_type = ChefManagedEntryStore.type_names_for_backcompat[resource_type]
|
74
|
-
if backcompat_type && backcompat_type != resource_type
|
75
|
-
delete_data(backcompat_type, name, action_handler)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
#
|
80
|
-
# Delete the given data
|
81
|
-
#
|
82
|
-
# @param resource_type [Symbol] The type of thing to delete (:machine, :machine_image, :load_balancer, :aws_vpc, :aws_subnet, ...)
|
83
|
-
# @param name [String] The unique identifier of the thing to delete
|
84
|
-
#
|
85
|
-
# @return [Boolean] Whether anything was deleted or not.
|
86
|
-
#
|
87
|
-
def delete_data(resource_type, name, action_handler)
|
88
|
-
_chef_server = self.chef_server
|
89
|
-
Chef::Provisioning.inline_resource(action_handler) do
|
90
|
-
if resource_type == :machine
|
91
|
-
chef_node name do
|
92
|
-
chef_server _chef_server
|
93
|
-
action :delete
|
94
|
-
end
|
95
|
-
else
|
96
|
-
chef_data_bag_item name do
|
97
|
-
chef_server _chef_server
|
98
|
-
data_bag resource_type.to_s
|
99
|
-
action :delete
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
backcompat_type = ChefManagedEntryStore.type_names_for_backcompat[resource_type]
|
105
|
-
if backcompat_type && backcompat_type != resource_type
|
106
|
-
delete_data(backcompat_type, name, action_handler)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def identifier(resource_type, name)
|
111
|
-
if resource_type == :machine
|
112
|
-
File.join(chef_server[:chef_server_url], "nodes", name)
|
113
|
-
else
|
114
|
-
File.join(chef_server[:chef_server_url], "data", resource_type.to_s, name)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
#
|
119
|
-
# A list of the name that we used to use to store a given type before we
|
120
|
-
# standardized on "just use the resource name so we don't create collisions."
|
121
|
-
# Will be used to look up the old data.
|
122
|
-
#
|
123
|
-
def self.type_names_for_backcompat
|
124
|
-
@@type_names_for_backcompat ||= {}
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
1
|
+
require 'chef/provisioning/managed_entry_store'
|
2
|
+
require 'cheffish'
|
3
|
+
|
4
|
+
class Chef
|
5
|
+
module Provisioning
|
6
|
+
class ChefManagedEntryStore < ManagedEntryStore
|
7
|
+
def initialize(chef_server = Cheffish.default_chef_server)
|
8
|
+
@chef_server = chef_server
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :chef_server
|
12
|
+
|
13
|
+
def chef_api
|
14
|
+
@chef_api ||= Cheffish.chef_server_api(chef_server)
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# Get the given data
|
19
|
+
#
|
20
|
+
# @param resource_type [Symbol] The type of thing to retrieve (:machine, :machine_image, :load_balancer, :aws_vpc, :aws_subnet, ...)
|
21
|
+
# @param name [String] The unique identifier of the thing to retrieve
|
22
|
+
#
|
23
|
+
# @return [Hash,Array] The data, or `nil` if the data does not exist. Will be JSON- and YAML-compatible (Hash, Array, String, Integer, Boolean, Nil)
|
24
|
+
#
|
25
|
+
def get_data(resource_type, name)
|
26
|
+
begin
|
27
|
+
if resource_type == :machine
|
28
|
+
chef_api.get("nodes/#{name}")
|
29
|
+
else
|
30
|
+
chef_api.get("data/#{resource_type}/#{name}")
|
31
|
+
end
|
32
|
+
rescue Net::HTTPServerException => e
|
33
|
+
if e.response.code == '404'
|
34
|
+
backcompat_type = ChefManagedEntryStore.type_names_for_backcompat[resource_type]
|
35
|
+
if backcompat_type && backcompat_type != resource_type
|
36
|
+
get_data(backcompat_type, name)
|
37
|
+
else
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
else
|
41
|
+
raise
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Save the given data
|
48
|
+
#
|
49
|
+
# @param resource_type [Symbol] The type of thing to save (:machine, :machine_image, :load_balancer, :aws_vpc, :aws_subnet ...)
|
50
|
+
# @param name [String] The unique identifier of the thing to save
|
51
|
+
# @param data [Hash,Array] The data to save. Must be JSON- and YAML-compatible (Hash, Array, String, Integer, Boolean, Nil)
|
52
|
+
#
|
53
|
+
def save_data(resource_type, name, data, action_handler)
|
54
|
+
_chef_server = self.chef_server
|
55
|
+
Chef::Provisioning.inline_resource(action_handler) do
|
56
|
+
if resource_type == :machine
|
57
|
+
chef_node name do
|
58
|
+
chef_server _chef_server
|
59
|
+
raw_json data
|
60
|
+
end
|
61
|
+
else
|
62
|
+
chef_data_bag resource_type.to_s do
|
63
|
+
chef_server _chef_server
|
64
|
+
end
|
65
|
+
chef_data_bag_item name do
|
66
|
+
chef_server _chef_server
|
67
|
+
data_bag resource_type.to_s
|
68
|
+
raw_data data
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
backcompat_type = ChefManagedEntryStore.type_names_for_backcompat[resource_type]
|
74
|
+
if backcompat_type && backcompat_type != resource_type
|
75
|
+
delete_data(backcompat_type, name, action_handler)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# Delete the given data
|
81
|
+
#
|
82
|
+
# @param resource_type [Symbol] The type of thing to delete (:machine, :machine_image, :load_balancer, :aws_vpc, :aws_subnet, ...)
|
83
|
+
# @param name [String] The unique identifier of the thing to delete
|
84
|
+
#
|
85
|
+
# @return [Boolean] Whether anything was deleted or not.
|
86
|
+
#
|
87
|
+
def delete_data(resource_type, name, action_handler)
|
88
|
+
_chef_server = self.chef_server
|
89
|
+
Chef::Provisioning.inline_resource(action_handler) do
|
90
|
+
if resource_type == :machine
|
91
|
+
chef_node name do
|
92
|
+
chef_server _chef_server
|
93
|
+
action :delete
|
94
|
+
end
|
95
|
+
else
|
96
|
+
chef_data_bag_item name do
|
97
|
+
chef_server _chef_server
|
98
|
+
data_bag resource_type.to_s
|
99
|
+
action :delete
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
backcompat_type = ChefManagedEntryStore.type_names_for_backcompat[resource_type]
|
105
|
+
if backcompat_type && backcompat_type != resource_type
|
106
|
+
delete_data(backcompat_type, name, action_handler)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def identifier(resource_type, name)
|
111
|
+
if resource_type == :machine
|
112
|
+
File.join(chef_server[:chef_server_url], "nodes", name)
|
113
|
+
else
|
114
|
+
File.join(chef_server[:chef_server_url], "data", resource_type.to_s, name)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# A list of the name that we used to use to store a given type before we
|
120
|
+
# standardized on "just use the resource name so we don't create collisions."
|
121
|
+
# Will be used to look up the old data.
|
122
|
+
#
|
123
|
+
def self.type_names_for_backcompat
|
124
|
+
@@type_names_for_backcompat ||= {}
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|