Class: Chef::Provisioning::Machine::BasicMachine

Inherits:
Chef::Provisioning::Machine show all
Defined in:
lib/chef/provisioning/machine/basic_machine.rb

Direct Known Subclasses

UnixMachine, WindowsMachine

Instance Attribute Summary collapse

Attributes inherited from Chef::Provisioning::Machine

#machine_spec

Instance Method Summary collapse

Methods inherited from Chef::Provisioning::Machine

#create_dir, #delete_file, #detect_os, #file_exists?, #files_different?, #get_attributes, #is_directory?, #name, #node, #set_attributes

Constructor Details

#initialize(machine_spec, transport, convergence_strategy) ⇒ BasicMachine

Returns a new instance of BasicMachine.



7
8
9
10
11
# File 'lib/chef/provisioning/machine/basic_machine.rb', line 7

def initialize(machine_spec, transport, convergence_strategy)
  super(machine_spec)
  @transport = transport
  @convergence_strategy = convergence_strategy
end

Instance Attribute Details

#convergence_strategyObject (readonly)

Returns the value of attribute convergence_strategy.



14
15
16
# File 'lib/chef/provisioning/machine/basic_machine.rb', line 14

def convergence_strategy
  @convergence_strategy
end

#transportObject (readonly)

Returns the value of attribute transport.



13
14
15
# File 'lib/chef/provisioning/machine/basic_machine.rb', line 13

def transport
  @transport
end

Instance Method Details

#cleanup_convergence(action_handler) ⇒ Object



24
25
26
# File 'lib/chef/provisioning/machine/basic_machine.rb', line 24

def cleanup_convergence(action_handler)
  convergence_strategy.cleanup_convergence(action_handler, machine_spec)
end

#converge(action_handler) ⇒ Object



20
21
22
# File 'lib/chef/provisioning/machine/basic_machine.rb', line 20

def converge(action_handler)
  convergence_strategy.converge(action_handler, self)
end

#disconnectObject



78
79
80
# File 'lib/chef/provisioning/machine/basic_machine.rb', line 78

def disconnect
  transport.disconnect
end

#download_file(action_handler, path, local_path) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/chef/provisioning/machine/basic_machine.rb', line 44

def download_file(action_handler, path, local_path)
  if files_different?(path, local_path)
    action_handler.perform_action "download file #{path} on #{machine_spec.name} to #{local_path}" do
      transport.download_file(path, local_path)
    end
  end
end

#execute(action_handler, command, options = {}) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/chef/provisioning/machine/basic_machine.rb', line 28

def execute(action_handler, command, options = {})
  action_handler.perform_action "run '#{command}' on #{machine_spec.name}" do
    result = transport.execute(command, options)
    result.error!
    result
  end
end

#execute_always(command, options = {}) ⇒ Object



36
37
38
# File 'lib/chef/provisioning/machine/basic_machine.rb', line 36

def execute_always(command, options = {})
  transport.execute(command, options)
end

#make_url_available_to_remote(local_url) ⇒ Object



74
75
76
# File 'lib/chef/provisioning/machine/basic_machine.rb', line 74

def make_url_available_to_remote(local_url)
  transport.make_url_available_to_remote(local_url)
end

#read_file(path) ⇒ Object



40
41
42
# File 'lib/chef/provisioning/machine/basic_machine.rb', line 40

def read_file(path)
  transport.read_file(path)
end

#setup_convergence(action_handler) ⇒ Object



16
17
18
# File 'lib/chef/provisioning/machine/basic_machine.rb', line 16

def setup_convergence(action_handler)
  convergence_strategy.setup_convergence(action_handler, self)
end

#upload_file(action_handler, local_path, path, options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/chef/provisioning/machine/basic_machine.rb', line 63

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 #{machine_spec.name}" do
      transport.upload_file(local_path, path)
    end
  end
end

#write_file(action_handler, path, content, options = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/chef/provisioning/machine/basic_machine.rb', line 52

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 #{machine_spec.name}" do
      transport.write_file(path, content)
    end
  end
end