Skip to content

Commit

Permalink
allow resources used in provider to send updated_by_last_action
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Baer committed Sep 10, 2014
1 parent 0d4876d commit bd271e3
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions providers/default.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
use_inline_resources if respond_to?(:use_inline_resources)

def whyrun_supported?
true
end

def set_updated
r = yield
new_resource.updated_by_last_action(r.updated_by_last_action?)
end

def load_current_resource
unless new_resource.config_directory
case node['haproxy']['install_method']
Expand All @@ -23,40 +32,52 @@ def make_hash(attr)
new_hash
end

action :create do

run_context.include_recipe "haproxy::install_#{node['haproxy']['install_method']}"

if(new_resource.config.is_a?(Proc))
chef_gem 'attribute_struct'
require 'attribute_struct'
new_resource.config AttributeStruct.new(&new_resource.config)._dump
end

def create_haproxy_etc_directory
directory new_resource.config_directory do
recursive true
end
end

new_resource.config Chef::Mixin::DeepMerge.merge(make_hash(node[:haproxy][:config]), new_resource.config)

def haproxy_default_file
cookbook_file '/etc/default/haproxy' do
source 'haproxy-default'
cookbook 'haproxy'
owner 'root'
group 'root'
mode 00644
notifies :restart, 'service[haproxy]'
notifies :restart, 'service[haproxy]', :delayed
end
end

def create_haproxy_cfg
template ::File.join(new_resource.config_directory, 'haproxy.cfg') do
source 'haproxy.dynamic.cfg.erb'
cookbook 'haproxy'
owner 'root'
group 'root'
mode 00644
notifies :reload, 'service[haproxy]'
notifies :reload, 'service[haproxy]', :delayed
variables(:config => new_resource.config)
end
end

action :create do

run_context.include_recipe "haproxy::install_#{node['haproxy']['install_method']}"

if(new_resource.config.is_a?(Proc))
chef_gem 'attribute_struct'
require 'attribute_struct'
new_resource.config AttributeStruct.new(&new_resource.config)._dump
end

set_updated { create_haproxy_etc_directory }

new_resource.config Chef::Mixin::DeepMerge.merge(make_hash(node[:haproxy][:config]), new_resource.config)

set_updated { haproxy_default_file }

set_updated { create_haproxy_cfg }

service "haproxy" do
supports :restart => true, :status => true, :reload => true
Expand Down

0 comments on commit bd271e3

Please sign in to comment.