Class: Chef::Provider::Machine

Inherits:
LWRPBase
  • Object
show all
Defined in:
lib/chef/provider/machine.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#machine_specObject (readonly)

Returns the value of attribute machine_spec.



82
83
84
# File 'lib/chef/provider/machine.rb', line 82

def machine_spec
  @machine_spec
end

Class Method Details

.upload_files(action_handler, machine, files) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/chef/provider/machine.rb', line 133

def self.upload_files(action_handler, machine, files)
  if files
    files.each_pair do |remote_file, local|
      if local.is_a?(Hash)
        if local[:local_path]
          machine.upload_file(action_handler, local[:local_path], remote_file)
        else
          machine.write_file(action_handler, remote_file, local[:content])
        end
      else
        machine.upload_file(action_handler, local, remote_file)
      end
    end
  end
end

Instance Method Details

#action_handlerObject



9
10
11
# File 'lib/chef/provider/machine.rb', line 9

def action_handler
  @action_handler ||= ChefMetal::ChefProviderActionHandler.new(self)
end

#current_driverObject



88
89
90
91
92
# File 'lib/chef/provider/machine.rb', line 88

def current_driver
  if machine_spec.driver_url
    run_context.chef_metal.driver_for(machine_spec.driver_url)
  end
end

#current_machine_optionsObject



98
99
100
101
102
# File 'lib/chef/provider/machine.rb', line 98

def current_machine_options
  if current_driver
    machine_options(current_driver)
  end
end

#load_current_resourceObject



125
126
127
128
129
130
131
# File 'lib/chef/provider/machine.rb', line 125

def load_current_resource
  node_driver = Chef::Provider::ChefNode.new(new_resource, run_context)
  node_driver.load_current_resource
  json = node_driver.new_json
  json['normal']['metal'] = node_driver.current_json['normal']['metal']
  @machine_spec = ChefMetal::ChefMachineSpec.new(json, new_resource.chef_server)
end

#machine_options(driver) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/chef/provider/machine.rb', line 104

def machine_options(driver)
  configs = []
  configs << {
    :convergence_options =>
      [ :chef_server,
        :allow_overwrite_keys,
        :source_key, :source_key_path, :source_key_pass_phrase,
        :private_key_options,
        :ohai_hints,
        :public_key_path, :public_key_format,
        :admin, :validator
      ].inject({}) do |result, key|
        result[key] = new_resource.send(key)
        result
      end
  }
  configs << new_resource.machine_options if new_resource.machine_options
  configs << driver.config[:machine_options] if driver.config[:machine_options]
  Cheffish::MergedConfig.new(*configs)
end

#new_driverObject



84
85
86
# File 'lib/chef/provider/machine.rb', line 84

def new_driver
  run_context.chef_metal.driver_for(new_resource.driver)
end

#new_machine_optionsObject



94
95
96
# File 'lib/chef/provider/machine.rb', line 94

def new_machine_options
  machine_options(new_driver)
end

#whyrun_supported?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/chef/provider/machine.rb', line 15

def whyrun_supported?
  true
end