chef-metal 0.14.2 → 0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -1
  3. data/README.md +2 -257
  4. data/Rakefile +0 -4
  5. data/lib/chef_metal.rb +1 -87
  6. data/lib/chef_metal/action_handler.rb +1 -66
  7. data/lib/chef_metal/add_prefix_action_handler.rb +1 -29
  8. data/lib/chef_metal/chef_image_spec.rb +1 -106
  9. data/lib/chef_metal/chef_machine_spec.rb +1 -82
  10. data/lib/chef_metal/chef_provider_action_handler.rb +1 -72
  11. data/lib/chef_metal/chef_run_data.rb +1 -125
  12. data/lib/chef_metal/convergence_strategy.rb +1 -26
  13. data/lib/chef_metal/convergence_strategy/install_cached.rb +1 -157
  14. data/lib/chef_metal/convergence_strategy/install_msi.rb +1 -56
  15. data/lib/chef_metal/convergence_strategy/install_sh.rb +1 -53
  16. data/lib/chef_metal/convergence_strategy/no_converge.rb +1 -37
  17. data/lib/chef_metal/convergence_strategy/precreate_chef_objects.rb +1 -181
  18. data/lib/chef_metal/driver.rb +1 -288
  19. data/lib/chef_metal/image_spec.rb +1 -70
  20. data/lib/chef_metal/machine.rb +1 -110
  21. data/lib/chef_metal/machine/basic_machine.rb +1 -82
  22. data/lib/chef_metal/machine/unix_machine.rb +1 -276
  23. data/lib/chef_metal/machine/windows_machine.rb +1 -102
  24. data/lib/chef_metal/machine_spec.rb +1 -78
  25. data/lib/chef_metal/recipe_dsl.rb +1 -94
  26. data/lib/chef_metal/transport.rb +1 -87
  27. data/lib/chef_metal/transport/ssh.rb +1 -288
  28. data/lib/chef_metal/transport/winrm.rb +1 -134
  29. data/lib/chef_metal/version.rb +1 -3
  30. metadata +19 -145
  31. data/bin/metal +0 -275
  32. data/lib/chef/provider/machine.rb +0 -171
  33. data/lib/chef/provider/machine_batch.rb +0 -186
  34. data/lib/chef/provider/machine_execute.rb +0 -30
  35. data/lib/chef/provider/machine_file.rb +0 -49
  36. data/lib/chef/provider/machine_image.rb +0 -54
  37. data/lib/chef/resource/machine.rb +0 -116
  38. data/lib/chef/resource/machine_batch.rb +0 -72
  39. data/lib/chef/resource/machine_execute.rb +0 -22
  40. data/lib/chef/resource/machine_file.rb +0 -28
  41. data/lib/chef/resource/machine_image.rb +0 -29
