Class: Chef::Provider::MachineImage

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.additional_image_option_keysObject



96
97
98
# File 'lib/chef/provider/machine_image.rb', line 96

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

Instance Method Details

#action_handlerObject



10
11
12
# File 'lib/chef/provider/machine_image.rb', line 10

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

#chef_managed_entry_storeObject



22
23
24
# File 'lib/chef/provider/machine_image.rb', line 22

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

#create_image(image_spec, machine_options) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/chef/provider/machine_image.rb', line 56

def create_image(image_spec, machine_options)
  # 1. Create the exemplar machine
  machine_provider = Chef::Provider::Machine.new(new_resource, run_context)
  machine_provider.action_handler = action_handler
  machine_provider.load_current_resource
  machine_provider.action_converge

  # 2. Create the image
  machine_options = new_machine_options
  new_driver.allocate_image(action_handler, image_spec, new_image_options,
                            machine_provider.machine_spec, machine_options)
  image_spec.driver_url ||= new_driver.driver_url
  image_spec.from_image ||= new_resource.from_image if new_resource.from_image
  image_spec.run_list   ||= machine_provider.machine_spec.node['run_list']

  # 3. Save the linkage from name -> image id
  image_spec.save(action_handler)

  # 4. Wait for image to be ready
  new_driver.ready_image(action_handler, image_spec, new_image_options)

  machine_provider.action_destroy
end

#load_current_resourceObject



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

def load_current_resource
end

#new_driverObject

Get the driver specified in the resource



18
19
20
# File 'lib/chef/provider/machine_image.rb', line 18

def new_driver
  @new_driver ||= run_context.chef_provisioning.driver_for(new_resource.driver)
end

#new_image_optionsObject



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/chef/provider/machine_image.rb', line 80

def new_image_options
  @new_image_options ||= begin
    configs = []
    configs << new_resource.image_options if new_resource.image_options
    # See documentation in machine.rb provider
    (self.class.additional_image_option_keys || []).each do |k|
      configs << { k => new_resource.send(k)} if new_resource.send(k)
    end
    Cheffish::MergedConfig.new(*configs)
  end
end

#new_machine_optionsObject



92
93
94
# File 'lib/chef/provider/machine_image.rb', line 92

def new_machine_options
  @new_machine_options ||= new_resource.machine_options
end