Class: Chef::Provisioning::ChefRunData

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/provisioning/chef_run_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ChefRunData

Returns a new instance of ChefRunData.


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

def initialize(config)
  @config = config
  @drivers = {}
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


13
14
15
# File 'lib/chef/provisioning/chef_run_data.rb', line 13

def config
  @config
end

#current_driverObject (readonly)

Returns the value of attribute current_driver


15
16
17
# File 'lib/chef/provisioning/chef_run_data.rb', line 15

def current_driver
  @current_driver
end

#current_image_optionsObject

Returns the value of attribute current_image_options


18
19
20
# File 'lib/chef/provisioning/chef_run_data.rb', line 18

def current_image_options
  @current_image_options
end

#current_load_balancer_optionsObject

Returns the value of attribute current_load_balancer_options


17
18
19
# File 'lib/chef/provisioning/chef_run_data.rb', line 17

def current_load_balancer_options
  @current_load_balancer_options
end

#current_machine_optionsObject

Returns the value of attribute current_machine_options


16
17
18
# File 'lib/chef/provisioning/chef_run_data.rb', line 16

def current_machine_options
  @current_machine_options
end

#driversObject (readonly)

Returns the value of attribute drivers


14
15
16
# File 'lib/chef/provisioning/chef_run_data.rb', line 14

def drivers
  @drivers
end

Instance Method Details

#add_machine_options(options, &block) ⇒ Object


79
80
81
# File 'lib/chef/provisioning/chef_run_data.rb', line 79

def add_machine_options(options, &block)
  with_machine_options(Chef::Mixin::DeepMerge.hash_only_merge(current_machine_options, options), &block)
end

#connect_to_machine(name, chef_server = nil) ⇒ Object


87
88
89
90
91
92
93
94
# File 'lib/chef/provisioning/chef_run_data.rb', line 87

def connect_to_machine(name, chef_server = nil)
  if name.is_a?(ManagedEntry)
    machine_spec = name
  else
    machine_spec = Provisioning.chef_managed_entry_store(chef_server).get(:machine, name)
  end
  Chef::Provisioning.connect_to_machine(machine_spec, config)
end

#driver_for(driver) ⇒ Object


83
84
85
# File 'lib/chef/provisioning/chef_run_data.rb', line 83

def driver_for(driver)
  driver.is_a?(String) ? driver_for_url(driver) : driver
end

#with_driver(driver, options = nil, &block) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/chef/provisioning/chef_run_data.rb', line 44

def with_driver(driver, options = nil, &block)
  if drivers[driver] && options
    raise "Driver #{driver} has already been created, options #{options} would be ignored!"
  end
  old_driver, old_options = @current_driver, @current_driver_options
  @current_driver, @current_driver_options = driver, options
  if block_given?
    begin
      yield
    ensure
      @current_driver, @current_driver_options = old_driver, old_options
    end
  end
end

#with_image_options(value) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
# File 'lib/chef/provisioning/chef_run_data.rb', line 32

def with_image_options(value)
  old_value = self.current_image_options
  self.current_image_options = value
  if block_given?
    begin
      yield
    ensure
      self.current_image_options = old_value
    end
  end
end

#with_machine_options(value) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/chef/provisioning/chef_run_data.rb', line 20

def with_machine_options(value)
  old_value = self.current_machine_options
  self.current_machine_options = value
  if block_given?
    begin
      yield
    ensure
      self.current_machine_options = old_value
    end
  end
end