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


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

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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config


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

def config
  @config
end

#current_data_centerObject

Returns the value of attribute current_data_center


20
21
22
# File 'lib/chef/provisioning/chef_run_data.rb', line 20

def current_data_center
  @current_data_center
end

#current_driverObject (readonly)

Returns the value of attribute current_driver


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

def current_driver
  @current_driver
end

#current_image_optionsObject

Returns the value of attribute current_image_options


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

def current_image_options
  @current_image_options
end

#current_load_balancer_optionsObject

Returns the value of attribute current_load_balancer_options


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

def current_load_balancer_options
  @current_load_balancer_options
end

#current_machine_optionsObject

Returns the value of attribute current_machine_options


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

def current_machine_options
  @current_machine_options
end

#driversObject (readonly)

Returns the value of attribute drivers


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

def drivers
  @drivers
end

Instance Method Details

#add_machine_options(options, &block) ⇒ Object


86
87
88
# File 'lib/chef/provisioning/chef_run_data.rb', line 86

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


94
95
96
97
98
99
100
101
# File 'lib/chef/provisioning/chef_run_data.rb', line 94

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

#driver_for(driver) ⇒ Object


90
91
92
# File 'lib/chef/provisioning/chef_run_data.rb', line 90

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

#with_data_center(value) ⇒ Object


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

def with_data_center(value)
  old_value = self.current_data_center
  self.current_data_center = value
  if block_given?
    begin
      yield
    ensure
      self.current_data_center = old_value
    end
  end
end

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


58
59
60
61
62
63
64
# File 'lib/chef/provisioning/chef_run_data.rb', line 58

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

#with_image_options(value) ⇒ Object


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

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


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

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