summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Raabe <brandocorp@gmail.com>2015-03-18 22:11:38 -0700
committerBrandon Raabe <brandocorp@gmail.com>2015-03-18 22:11:38 -0700
commit19d31707dba909bcb8d24dac6293e9341ccb0b16 (patch)
tree53202cf04785f4e82b1214b954e3dca87c459454
parente871f26bc8144dc8385ea87fd146ea0c3bfcff0c (diff)
downloadchef-19d31707dba909bcb8d24dac6293e9341ccb0b16.tar.gz
pass resource as an option to allow access to resource events
-rw-r--r--lib/chef/http.rb28
-rw-r--r--lib/chef/provider/remote_file/http.rb3
2 files changed, 21 insertions, 10 deletions
diff --git a/lib/chef/http.rb b/lib/chef/http.rb
index fa17ca0006..e84115276d 100644
--- a/lib/chef/http.rb
+++ b/lib/chef/http.rb
@@ -39,12 +39,14 @@ class Chef
attr_reader :display
attr_reader :interval
+ attr_reader :resource
- def initialize(size, opts = {})
+ def initialize(size, resource)
@total = size
@status = 0
- @display = opts[:display] || false
- @interval = opts[:interval] || 10
+ @resource = resource
+ @display = resource.show_progress
+ @interval = resource.progress_interval
progress_indicator if @display
end
@@ -64,7 +66,7 @@ class Chef
@status = percent_complete
return true
end
- return false
+ false
end
def percent_complete
@@ -90,7 +92,16 @@ class Chef
end
def progress_indicator
- Chef::Log.info '[' + display_status + display_remainder + ']' + display_percentage
+ Chef::Log.debug '[' + display_status + display_remainder + ']' + display_percentage
+ send_event 'download progress:' + display_percentage
+ end
+
+ def send_event(message)
+ events.resource_update_applied(resource.name, resource.action, message)
+ end
+
+ def events
+ resource.events
end
end
@@ -146,8 +157,9 @@ class Chef
@sign_on_redirect = true
@redirects_followed = 0
@redirect_limit = 10
- @show_progress = options[:show_progress] || false
- @progress_interval = options[:progress_interval] || 1
+ @resource = options[:resource]
+ @show_progress = options[:resource].show_progress
+ @progress_interval = options[:resource].progress_interval
@middlewares = []
self.class.middlewares.each do |middleware_class|
@@ -428,7 +440,7 @@ class Chef
end
def stream_to_tempfile(url, response)
- progress = ProgressBar.new(response['Content-Length'], display: show_progress, interval: progress_interval)
+ progress = ProgressBar.new(response['Content-Length'], @resource)
tf = Tempfile.open("chef-rest")
if Chef::Platform.windows?
tf.binmode # required for binary files on Windows platforms
diff --git a/lib/chef/provider/remote_file/http.rb b/lib/chef/provider/remote_file/http.rb
index 41727bd202..68e8930634 100644
--- a/lib/chef/provider/remote_file/http.rb
+++ b/lib/chef/provider/remote_file/http.rb
@@ -114,8 +114,7 @@ class Chef
end
if want_progress?
Chef::Log.debug("enabling progress output for streaming requests")
- opts[:show_progress] = true
- opts[:progress_interval] = new_resource.progress_interval
+ opts[:resource] = new_resource
end
opts
end