-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor LWRPs into custom resources
This originated from a need to fix the deprecation warnings for use_inline_resources (FC113)[1] and this commit implements just the bare minimum required to convert to custom resources while keeping all the tests passing. Support for chef-client 12 is dropped as that will be EOL this month[2]. I also removed the exec bit from some template and attribute files. [1] http://www.foodcritic.io/#FC113 [2] https://www.chef.io/eol-chef12-and-chefdk1/
- Loading branch information
1 parent
6ea1cc2
commit 8d196b7
Showing
20 changed files
with
339 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,55 @@ | ||
actions :add | ||
# frozen_string_literal: true | ||
# | ||
# Cookbook:: dhcp | ||
# Resource:: class | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
default_action :add | ||
|
||
attribute :match, kind_of: String, required: true | ||
attribute :conf_dir, kind_of: String, default: '/etc/dhcp' | ||
property :match, String, required: true | ||
property :conf_dir, String, default: '/etc/dhcp' | ||
|
||
attr_accessor :subclasses | ||
|
||
def subclass(value) | ||
@subclasses ||= [] | ||
@subclasses << value | ||
end | ||
|
||
action_class do | ||
include Dhcp::Helpers | ||
end | ||
|
||
action :add do | ||
with_run_context :root do | ||
run_context.include_recipe 'dhcp::_service' | ||
|
||
directory "#{new_resource.conf_dir}/classes.d #{new_resource.name}" do | ||
path "#{new_resource.conf_dir}/classes.d" | ||
end | ||
|
||
template "#{new_resource.conf_dir}/classes.d/#{new_resource.name}.conf" do | ||
cookbook 'dhcp' | ||
source 'class.conf.erb' | ||
variables name: new_resource.name, match: new_resource.match, subclasses: new_resource.subclasses | ||
owner 'root' | ||
group 'root' | ||
mode '0644' | ||
notifies :restart, "service[#{node['dhcp']['service_name']}]", :delayed | ||
end | ||
|
||
write_include 'classes.d', new_resource.name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,64 @@ | ||
actions :add, :remove | ||
# frozen_string_literal: true | ||
# | ||
# Cookbook:: dhcp | ||
# Resource:: group | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
default_action :add | ||
|
||
attribute :name, kind_of: String, name_attribute: true | ||
attribute :parameters, kind_of: Array, default: [] | ||
attribute :evals, kind_of: Array, default: [] | ||
attribute :hosts, kind_of: Hash, default: {} | ||
attribute :conf_dir, kind_of: String, default: '/etc/dhcp' | ||
property :parameters, Array, default: [] | ||
property :evals, Array, default: [] | ||
property :hosts, Hash, default: {} | ||
property :conf_dir, String, default: '/etc/dhcp' | ||
|
||
action_class do | ||
include Dhcp::Helpers | ||
end | ||
|
||
action :add do | ||
with_run_context :root do | ||
directory "#{new_resource.conf_dir}/groups.d #{new_resource.name}" do | ||
path "#{new_resource.conf_dir}/groups.d" | ||
end | ||
|
||
template "#{new_resource.conf_dir}/groups.d/#{new_resource.name}.conf" do | ||
cookbook 'dhcp' | ||
source 'group.conf.erb' | ||
variables( | ||
name: new_resource.name, | ||
parameters: new_resource.parameters, | ||
evals: new_resource.evals, | ||
hosts: new_resource.hosts | ||
) | ||
owner 'root' | ||
group 'root' | ||
mode '0644' | ||
notifies :restart, "service[#{node['dhcp']['service_name']}]", :delayed | ||
end | ||
|
||
write_include 'groups.d', new_resource.name | ||
end | ||
end | ||
|
||
action :remove do | ||
with_run_context :root do | ||
file "#{new_resource.conf_dir}/groups.d/#{new_resource.name}.conf" do | ||
action :delete | ||
notifies :restart, "service[#{node['dhcp']['service_name']}]", :delayed | ||
end | ||
|
||
write_include 'groups.d', new_resource.name | ||
end | ||
end |
Oops, something went wrong.