@@ -1,29 +1 @@
1
- require 'chef_metal/action_handler'
2
-
3
- module ChefMetal
4
- class AddPrefixActionHandler
5
- extend Forwardable
6
-
7
- def initialize(action_handler, prefix)
8
- @action_handler = action_handler
9
- @prefix = prefix
10
- end
11
-
12
- attr_reader :action_handler
13
- attr_reader :prefix
14
-
15
- def_delegators :@action_handler, :should_perform_actions, :updated!, :open_stream, :host_node
16
-
17
- def report_progress(description)
18
- action_handler.report_progress(Array(description).flatten.map { |d| "#{prefix}#{d}" })
19
- end
20
-
21
- def performed_action(description)
22
- action_handler.performed_action(Array(description).flatten.map { |d| "#{prefix}#{d}" })
23
- end
24
-
25
- def perform_action(description, &block)
26
- action_handler.perform_action(Array(description).flatten.map { |d| "#{prefix}#{d}" }, &block)
27
- end
28
- end
29
- end
1
+ require "chef/provisioning/add_prefix_action_handler"
@@ -1,106 +1 @@
1
- require 'chef_metal'
2
- require 'cheffish'
3
- require 'chef_metal/image_spec'
4
-
5
- module ChefMetal
6
- #
7
- # Specification for a image. Sufficient information to find and contact it
8
- # after it has been set up.
9
- #
10
- class ChefImageSpec < ImageSpec
11
- def initialize(node, chef_server)
12
- super(node)
13
- @chef_server = chef_server
14
- end
15
-
16
- #
17
- # Get a ImageSpec from the chef server. If the node does not exist on the
18
- # server, it returns nil.
19
- #
20
- def self.get(name, chef_server = Cheffish.default_chef_server)
21
- chef_api = Cheffish.chef_server_api(chef_server)
22
- begin
23
- data = chef_api.get("/data/images/#{name}")
24
- data['machine_options'] = strings_to_symbols(data['machine_options'])
25
- ChefImageSpec.new(data, chef_server)
26
- rescue Net::HTTPServerException => e
27
- if e.response.code == '404'
28
- nil
29
- else
30
- raise
31
- end
32
- end
33
- end
34
-
35
- # Creates a new empty ImageSpec with the given name.
36
- def self.empty(id, chef_server = Cheffish.default_chef_server)
37
- ChefImageSpec.new({ 'id' => id }, chef_server)
38
- end
39
-
40
- #
41
- # Globally unique identifier for this image. Does not depend on the image's
42
- # location or existence.
43
- #
44
- def id
45
- ChefImageSpec.id_from(chef_server, name)
46
- end
47
-
48
- def self.id_from(chef_server, name)
49
- "#{chef_server[:chef_server_url]}/data/images/#{name}"
50
- end
51
-
52
- #
53
- # Save this node to the server. If you have significant information that
54
- # could be lost, you should do this as quickly as possible. Data will be
55
- # saved automatically for you after allocate_image and ready_image.
56
- #
57
- def save(action_handler)
58
- # Save the node to the server.
59
- _self = self
60
- _chef_server = _self.chef_server
61
- ChefMetal.inline_resource(action_handler) do
62
- chef_data_bag_item _self.name do
63
- data_bag 'images'
64
- chef_server _chef_server
65
- raw_data _self.image_data
66
- end
67
- end
68
- end
69
-
70
- def delete(action_handler)
71
- # Save the node to the server.
72
- _self = self
73
- _chef_server = _self.chef_server
74
- ChefMetal.inline_resource(action_handler) do
75
- chef_data_bag_item _self.name do
76
- data_bag 'images'
77
- chef_server _chef_server
78
- action :destroy
79
- end
80
- end
81
- end
82
-
83
- protected
84
-
85
- attr_reader :chef_server
86
-
87
- #
88
- # Chef API object for the given Chef server
89
- #
90
- def chef_api
91
- Cheffish.server_api_for(chef_server)
92
- end
93
-
94
- def self.strings_to_symbols(data)
95
- if data.is_a?(Hash)
96
- result = {}
97
- data.each_pair do |key, value|
98
- result[key.to_sym] = strings_to_symbols(value)
99
- end
100
- result
101
- else
102
- data
103
- end
104
- end
105
- end
106
- end
1
+ require "chef/provisioning/chef_image_spec"
@@ -1,82 +1 @@
1
- require 'pry'
2
- require 'chef_metal'
3
- require 'cheffish'
4
- require 'chef_metal/machine_spec'
5
-
6
- module ChefMetal
7
- #
8
- # Specification for a machine. Sufficient information to find and contact it
9
- # after it has been set up.
10
- #
11
- class ChefMachineSpec < MachineSpec
12
- def initialize(node, chef_server)
13
- super(node)
14
- @chef_server = chef_server
15
- end
16
-
17
- #
18
- # Get a MachineSpec from the chef server. If the node does not exist on the
19
- # server, it returns nil.
20
- #
21
- def self.get(name, chef_server = Cheffish.default_chef_server)
22
- chef_api = Cheffish.chef_server_api(chef_server)
23
- begin
24
- ChefMachineSpec.new(chef_api.get("/nodes/#{name}"), chef_server)
25
- rescue Net::HTTPServerException => e
26
- if e.response.code == '404'
27
- nil
28
- else
29
- raise
30
- end
31
- end
32
- end
33
-
34
- # Creates a new empty MachineSpec with the given name.
35
- def self.empty(name, chef_server = Cheffish.default_chef_server)
36
- ChefMachineSpec.new({ 'name' => name, 'normal' => {} }, chef_server)
37
- end
38
-
39
- #
40
- # Globally unique identifier for this machine. Does not depend on the machine's
41
- # location or existence.
42
- #
43
- def id
44
- ChefMachineSpec.id_from(chef_server, name)
45
- end
46
-
47
- def self.id_from(chef_server, name)
48
- "#{chef_server[:chef_server_url]}/nodes/#{name}"
49
- end
50
-
51
- #
52
- # Save this node to the server. If you have significant information that
53
- # could be lost, you should do this as quickly as possible. Data will be
54
- # saved automatically for you after allocate_machine and ready_machine.
55
- #
56
- def save(action_handler)
57
- if location && (!location.is_a?(Hash) || !location['driver_url'])
58
- raise "Drivers must specify a canonical driver_url in machine_spec.location. Contact your driver's author."
59
- end
60
- # Save the node to the server.
61
- _self = self
62
- _chef_server = _self.chef_server
63
- ChefMetal.inline_resource(action_handler) do
64
- chef_node _self.name do
65
- chef_server _chef_server
66
- raw_json _self.node
67
- end
68
- end
69
- end
70
-
71
- protected
72
-
73
- attr_reader :chef_server
74
-
75
- #
76
- # Chef API object for the given Chef server
77
- #
78
- def chef_api
79
- Cheffish.server_api_for(chef_server)
80
- end
81
- end
82
- end
1
+ require "chef/provisioning/chef_machine_spec"
@@ -1,72 +1 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Author:: Douglas Triggs (<doug@getchef.com>)
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
- require 'chef_metal/action_handler'
20
-
21
- # This is included in the metal drivers to proxy from generic requests needed
22
- # to specific driver actions
23
- module ChefMetal
24
- class ChefProviderActionHandler < ActionHandler
25
- def initialize(provider)
26
- @provider = provider
27
- end
28
-
29
- attr_reader :provider
30
-
31
- def updated!
32
- provider.new_resource.updated_by_last_action(true)
33
- end
34
-
35
- def should_perform_actions
36
- !provider.run_context.config.why_run
37
- end
38
-
39
- def report_progress(description)
40
- # TODO this seems wrong but Chef doesn't have another thing
41
- provider.converge_by description do
42
- # We already did the action, but we trust whoever told us that they did it.
43
- end
44
- end
45
-
46
- def performed_action(description)
47
- provider.converge_by description do
48
- # We already did the action, but we trust whoever told us that they did it.
49
- end
50
- end
51
-
52
- def perform_action(description, &block)
53
- provider.converge_by(description, &block)
54
- end
55
-
56
- def open_stream(name, &block)
57
- if provider.run_context.respond_to?(:open_stream)
58
- provider.run_context.open_stream({ :name => name }, &block)
59
- else
60
- if block_given?
61
- yield STDOUT
62
- else
63
- STDOUT
64
- end
65
- end
66
- end
67
-
68
- def host_node
69
- "#{provider.run_context.config[:chef_server_url]}/nodes/#{provider.run_context.node['name']}"
70
- end
71
- end
72
- end
1
+ require "chef/provisioning/chef_provider_action_handler"
@@ -1,125 +1 @@
1
- require 'chef/mixin/deep_merge'
2
- require 'cheffish/merged_config'
3
- require 'chef_metal/chef_machine_spec'
4
-
5
- module ChefMetal
6
- class ChefRunData
7
-
8
- def initialize(config)
9
- @config = config
10
- @drivers = {}
11
- end
12
-
13
- attr_reader :config
14
- attr_reader :drivers
15
- attr_reader :current_driver
16
- attr_accessor :current_machine_options
17
- attr_accessor :current_image_options
18
-
19
-
20
- def with_machine_options(value)
21
- old_value = self.current_machine_options
22
- self.current_machine_options = value
23
- if block_given?
24
- begin
25
- yield
26
- ensure
27
- self.current_machine_options = old_value
28
- end
29
- end
30
- end
31
-
32
- def with_image_options(value)
33
- old_value = self.current_image_options
34
- self.current_image_options = value
35
- if block_given?
36
- begin
37
- yield
38
- ensure
39
- self.current_image_options = old_value
40
- end
41
- end
42
- end
43
-
44
-
45
- def with_driver(driver, options = nil, &block)
46
- if drivers[driver] && options
47
- raise "Driver #{driver} has already been created, options #{options} would be ignored!"
48
- end
49
- @current_driver = driver
50
- @current_driver_options = options
51
- end
52
-
53
- def current_driver
54
- @current_driver || config[:driver]
55
- end
56
-
57
- def current_machine_options
58
- if @current_machine_options
59
- @current_machine_options
60
- else
61
- {}
62
- end
63
- end
64
-
65
- def current_image_options
66
- if @current_image_options
67
- @current_image_options
68
- else
69
- {}
70
- end
71
- end
72
-
73
- def add_machine_options(options, &block)
74
- with_machine_options(Chef::Mixin::DeepMerge.hash_only_merge(current_machine_options, options), &block)
75
- end
76
-
77
- def driver_for(driver)
78
- driver.is_a?(String) ? driver_for_url(driver) : driver
79
- end
80
-
81
- def connect_to_machine(name, chef_server = nil)
82
- if name.is_a?(MachineSpec)
83
- machine_spec = name
84
- else
85
- machine_spec = ChefMetal::ChefMachineSpec.get(name, chef_server)
86
- end
87
- ChefMetal.connect_to_machine(machine_spec, config)
88
- end
89
-
90
- private
91
-
92
- def driver_for_url(driver_url)
93
- drivers[driver_url] ||= begin
94
- if driver_url == @current_driver && @current_driver_options
95
- # Use the driver options if available
96
- merged_config = Cheffish::MergedConfig.new({ :driver_options => @current_driver_options }, config)
97
- driver = ChefMetal.driver_for_url(driver_url, merged_config)
98
- else
99
- driver = ChefMetal.driver_for_url(driver_url, config)
100
- end
101
- # Check the canonicalized driver_url from the driver
102
- if driver.driver_url != driver_url
103
- if drivers[driver.driver_url] && @current_driver_options
104
- raise "Canonical driver #{driver.driver_url} for #{driver_url} has already been created! Current options #{@current_driver_options} would be ignored."
105
- end
106
- drivers[driver.driver_url] ||= driver
107
- else
108
- driver
109
- end
110
- end
111
- end
112
-
113
- def keys
114
- result = (config.keys || {}).dup
115
- Array(config.key_path) do |key_path|
116
- Dir.entries(key_path).each do |key|
117
- if File.extname(key) == '.pem'
118
- result[File.basename(key)[0..-5]] ||= key
119
- end
120
- end
121
- end
122
- result
123
- end
124
- end
125
- end
1
+ require "chef/provisioning/chef_run_data"
@@ -1,26 +1 @@
1
- module ChefMetal
2
- class ConvergenceStrategy
3
- # convergence_options - a freeform hash of options to the converger.
4
- # config - a Chef::Config-like object with global config like :log_level
5
- def initialize(convergence_options, config)
6
- @convergence_options = convergence_options || {}
7
- @config = config
8
- end
9
-
10
- attr_reader :convergence_options
11
- attr_reader :config
12
-
13
- # Get the machine ready to converge, but do not converge.
14
- def setup_convergence(action_handler, machine)
15
- raise "setup_convergence not overridden on #{self.class}"
16
- end
17
-
18
- def converge(action_handler, machine)
19
- raise "converge not overridden on #{self.class}"
20
- end
21
-
22
- def cleanup_convergence(action_handler, machine_spec)
23
- raise "cleanup_convergence not overridden on #{self.class}"
24
- end
25
- end
26
- end
1
+ require "chef/provisioning/convergence_strategy"