summaryrefslogtreecommitdiff
path: root/lib/chef/local_mode.rb
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-07-03 20:20:03 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-07-07 10:04:59 -0700
commit4f6488026bed45da624812de6985b1168b2358b2 (patch)
tree86cfb1945fce1fc061c64a37d8ab0da2495fab44 /lib/chef/local_mode.rb
parentb658f99957b24bfdf72fb340336d0348fdaf70f5 (diff)
downloadchef-4f6488026bed45da624812de6985b1168b2358b2.tar.gz
Refactor caller decorations into with_server_connectivity
Diffstat (limited to 'lib/chef/local_mode.rb')
-rw-r--r--lib/chef/local_mode.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/chef/local_mode.rb b/lib/chef/local_mode.rb
index eac2174c0b..0b8b66cae2 100644
--- a/lib/chef/local_mode.rb
+++ b/lib/chef/local_mode.rb
@@ -18,6 +18,32 @@ require 'chef/config'
class Chef
module LocalMode
+ # Create a chef local server (if the configuration requires one) for the
+ # duration of the given block.
+ #
+ # # This ...
+ # with_server_connectivity { stuff }
+ #
+ # # Is exactly equivalent to this ...
+ # Chef::LocalMode.setup_server_connectivity
+ # begin
+ # stuff
+ # ensure
+ # Chef::LocalMode.destroy_server_connectivity
+ # end
+ #
+ def self.with_server_connectivity
+ setup_server_connectivity
+ begin
+ yield
+ ensure
+ destroy_server_connectivity
+ end
+ end
+
+ # 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.
def self.setup_server_connectivity
if Chef::Config.chef_zero.enabled
destroy_server_connectivity
@@ -42,10 +68,12 @@ class Chef
end
end
+ # Return the current chef-zero server set up by setup_server_connectivity.
def self.chef_zero_server
@chef_zero_server
end
+ # If chef_zero_server is non-nil, stop it and remove references to it.
def self.destroy_server_connectivity
if @chef_zero_server
@chef_zero_server.stop