Method: Chef::LocalMode.setup_server_connectivity

Defined in:
lib/chef/local_mode.rb

.setup_server_connectivityObject

If Chef::Config.chef_zero.enabled is true, sets up a chef-zero server according to the Chef::Config.chef_zero and path options, and sets chef_server_url to point at it.



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
77
78
79
80
81
82
83
84
85
# File 'lib/chef/local_mode.rb', line 51

def self.setup_server_connectivity
  if Chef::Config.chef_zero.enabled
    destroy_server_connectivity

    require "chef_zero/server"
    require_relative "chef_fs/chef_fs_data_store"
    require_relative "chef_fs/config"

    @chef_fs = Chef::ChefFS::Config.new.local_fs
    @chef_fs.write_pretty_json = true
    data_store = Chef::ChefFS::ChefFSDataStore.new(@chef_fs)
    data_store = ChefZero::DataStore::V1ToV2Adapter.new(data_store, "chef")
    server_options = {}
    server_options[:data_store] = data_store
    server_options[:log_level] = Chef::Log.level
    server_options[:osc_compat] = Chef::Config.chef_zero.osc_compat
    server_options[:single_org] = Chef::Config.chef_zero.single_org

    server_options[:host] = Chef::Config.chef_zero.host
    server_options[:port] = parse_port(Chef::Config.chef_zero.port)
    @chef_zero_server = ChefZero::Server.new(server_options)

    if Chef::Config[:listen]
      Chef.deprecated(:local_listen, "Starting local-mode server in deprecated socket mode")
      @chef_zero_server.start_background
    else
      @chef_zero_server.start_socketless
    end

    local_mode_url = @chef_zero_server.local_mode_url

    Chef::Log.info("Started #{ChefUtils::Dist::Zero::PRODUCT} at #{local_mode_url} with #{@chef_fs.fs_description}")
    Chef::Config.chef_server_url = local_mode_url
  end
end