Class: ChefMetal::Machine::BasicMachine
Instance Attribute Summary collapse
#node
Instance Method Summary
collapse
-
#converge(action_handler, chef_server) ⇒ Object
-
#disconnect ⇒ Object
-
#download_file(action_handler, path, local_path) ⇒ Object
-
#execute(action_handler, command, options = {}) ⇒ Object
-
#execute_always(command, options = {}) ⇒ Object
-
#initialize(node, transport, convergence_strategy) ⇒ BasicMachine
constructor
A new instance of BasicMachine.
-
#make_url_available_to_remote(local_url) ⇒ Object
-
#read_file(path) ⇒ Object
-
#setup_convergence(action_handler, machine_resource) ⇒ Object
Sets up everything necessary for convergence to happen on the machine.
-
#upload_file(action_handler, local_path, path, options = {}) ⇒ Object
-
#write_file(action_handler, path, content, options = {}) ⇒ Object
#create_dir, #delete_file, #detect_os, #file_exists?, #files_different?, #get_attributes, #is_directory?, #set_attributes
Constructor Details
#initialize(node, transport, convergence_strategy) ⇒ BasicMachine
Returns a new instance of BasicMachine.
6
7
8
9
10
|
# File 'lib/chef_metal/machine/basic_machine.rb', line 6
def initialize(node, transport, convergence_strategy)
super(node)
@transport = transport
@convergence_strategy = convergence_strategy
end
|
Instance Attribute Details
#convergence_strategy ⇒ Object
Returns the value of attribute convergence_strategy.
13
14
15
|
# File 'lib/chef_metal/machine/basic_machine.rb', line 13
def convergence_strategy
@convergence_strategy
end
|
#transport ⇒ Object
Returns the value of attribute transport.
12
13
14
|
# File 'lib/chef_metal/machine/basic_machine.rb', line 12
def transport
@transport
end
|
Instance Method Details
#converge(action_handler, chef_server) ⇒ Object
22
23
24
|
# File 'lib/chef_metal/machine/basic_machine.rb', line 22
def converge(action_handler, chef_server)
convergence_strategy.converge(action_handler, self, chef_server)
end
|
#disconnect ⇒ Object
76
77
78
|
# File 'lib/chef_metal/machine/basic_machine.rb', line 76
def disconnect
transport.disconnect
end
|
#download_file(action_handler, path, local_path) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/chef_metal/machine/basic_machine.rb', line 42
def download_file(action_handler, path, local_path)
if files_different?(path, local_path)
action_handler.perform_action "download file #{path} on #{node['name']} to #{local_path}" do
transport.download_file(path, local_path)
end
end
end
|
#execute(action_handler, command, options = {}) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/chef_metal/machine/basic_machine.rb', line 26
def execute(action_handler, command, options = {})
action_handler.perform_action "run '#{command}' on #{node['name']}" do
result = transport.execute(command, options)
result.error!
result
end
end
|
#execute_always(command, options = {}) ⇒ Object
34
35
36
|
# File 'lib/chef_metal/machine/basic_machine.rb', line 34
def execute_always(command, options = {})
transport.execute(command, options)
end
|
#make_url_available_to_remote(local_url) ⇒ Object
72
73
74
|
# File 'lib/chef_metal/machine/basic_machine.rb', line 72
def make_url_available_to_remote(local_url)
transport.make_url_available_to_remote(local_url)
end
|
#read_file(path) ⇒ Object
38
39
40
|
# File 'lib/chef_metal/machine/basic_machine.rb', line 38
def read_file(path)
transport.read_file(path)
end
|
#setup_convergence(action_handler, machine_resource) ⇒ Object
Sets up everything necessary for convergence to happen on the machine. The node MUST be saved as part of this procedure. Other than that, nothing is guaranteed except that converge() will work when this is done.
18
19
20
|
# File 'lib/chef_metal/machine/basic_machine.rb', line 18
def setup_convergence(action_handler, machine_resource)
convergence_strategy.setup_convergence(action_handler, self, machine_resource)
end
|
#upload_file(action_handler, local_path, path, options = {}) ⇒ Object
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/chef_metal/machine/basic_machine.rb', line 61
def upload_file(action_handler, local_path, path, options = {})
if files_different?(path, local_path)
if options[:ensure_dir]
create_dir(action_handler, dirname_on_machine(path))
end
action_handler.perform_action "upload file #{local_path} to #{path} on #{node['name']}" do
transport.upload_file(local_path, path)
end
end
end
|
#write_file(action_handler, path, content, options = {}) ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/chef_metal/machine/basic_machine.rb', line 50
def write_file(action_handler, path, content, options = {})
if files_different?(path, nil, content)
if options[:ensure_dir]
create_dir(action_handler, dirname_on_machine(path))
end
action_handler.perform_action "write file #{path} on #{node['name']}" do
transport.write_file(path, content)
end
end
end
|