Class: Chef::ResolverServer
- Inherits:
-
Object
- Object
- Chef::ResolverServer
- Defined in:
- lib/chef/resolver_server.rb
Constant Summary collapse
- IPv4 =
"127.0.0.1".freeze
Instance Method Summary collapse
-
#initialize(port, config, watch = false) ⇒ ResolverServer
constructor
A new instance of ResolverServer.
- #load_chef_config(config) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(port, config, watch = false) ⇒ ResolverServer
Returns a new instance of ResolverServer.
10 11 12 13 14 15 16 17 18 |
# File 'lib/chef/resolver_server.rb', line 10 def initialize port, config, watch = false @port = port if config.is_a?(String) load_config_from_file config start_file_watcher if watch else load_config config end end |
Instance Method Details
#load_chef_config(config) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/chef/resolver_server.rb', line 31 def load_chef_config config @default_config ||= Chef::Config.configuration @original_env ||= ENV.to_hash @cached_configs ||= {} cache_key = config.object_id cached_config = @cached_configs[cache_key] if cached_config Chef::Config.configuration = cached_config else Chef::Config.configuration = @default_config.dup (config['env'] || []).each do |key, val| ENV[key] = val end Chef::Config.from_file(config['knife_file']) @cached_configs[cache_key] = Chef::Config.configuration ENV.replace(@original_env) end nil end |
#start ⇒ Object
20 21 22 23 24 |
# File 'lib/chef/resolver_server.rb', line 20 def start @server = UDPSocket.open @server.bind IPv4, @port @thread = Thread.new { process_requests } end |
#stop ⇒ Object
26 27 28 29 |
# File 'lib/chef/resolver_server.rb', line 26 def stop @thread.kill if @thread @watcher.stop if @watcher end |