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

LWRP for Pools and RBD #41

Closed
wants to merge 4 commits into from
Closed
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
49 changes: 49 additions & 0 deletions providers/pool.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Cookbook Name:: ceph
# Provider:: pool
#
# Author:: Hunter Nield <[email protected]>
#
# Copyright 2013, Hunter Nield
#
# 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.
#

def whyrun_supported?
true
end

action :create do
converge_by("Creating pool '#{new_resource.name}'") do
execute "create pool" do
not_if "rados lspools | grep #{new_resource.name}"
command("rados mkpool #{new_resource.name}")
Copy link
Member

Choose a reason for hiding this comment

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

We'd rather use ceph osd pool create pool pg_num and ceph osd lspools.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll update. Is there a difference in how the pools are created by the two different commands?

Copy link
Member

Choose a reason for hiding this comment

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

Not to my knowledge, it's just that the rados command is starting to get deprecated in favor of the ceph one.

end
Chef::Log.info("Created` pool '#{new_resource.name}'")
end
end

action :delete do

converge_by("Deleting pool '#{new_resource.name}'") do
Copy link
Contributor

Choose a reason for hiding this comment

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

converge_by is useless here because your are only using only chef resources :)

It's the same for action :create

Copy link
Contributor

Choose a reason for hiding this comment

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

ok forget it, It can be better to keep it :)

execute "delete pool" do
only_if "rados lspools | grep #{new_resource.name}"
if new_resource.force == true
command("rados rmpool #{new_resource.name} #{new_resource.name} --yes-i-really-really-mean-it")
Copy link
Member

Choose a reason for hiding this comment

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

ceph osd pool delete pool pool --yes-i-really-really-mean-it

else
command("rados rmpool #{new_resource.name}")
end
Chef::Log.info("Deleted pool '#{new_resource.name}'")
end
end
end
89 changes: 89 additions & 0 deletions providers/rbd_image.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#
# Cookbook Name:: ceph
# Provider:: rbd_image
#
# Author:: Hunter Nield <[email protected]>
#
# Copyright 2013, Hunter Nield
#
# 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.
#

def whyrun_supported?
true
end


action :create do

converge_by("Creating block device '#{new_resource.name}' of #{new_resource.size}MB") do
if new_resource.pool
pool = "-p #{new_resource.pool}"
end

execute "create rbd image" do
not_if "rbd #{pool} ls | grep #{new_resource.name}"
Copy link
Member

Choose a reason for hiding this comment

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

you could use rbd info name instead. This will avoid to list everything.

command("rbd create #{pool} --size #{new_resource.size} #{new_resource.name}")
end
Chef::Log.info("Created block device '#{new_resource.name}' of #{new_resource.size}MB")
end

end

action :delete do

converge_by("Deleting block device '#{new_resource.name}'") do
if new_resource.pool
pool = "-p #{new_resource.pool}"
end

execute "create rbd image" do
only_if "rbd #{pool} ls | grep #{new_resource.name}"
Copy link
Member

Choose a reason for hiding this comment

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

same as above

command("rbd rm #{pool} #{new_resource.name}")
end
Chef::Log.info("Deleted block device '#{new_resource.name}'")
end

end

action :map do
Copy link
Member

Choose a reason for hiding this comment

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

This should also make sure the rbd kernel object is loaded


converge_by("Mapping block device '#{new_resource.name}'") do
if new_resource.pool
pool = "-p #{new_resource.pool}"
end

execute "map rbd image" do
not_if "rbd #{pool} showmapped | grep #{new_resource.name}"
command("rbd map #{pool} #{new_resource.name}")
end
Chef::Log.info("Mapped block device '#{new_resource.name}'")
end

end

action :unmap do


converge_by("Unmapping block device '#{new_resource.name}' mounted at '#{new_resource.device}'") do
if new_resource.pool
pool = "-p #{new_resource.pool}"
end

execute "unmap rbd image" do
only_if "rbd #{pool} showmapped | grep #{new_resource.device}"
command("rbd unmap #{pool} #{new_resource.device}")
end
Chef::Log.info("Unmapped block device '#{new_resource.name}' mounted at '#{new_resource.device}'")
end
end
26 changes: 26 additions & 0 deletions resources/pool.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Author:: Hunter Nield (<[email protected]>)
# Cookbook Name:: ceph
# Resource:: pool
#
# Copyright 2013, Hunter NIeld
#
# 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.

actions :create, :delete
default_action :create

attribute :name, :kind_of => String,
:name_attribute => true
attribute :force, :kind_of => [ TrueClass, FalseClass ],
:default => false
26 changes: 26 additions & 0 deletions resources/rbd_image.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Author:: Hunter Nield (<[email protected]>)
# Cookbook Name:: ceph
# Resource:: rbd_image
#
# Copyright 2013, Hunter NIeld
#
# 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.

actions :create, :delete, :map, :unmap
default_action :create

attribute :name, :kind_of => String, :name_attribute => true
attribute :pool, :kind_of => String, :default => nil
attribute :size, :kind_of => Fixnum, :default => nil
attribute :device, :kind_of => String, :default => nil