Class: ChefMetal::Machine::BasicMachine

Inherits:
ChefMetal::Machine show all
Defined in:
lib/chef_metal/machine/basic_machine.rb

Direct Known Subclasses

UnixMachine, WindowsMachine

Instance Attribute Summary collapse

Attributes inherited from ChefMetal::Machine

#node

Instance Method Summary collapse

Methods inherited from ChefMetal::Machine

#create_dir, #delete_file, #detect_os, #file_exists?, #files_different?, #get_attributes, #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_strategyObject (readonly)

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

#transportObject (readonly)

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) ⇒ Object



22
23
24
# File 'lib/chef_metal/machine/basic_machine.rb', line 22

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

#disconnectObject



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

def disconnect
  transport.disconnect
end

#download_file(action_handler, path, local_path) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/chef_metal/machine/basic_machine.rb', line 40

def download_file(action_handler, path, local_path)
  if files_different?(path, local_path)
    action_handler.converge_by "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
# File 'lib/chef_metal/machine/basic_machine.rb', line 26

def execute(action_handler, command, options = {})
  action_handler.converge_by "run '#{command}' on #{node['name']}" do
    transport.execute(command, options).error!
  end
end

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



32
33
34
# File 'lib/chef_metal/machine/basic_machine.rb', line 32

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

#make_url_available_to_remote(local_url) ⇒ Object



70
71
72
# File 'lib/chef_metal/machine/basic_machine.rb', line 70

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

#read_file(path) ⇒ Object



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

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



59
60
61
62
63
64
65
66
67
68
# File 'lib/chef_metal/machine/basic_machine.rb', line 59

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.converge_by "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



48
49
50
51
52
53
54
55
56
57
# File 'lib/chef_metal/machine/basic_machine.rb', line 48

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.converge_by "write file #{path} on #{node['name']}" do
      transport.write_file(path, content)
    end
  end
end