Skip to content

Commit

Permalink
Adding whyrun support to python LWRP.
Browse files Browse the repository at this point in the history
  • Loading branch information
PrajaktaPurohit committed Oct 25, 2012
1 parent e7d06b4 commit c02b226
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
31 changes: 20 additions & 11 deletions providers/pip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
require 'chef/mixin/language'
include Chef::Mixin::ShellOut

def whyrun_supported?
true
end

# the logic in all action methods mirror that of
# the Chef::Provider::Package which will make
# refactoring into core chef easy
Expand All @@ -42,10 +46,11 @@
end

if install_version
Chef::Log.info("Installing #{@new_resource} version #{install_version}")
status = install_package(@new_resource.package_name, install_version, timeout)
if status
@new_resource.updated_by_last_action(true)
description = []
description << "install package #{@new_resource} version #{install_version}"
converge_by(description) do
Chef::Log.info("Installing #{@new_resource} version #{install_version}")
status = install_package(@new_resource.package_name, install_version, timeout)
end
end
end
Expand All @@ -59,10 +64,11 @@

if @current_resource.version != candidate_version
orig_version = @current_resource.version || "uninstalled"
Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{candidate_version}")
status = upgrade_package(@new_resource.package_name, candidate_version, timeout)
if status
@new_resource.updated_by_last_action(true)
description = []
description << "upgrade #{@current_resource} version from #{@current_resource.version} to #{candidate_version}"
converge_by(description) do
Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{candidate_version}")
status = upgrade_package(@new_resource.package_name, candidate_version, timeout)
end
end
end
Expand All @@ -75,9 +81,12 @@
end

if removing_package?
Chef::Log.info("Removing #{@new_resource}")
remove_package(@current_resource.package_name, @new_resource.version, timeout)
@new_resource.updated_by_last_action(true)
description = []
description << "remove package #{@new_resource}"
converge_by(description) do
Chef::Log.info("Removing #{@new_resource}")
remove_package(@current_resource.package_name, @new_resource.version, timeout)
end
else
end
end
Expand Down
13 changes: 10 additions & 3 deletions providers/virtualenv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
require 'chef/mixin/language'
include Chef::Mixin::ShellOut

def whyrun_supported?
true
end

action :create do
unless exists?
Chef::Log.info("Creating virtualenv #{@new_resource} at #{@new_resource.path}")
Expand All @@ -35,9 +39,12 @@

action :delete do
if exists?
Chef::Log.info("Deleting virtualenv #{@new_resource} at #{@new_resource.path}")
FileUtils.rm_rf(@new_resource.path)
new_resource.updated_by_last_action(true)
description = []
description << "delete virtualenv #{@new_resource} at #{@new_resource.path}"
converge_by(description) do
Chef::Log.info("Deleting virtualenv #{@new_resource} at #{@new_resource.path}")
FileUtils.rm_rf(@new_resource.path)
end
end
end

Expand Down

0 comments on commit c02b226

Please sign in to comment.