Module: Chefdepartie::Server
Instance Method Summary collapse
-
#configure(kwargs) ⇒ Object
Load chef config from hash or file.
- #join ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #upload_all ⇒ Object
Instance Method Details
#configure(kwargs) ⇒ Object
Load chef config from hash or file
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/chefdepartie/server.rb', line 36 def configure(kwargs) config_file = kwargs[:config_file] || ENV['CHEFDEPARTIE_CONFIG'] || '' # Load config from config file if provided Chef::Config.from_file(config_file) if !config_file.empty? && File.exist?(config_file) config = kwargs[:config] # Load config from hash if config && config.is_a?(Hash) config[:node_name] ||= 'chef-zero' config[:client_key] ||= fake_key config.each do |k, v| Chef::Config.send(k.to_sym, v) end end @background = kwargs[:background] @cache = kwargs[:cache] uri = URI(Chef::Config[:chef_server_url]) host = '0.0.0.0' host = '127.0.0.1' if (uri.host == '127.0.0.1' || uri.host == 'localhost') # listen on everything unless explicitly localhost. @opts = { host: host, port: uri.port } @opts.merge!(data_store: Cache.setup(@cache)) if @cache end |
#join ⇒ Object
20 21 22 |
# File 'lib/chefdepartie/server.rb', line 20 def join @server_thread.join unless @background end |
#start ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/chefdepartie/server.rb', line 8 def start @server = ChefZero::Server.new(@opts) if @background @server.start_background else @server_thread = Thread.new do server.start end end end |
#stop ⇒ Object
24 25 26 27 |
# File 'lib/chefdepartie/server.rb', line 24 def stop puts 'Stopping server' @server_thread.nil? ? @server.stop : @server_thread.stop end |
#upload_all ⇒ Object
29 30 31 32 33 |
# File 'lib/chefdepartie/server.rb', line 29 def upload_all Chefdepartie::Roles.upload_all Chefdepartie::Databags.upload_all Chefdepartie::Cookbooks.upload_all end |