Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add placement group control to the pool resource. #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion providers/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can be quite dumb... but why not testing @current_resource.pgp_num == @new_resource.pgp_num also? :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt it was redundant - pg_num should never differ from pgp_num except while changing values. We could test for it just in case something fails though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really as you wish.

Done is better than perfect

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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions resources/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down