diff --git a/providers/pool.rb b/providers/pool.rb index 182c450..e248c08 100644 --- a/providers/pool.rb +++ b/providers/pool.rb @@ -13,7 +13,17 @@ def whyrun_supported? action :create do if @current_resource.exists - Chef::Log.info "#{@new_resource} already exists - nothing to do." + if @current_resource.pg_num == @new_resource.pg_num + Chef::Log.info "#{@new_resource} already exists - nothing to do." + else + Chef::Log.info "#{@new_resource} already exists, with different pg_num." + converge_by("Setting pg_num for #{@new_resource}") do + set_pg_num(@new_resource.name, @new_resource.pg_num) + while get_pgp_num(@new_resource.name) != @new_resource.pg_num + set_pgp_num(@new_resource.name, @new_resource.pg_num) + end + end + end else converge_by("Creating #{@new_resource}") do create_pool @@ -35,6 +45,8 @@ def load_current_resource @current_resource = Chef::Resource::CephPool.new(@new_resource.name) @current_resource.name(@new_resource.name) @current_resource.exists = pool_exists?(@current_resource.name) + @current_resource.pg_num = get_pg_num(@current_resource.name) || 0 + @current_resource.pgp_num = get_pgp_num(@current_resource.name) || 0 end def create_pool @@ -56,6 +68,36 @@ def delete_pool Chef::Log.debug "Pool deleted: #{cmd.stderr}" end +def set_pg_num(name, pg_num) + cmd_text = "ceph osd pool set #{name} pg_num #{pg_num}" + cmd = Mixlib::ShellOut.new(cmd_text) + cmd.run_command + cmd.error! + Chef::Log.debug "Placement Groups Set: #{cmd.stderr}" +end + +def set_pgp_num(name, pg_num) + cmd_text = "ceph osd pool set #{name} pgp_num #{pg_num}" + cmd = Mixlib::ShellOut.new(cmd_text) + cmd.run_command + cmd.error! + Chef::Log.debug "Placement Groups Set: #{cmd.stderr}" +end + +def get_pg_num(name) + cmd = Mixlib::ShellOut.new("ceph osd pool get #{name} pg_num") + cmd.run_command + cmd.error! + cmd.stdout.split(' ')[1].to_i +end + +def get_pgp_num(name) + cmd = Mixlib::ShellOut.new("ceph osd pool get #{name} pgp_num") + cmd.run_command + cmd.error! + cmd.stdout.split(' ')[1].to_i +end + def pool_exists?(name) cmd = Mixlib::ShellOut.new("ceph osd pool get #{name} size") cmd.run_command diff --git a/resources/pool.rb b/resources/pool.rb index 2e3052e..052dccc 100644 --- a/resources/pool.rb +++ b/resources/pool.rb @@ -12,6 +12,7 @@ # The total number of placement groups for the pool. attribute :pg_num, :kind_of => Integer, :required => true +attribute :pgp_num, kind_of: Integer, required: false # Optional arguments for pool creation attribute :create_options, :kind_of => String