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.



111
112
113
# File 'lib/chef/provider/machine.rb', line 111

def machine_spec
  @machine_spec
end

Class Method Details

.additional_machine_option_keysObject



179
180
181
# File 'lib/chef/provider/machine.rb', line 179

def self.additional_machine_option_keys
  @@additional_machine_option_keys ||= []
end

.upload_files(action_handler, machine, files) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/chef/provider/machine.rb', line 201

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



11
12
13
# File 'lib/chef/provider/machine.rb', line 11

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

#action_handler=(value) ⇒ Object



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

def action_handler=(value)
  @action_handler = value
end

#chef_managed_entry_storeObject



197
198
199
# File 'lib/chef/provider/machine.rb', line 197

def chef_managed_entry_store
  @chef_managed_entry_store ||= Provisioning.chef_managed_entry_store(new_resource.chef_server)
end

#current_driverObject



117
118
119
120
121
# File 'lib/chef/provider/machine.rb', line 117

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

#current_machine_optionsObject



137
138
139
# File 'lib/chef/provider/machine.rb', line 137

def current_machine_options
  machine_options(current_driver)
end

#from_image_specObject



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

def from_image_spec
  @from_image_spec ||= begin
    if new_resource.from_image
      chef_managed_entry_store.get!(:machine_image, new_resource.from_image)
    else
      nil
    end
  end
end

#load_current_resourceObject



183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/chef/provider/machine.rb', line 183

def load_current_resource
  if defined?(Chef::Provider::ChefNode)
    # Cheffish 1.x
    node_provider = Chef::Provider::ChefNode.new(new_resource, run_context)
  else
    # Cheffish 2.x
    node_provider = Chef::Resource::ChefNode.action_class.new(new_resource, run_context)
  end
  node_provider.load_current_resource
  json = node_provider.new_json
  json['normal']['chef_provisioning'] = node_provider.current_json['normal']['chef_provisioning']
  @machine_spec = chef_managed_entry_store.new_entry(:machine, new_resource.name, json)
end

#machine_options(driver) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/chef/provider/machine.rb', line 141

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,
        :chef_config
      ].inject({}) do |result, key|
        result[key] = new_resource.send(key)
        result
      end
  }

  # The current use case for this is adding a new attribute `aws_tags` to
  # the machine resource from the chef-provisioning-aws driver.  Because we
  # want that attribute to work for the recipe DSL, it needs to be added at the
  # Chef::Resource::Machine class level and not at an instance level.  Thus we
  # also need to pull the additional_machine_option_keys (:aws_tags) from the
  # Chef::Resource::Machine class level.  If you use two drivers (like AWS and
  # Azure) then all machine instances will still have the `aws_tags` attribute
  # DSL and will pass `:aws_tags` in on the machine_options.  They can simply
  # be ignored by the Azure driver.
  (self.class.additional_machine_option_keys || []).each do |k|
    configs << { k => new_resource.send(k)} if new_resource.send(k)
  end

  configs << { from_image: new_resource.from_image } if new_resource.from_image
  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



113
114
115
# File 'lib/chef/provider/machine.rb', line 113

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

#new_machine_optionsObject



133
134
135
# File 'lib/chef/provider/machine.rb', line 133

def new_machine_options
  machine_options(new_driver)
end

#whyrun_supported?Boolean

Returns:

  • (Boolean)


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

def whyrun_supported?
  true
end