diff options
author | Tim Smith <tsmith@chef.io> | 2017-03-25 17:02:36 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2017-08-09 20:00:33 +0000 |
commit | 70eef6e0eea010420de4751d13164c3748a299c1 (patch) | |
tree | 26d818c7778c9177e1cfb36dc647f087dac2edaf /lib/chef | |
parent | 7372d0ece166ee0d5a3e25bf84861807995e58be (diff) | |
download | chef-70eef6e0eea010420de4751d13164c3748a299c1.tar.gz |
Add zypper_repository resource
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/provider/support/zypper_repo.erb | 17 | ||||
-rw-r--r-- | lib/chef/provider/zypper_repository.rb | 79 | ||||
-rw-r--r-- | lib/chef/providers.rb | 1 | ||||
-rw-r--r-- | lib/chef/resource/zypper_repository.rb | 51 | ||||
-rw-r--r-- | lib/chef/resources.rb | 1 |
5 files changed, 149 insertions, 0 deletions
diff --git a/lib/chef/provider/support/zypper_repo.erb b/lib/chef/provider/support/zypper_repo.erb new file mode 100644 index 0000000000..6d508fa77f --- /dev/null +++ b/lib/chef/provider/support/zypper_repo.erb @@ -0,0 +1,17 @@ +# This file was generated by Chef +# Do NOT modify this file by hand. + +[<%= @config.repo_name %>] +<% %w{ type enabled autorefresh gpgcheck gpgkey baseurl mirrorlist path priority keeppackages mode refresh_cache }.each do |prop| -%> +<% next if @config.send(prop.to_sym).nil? -%> +<%= prop %>=<%= + case @config.send(prop.to_sym) + when TrueClass + '1' + when FalseClass + '0' + else + @config.send(prop.to_sym) + end %> +<% end -%> +name=<%= @config.description || @config.repo_name %> diff --git a/lib/chef/provider/zypper_repository.rb b/lib/chef/provider/zypper_repository.rb new file mode 100644 index 0000000000..b0b6e3aefd --- /dev/null +++ b/lib/chef/provider/zypper_repository.rb @@ -0,0 +1,79 @@ +# +# Author:: Tim Smith (<tsmith@chef.io>) +# Copyright:: Copyright (c) 2017, Chef Software Inc. +# License:: Apache License, Version 2.0 +# +# 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. +# + +require "chef/resource" +require "chef/dsl/declare_resource" +require "chef/mixin/which" +require "chef/provider/noop" + +class Chef + class Provider + class ZypperRepository < Chef::Provider + + extend Chef::Mixin::Which + + provides :zypper_repository do + which "zypper" + end + + def load_current_resource + end + + action :create do + declare_resource(:template, "/etc/zypp/repos.d/#{new_resource.repo_name}.repo") do + if template_available?(new_resource.source) + source new_resource.source + else + source ::File.expand_path("../support/zypper_repo.erb", __FILE__) + local true + end + sensitive new_resource.sensitive + variables(config: new_resource) + mode new_resource.mode + notifies :run, "execute[zypper --non-interactive refresh #{new_resource.repo_name}]", :immediately if new_resource.refresh_cache + end + + declare_resource(:execute, "zypper --non-interactive refresh #{new_resource.repo_name}") do + action :nothing + end + end + + action :delete do + declare_resource(:execute, "zypper removerepo #{new_resource.repo_name}") do + only_if "zypper lr #{new_resource.repo_name}" + end + end + + action :refresh do + declare_resource(:execute, "zypper refresh #{new_resource.repo_name}") do + only_if "zypper lr #{new_resource.repo_name}" + end + end + + alias_method :action_add, :action_create + alias_method :action_remove, :action_delete + + def template_available?(path) + !path.nil? && run_context.has_template_in_cookbook?(new_resource.cookbook_name, path) + end + + end + end +end + +Chef::Provider::Noop.provides :zypper_repository diff --git a/lib/chef/providers.rb b/lib/chef/providers.rb index 5a4d287b89..e5b39c4e3c 100644 --- a/lib/chef/providers.rb +++ b/lib/chef/providers.rb @@ -60,6 +60,7 @@ require "chef/provider/user" require "chef/provider/whyrun_safe_ruby_block" require "chef/provider/yum_repository" require "chef/provider/windows_task" +require "chef/provider/zypper_repository" require "chef/provider/env/windows" diff --git a/lib/chef/resource/zypper_repository.rb b/lib/chef/resource/zypper_repository.rb new file mode 100644 index 0000000000..cce09ec83c --- /dev/null +++ b/lib/chef/resource/zypper_repository.rb @@ -0,0 +1,51 @@ +# +# Author:: Tim Smith (<tsmith@chef.io>) +# Copyright:: Copyright (c) 2017 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# 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. +# + +require "chef/resource" + +class Chef + class Resource + class ZypperRepository < Chef::Resource + resource_name :zypper_repository + provides :zypper_repository + + property :repo_name, String, name_property: true + property :description, String + property :type, String, default: "NONE" + property :enabled, [true, false], default: true + property :autorefresh, [true, false], default: true + property :gpgcheck, [true, false], default: true + property :gpgkey, String + property :baseurl, String + property :mirrorlist, String + property :path, String + property :priority, Integer, default: 99 + property :keeppackages, [true, false], default: false + property :mode, default: "0644" + property :refresh_cache, [true, false], default: true + property :source, String, regex: /.*/ + + default_action :create + allowed_actions :create, :remove, :add, :refresh + + # provide compatibility with the zypper cookbook + alias_method :key, :gpgkey + alias_method :uri, :baseurl + end + end +end diff --git a/lib/chef/resources.rb b/lib/chef/resources.rb index 7761d9ea66..a1f4f8ac0b 100644 --- a/lib/chef/resources.rb +++ b/lib/chef/resources.rb @@ -96,6 +96,7 @@ require "chef/resource/yum_repository" require "chef/resource/lwrp_base" require "chef/resource/bff_package" require "chef/resource/zypper_package" +require "chef/resource/zypper_repository" require "chef/resource/cab_package" require "chef/resource/powershell_package" require "chef/resource/msu_package" |