Skip to content

Commit

Permalink
improve idempotence in :create and :delete actions
Browse files Browse the repository at this point in the history
  • Loading branch information
schisamo committed Aug 30, 2013
1 parent d079231 commit 2104d1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
24 changes: 10 additions & 14 deletions providers/interface_junos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,22 @@ def whyrun_supported?
action :create do
updated_values = junos_client.updated_changed_properties(new_resource.state,
current_resource.state)

message = "create interface #{new_resource.name} with values:"
message << " #{updated_values.map{|e| e.join(" => ")}.join(", ")}"

converge_by(message) do
junos_client.commit!
Chef::Log.debug("#{new_resource} wrote and committed configuration changes")
unless updated_values.empty?
message = "create interface #{new_resource.name} with values:"
message << " #{updated_values.map{|e| e.join(" => ")}.join(", ")}"
converge_by(message) do
junos_client.write!
end
end

# Chef::Log.info("#{new_resource} created")
end

action :delete do
if current_resource.exists
converge_by("remove interface #{new_resource.name}") do
if current_resource.exists?
converge_by("delete existing interface #{new_resource.name}") do
junos_client.delete!
Chef::Log.info("#{new_resource} deleted")
end
else
Chef::Log.debug("#{new_resource} does not exist - nothing to do")
end
end

action :enable do
if current_resource.exists? && !current_resource.active?
Expand Down
22 changes: 10 additions & 12 deletions providers/vlan_junos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,22 @@ def whyrun_supported?
action :create do
updated_values = junos_client.updated_changed_properties(new_resource.state,
current_resource.state)

message = "create vlan #{new_resource.name} with values:"
message << " #{updated_values.map{|e| e.join(" => ")}.join(", ")}"

converge_by(message) do
junos_client.write!
Chef::Log.debug("#{new_resource} wrote and committed configuration changes")
unless updated_values.empty?
message = "create vlan #{new_resource.name} with values:"
message << " #{updated_values.map{|e| e.join(" => ")}.join(", ")}"
converge_by(message) do
junos_client.write!
end
end
end

action :delete do
if current_resource.exists
converge_by("remove vlan #{new_resource.name}") do
if current_resource.exists?
converge_by("delete existing vlan #{new_resource.name}") do
junos_client.delete!
Chef::Log.info("#{new_resource} deleted")
end
else
Chef::Log.debug("#{new_resource} does not exist - nothing to do")
end
end

action :enable do
if current_resource.exists? && !current_resource.active?
Expand Down

0 comments on commit 2104d1c

Please sign in to comment.