chef-metal 0.10.2 → 0.11.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -5
- data/README.md +3 -3
- data/bin/metal +5 -9
- data/lib/chef/provider/machine.rb +81 -32
- data/lib/chef/provider/machine_batch.rb +67 -58
- data/lib/chef/provider/machine_execute.rb +7 -7
- data/lib/chef/provider/machine_file.rb +11 -11
- data/lib/chef/resource/machine.rb +11 -15
- data/lib/chef/resource/machine_batch.rb +1 -1
- data/lib/chef/resource/machine_execute.rb +3 -4
- data/lib/chef/resource/machine_file.rb +3 -4
- data/lib/chef_metal.rb +26 -28
- data/lib/chef_metal/action_handler.rb +9 -7
- data/lib/chef_metal/add_prefix_action_handler.rb +7 -5
- data/lib/chef_metal/chef_machine_spec.rb +64 -0
- data/lib/chef_metal/{provider_action_handler.rb → chef_provider_action_handler.rb} +27 -14
- data/lib/chef_metal/chef_run_data.rb +68 -7
- data/lib/chef_metal/convergence_strategy.rb +14 -3
- data/lib/chef_metal/convergence_strategy/install_cached.rb +24 -10
- data/lib/chef_metal/convergence_strategy/install_msi.rb +17 -10
- data/lib/chef_metal/convergence_strategy/install_sh.rb +20 -10
- data/lib/chef_metal/convergence_strategy/no_converge.rb +20 -13
- data/lib/chef_metal/convergence_strategy/precreate_chef_objects.rb +51 -47
- data/lib/chef_metal/{provider.rb → driver.rb} +103 -79
- data/lib/chef_metal/machine.rb +13 -5
- data/lib/chef_metal/machine/basic_machine.rb +11 -11
- data/lib/chef_metal/machine/unix_machine.rb +6 -6
- data/lib/chef_metal/machine/windows_machine.rb +3 -3
- data/lib/chef_metal/machine_spec.rb +22 -25
- data/lib/chef_metal/recipe_dsl.rb +34 -9
- data/lib/chef_metal/transport.rb +7 -2
- data/lib/chef_metal/transport/ssh.rb +42 -9
- data/lib/chef_metal/transport/winrm.rb +8 -5
- data/lib/chef_metal/version.rb +1 -1
- data/spec/integration/machine.rb +29 -0
- metadata +21 -9
- data/lib/chef_metal/aws_credentials.rb +0 -58
- data/lib/chef_metal/openstack_credentials.rb +0 -44
- data/lib/chef_metal/provisioner.rb +0 -121
@@ -1,58 +0,0 @@
|
|
1
|
-
module ChefMetal
|
2
|
-
# Reads in a credentials file in Amazon's download format and presents the credentials to you
|
3
|
-
class AWSCredentials
|
4
|
-
def initialize
|
5
|
-
@credentials = {}
|
6
|
-
end
|
7
|
-
|
8
|
-
def default
|
9
|
-
@credentials['default'] || @credentials.first[1]
|
10
|
-
end
|
11
|
-
|
12
|
-
def keys
|
13
|
-
@credentials.keys
|
14
|
-
end
|
15
|
-
|
16
|
-
def [](name)
|
17
|
-
@credentials[name]
|
18
|
-
end
|
19
|
-
|
20
|
-
def load_ini(credentials_ini_file)
|
21
|
-
require 'inifile'
|
22
|
-
inifile = IniFile.load(File.expand_path(credentials_ini_file))
|
23
|
-
inifile.each_section do |section|
|
24
|
-
if section =~ /^\s*profile\s+(.+)$/ || section =~ /^\s*(default)\s*/
|
25
|
-
profile = $1.strip
|
26
|
-
@credentials[profile] = {
|
27
|
-
:access_key_id => inifile[section]['aws_access_key_id'],
|
28
|
-
:secret_access_key => inifile[section]['aws_secret_access_key'],
|
29
|
-
:region => inifile[section]['region']
|
30
|
-
}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def load_csv(credentials_csv_file)
|
36
|
-
require 'csv'
|
37
|
-
CSV.new(File.open(credentials_csv_file), :headers => :first_row).each do |row|
|
38
|
-
@credentials[row['User Name']] = {
|
39
|
-
:user_name => row['User Name'],
|
40
|
-
:access_key_id => row['Access Key Id'],
|
41
|
-
:secret_access_key => row['Secret Access Key']
|
42
|
-
}
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def load_default
|
47
|
-
load_ini('~/.aws/config')
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.method_missing(name, *args, &block)
|
51
|
-
singleton.send(name, *args, &block)
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.singleton
|
55
|
-
@aws_credentials ||= AWSCredentials.new
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module ChefMetal
|
2
|
-
# Reads in a credentials file
|
3
|
-
class OpenstackCredentials
|
4
|
-
def initialize
|
5
|
-
@credentials = {}
|
6
|
-
end
|
7
|
-
|
8
|
-
def default
|
9
|
-
@credentials['default'] || @credentials.first[1]
|
10
|
-
end
|
11
|
-
|
12
|
-
def keys
|
13
|
-
@credentials.keys
|
14
|
-
end
|
15
|
-
|
16
|
-
def [](name)
|
17
|
-
@credentials[name]
|
18
|
-
end
|
19
|
-
|
20
|
-
def load_yaml(credentials_yaml_file)
|
21
|
-
creds_file = YAML.load_file(File.expand_path(credentials_yaml_file))
|
22
|
-
creds_file.each do |section, creds|
|
23
|
-
@credentials[section] = {
|
24
|
-
:openstack_username => creds_file[section]['openstack_username'],
|
25
|
-
:openstack_api_key => creds_file[section]['openstack_api_key'],
|
26
|
-
:openstack_tenant => creds_file[section]['openstack_tenant'],
|
27
|
-
:openstack_auth_url => creds_file[section]['openstack_auth_url']
|
28
|
-
}
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def load_default
|
33
|
-
load_yaml('~/.fog')
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.method_missing(name, *args, &block)
|
37
|
-
singleton.send(name, *args, &block)
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.singleton
|
41
|
-
@openstack_credentials ||= OpenstackCredentials.new
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'chef_metal/add_prefix_action_handler'
|
2
|
-
|
3
|
-
module ChefMetal
|
4
|
-
class Provisioner
|
5
|
-
# Inflate a provisioner from node information; we don't want to force the
|
6
|
-
# driver to figure out what the provisioner really needs, since it varies
|
7
|
-
# from provisioner to provisioner.
|
8
|
-
#
|
9
|
-
# ## Parameters
|
10
|
-
# node - node to inflate the provisioner for
|
11
|
-
#
|
12
|
-
# returns a should return a Privisoner from the information provided
|
13
|
-
def self.inflate(node)
|
14
|
-
raise "#{self.class} does not override self.inflate"
|
15
|
-
end
|
16
|
-
|
17
|
-
# Acquire a machine, generally by provisioning it. Returns a Machine
|
18
|
-
# object pointing at the machine, allowing useful actions like setup,
|
19
|
-
# converge, execute, file and directory. The Machine object will have a
|
20
|
-
# "node" property which must be saved to the server (if it is any
|
21
|
-
# different from the original node object).
|
22
|
-
#
|
23
|
-
# ## Parameters
|
24
|
-
# action_handler - the action_handler object that is calling this method; this
|
25
|
-
# is generally a provider, but could be anything that can support the
|
26
|
-
# interface (i.e., in the case of the test kitchen metal driver for
|
27
|
-
# acquiring and destroying VMs).
|
28
|
-
# node - node object (deserialized json) representing this machine. If
|
29
|
-
# the node has a provisioner_options hash in it, these will be used
|
30
|
-
# instead of options provided by the provisioner. TODO compare and
|
31
|
-
# fail if different?
|
32
|
-
# node will have node['normal']['provisioner_options'] in it with any
|
33
|
-
# options. It is a hash with at least these options:
|
34
|
-
#
|
35
|
-
# -- provisioner_url: <provisioner url>
|
36
|
-
#
|
37
|
-
# node['normal']['provisioner_output'] will be populated with
|
38
|
-
# information about the created machine. For vagrant, it is a hash
|
39
|
-
# with at least these options:
|
40
|
-
#
|
41
|
-
# -- provisioner_url: <provisioner url>
|
42
|
-
#
|
43
|
-
def acquire_machine(action_handler, node)
|
44
|
-
raise "#{self.class} does not override acquire_machine"
|
45
|
-
end
|
46
|
-
|
47
|
-
# Connect to a machine without acquiring it. This method will NOT make any
|
48
|
-
# changes to anything.
|
49
|
-
#
|
50
|
-
# ## Parameters
|
51
|
-
# node - node object (deserialized json) representing this machine. The
|
52
|
-
# node may have normal attributes "provisioner_options" and
|
53
|
-
# "provisioner_output" in it, representing the input and output of
|
54
|
-
# any prior "acquire_machine" process (if any).
|
55
|
-
#
|
56
|
-
def connect_to_machine(node)
|
57
|
-
raise "#{self.class} does not override connect_to_machine"
|
58
|
-
end
|
59
|
-
|
60
|
-
# Delete the given machine (idempotent). Should destroy the machine,
|
61
|
-
# returning things to the state before acquire_machine was called.
|
62
|
-
def delete_machine(action_handler, node)
|
63
|
-
raise "#{self.class} does not override delete_machine"
|
64
|
-
end
|
65
|
-
|
66
|
-
# Stop the given machine.
|
67
|
-
def stop_machine(action_handler, node)
|
68
|
-
raise "#{self.class} does not override stop_machine"
|
69
|
-
end
|
70
|
-
|
71
|
-
# Provider notification that happens at the point a resource is declared
|
72
|
-
# (after all properties have been set on it)
|
73
|
-
def resource_created(machine)
|
74
|
-
end
|
75
|
-
|
76
|
-
#
|
77
|
-
# Batch methods
|
78
|
-
#
|
79
|
-
|
80
|
-
# Acquire machines in batch, in parallel if possible.
|
81
|
-
def acquire_machines(action_handler, nodes_json, parallelizer)
|
82
|
-
parallelizer.parallelize(nodes_json) do |node_json|
|
83
|
-
machine = acquire_machine(add_prefix(node_json, action_handler), node_json)
|
84
|
-
yield node_json, machine if block_given?
|
85
|
-
machine
|
86
|
-
end.to_a
|
87
|
-
end
|
88
|
-
|
89
|
-
# Stop machines in batch, in parallel if possible.
|
90
|
-
def stop_machines(action_handler, nodes_json, parallelizer)
|
91
|
-
parallelizer.parallelize(nodes_json) do |node_json|
|
92
|
-
stop_machine(add_prefix(node_json, action_handler), node_json)
|
93
|
-
yield node_json if block_given?
|
94
|
-
end.to_a
|
95
|
-
end
|
96
|
-
|
97
|
-
# Delete machines in batch, in parallel if possible.
|
98
|
-
def delete_machines(action_handler, nodes_json, parallelizer)
|
99
|
-
parallelizer.parallelize(nodes_json) do |node_json|
|
100
|
-
delete_machine(add_prefix(node_json, action_handler), node_json)
|
101
|
-
yield node_json if block_given?
|
102
|
-
end.to_a
|
103
|
-
end
|
104
|
-
|
105
|
-
protected
|
106
|
-
|
107
|
-
def save_node(provider, node, chef_server)
|
108
|
-
# Save the node and create the client. TODO strip automatic attributes first so we don't race with "current state"
|
109
|
-
ChefMetal.inline_resource(provider) do
|
110
|
-
chef_node node['name'] do
|
111
|
-
chef_server chef_server
|
112
|
-
raw_json node
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def add_prefix(node_json, action_handler)
|
118
|
-
AddPrefixActionHandler.new(action_handler, "[#{node_json['name']}] ")
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|