Module: Chef::Provisioning

Defined in:
lib/chef/provisioning.rb,
lib/chef/provisioning/driver.rb,
lib/chef/provisioning/machine.rb,
lib/chef/provisioning/version.rb,
lib/chef/provisioning/transport.rb,
lib/chef/provisioning/image_spec.rb,
lib/chef/provisioning/machine_spec.rb,
lib/chef/provisioning/chef_run_data.rb,
lib/chef/provisioning/transport/ssh.rb,
lib/chef/provisioning/action_handler.rb,
lib/chef/provisioning/chef_image_spec.rb,
lib/chef/provisioning/transport/winrm.rb,
lib/chef/provisioning/chef_machine_spec.rb,
lib/chef/provisioning/load_balancer_spec.rb,
lib/chef/provisioning/convergence_strategy.rb,
lib/chef/provisioning/machine/unix_machine.rb,
lib/chef/provisioning/machine/basic_machine.rb,
lib/chef/provisioning/chef_load_balancer_spec.rb,
lib/chef/provisioning/machine/windows_machine.rb,
lib/chef/provisioning/add_prefix_action_handler.rb,
lib/chef/provisioning/chef_provider_action_handler.rb,
lib/chef/provisioning/convergence_strategy/install_sh.rb,
lib/chef/provisioning/convergence_strategy/install_msi.rb,
lib/chef/provisioning/convergence_strategy/no_converge.rb,
lib/chef/provisioning/convergence_strategy/install_cached.rb,
lib/chef/provisioning/convergence_strategy/precreate_chef_objects.rb

Defined Under Namespace

Classes: ActionHandler, ActionHandlerForward, AddPrefixActionHandler, ChefImageSpec, ChefLoadBalancerSpec, ChefMachineSpec, ChefProviderActionHandler, ChefRunData, ConvergenceStrategy, Driver, ImageSpec, LoadBalancerSpec, Machine, MachineSpec, Transport

Constant Summary collapse

VERSION =
'0.15.1'
@@registered_driver_classes =

Helpers for driver inflation

{}

Class Method Summary collapse

Class Method Details

.connect_to_machine(machine_spec, config = Cheffish.profiled_config) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/chef/provisioning.rb', line 78

def self.connect_to_machine(machine_spec, config = Cheffish.profiled_config)
  chef_server = Cheffish.default_chef_server(config)
  if machine_spec.is_a?(String)
    machine_spec = ChefMachineSpec.get(machine_spec, chef_server)
  end
  driver = driver_for_url(machine_spec.driver_url, config)
  if driver
    machine_options = { :convergence_options => { :chef_server => chef_server } }
    machine_options = Cheffish::MergedConfig.new(config[:machine_options], machine_options) if config[:machine_options]
    driver.connect_to_machine(machine_spec, machine_options)
  else
    nil
  end
end

.default_driver(config = Cheffish.profiled_config) ⇒ Object



34
35
36
# File 'lib/chef/provisioning.rb', line 34

def self.default_driver(config = Cheffish.profiled_config)
  driver_for_url(config[:driver], config)
end

.driver_for_url(driver_url, config = Cheffish.profiled_config, allow_different_config = false) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/chef/provisioning.rb', line 38

def self.driver_for_url(driver_url, config = Cheffish.profiled_config, allow_different_config = false)
  #
  # Create and cache the driver
  #
  #
  # Figure out the driver class
  #
  scheme = driver_url.split(':', 2)[0]
  begin
    require "chef/provisioning/driver_init/#{scheme}"
  rescue LoadError => e
    require "chef_metal/driver_init/#{scheme}"
  end
  driver_class = @@registered_driver_classes[scheme]

  #
  # Merge in any driver-specific config
  #
  if config[:drivers] && config[:drivers][driver_url]
    config = Cheffish::MergedConfig.new(config[:drivers][driver_url], config)
  end

  #
  # Canonicalize the URL
  #
  canonicalized_url, canonicalized_config = driver_class.canonicalize_url(driver_url, config)
  config = canonicalized_config if canonicalized_config

  #
  # Merge in config from the canonicalized URL if it is different
  #
  if canonicalized_url != driver_url
    if config[:drivers] && config[:drivers][canonicalized_url]
      config = Cheffish::MergedConfig.new(config[:drivers][canonicalized_url], config)
    end
  end

  driver_class.from_url(canonicalized_url, config)
end

.inline_resource(action_handler, &block) ⇒ Object



9
10
11
12
# File 'lib/chef/provisioning.rb', line 9

def self.inline_resource(action_handler, &block)
  events = ActionHandlerForward.new(action_handler)
  Cheffish::BasicChefClient.converge_block(nil, events, &block)
end

.register_driver_class(name, driver) ⇒ Object



30
31
32
# File 'lib/chef/provisioning.rb', line 30

def self.register_driver_class(name, driver)
  @@registered_driver_classes[name] = driver
end