-
Notifications
You must be signed in to change notification settings - Fork 107
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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}") | ||
end | ||
Chef::Log.info("Created` pool '#{new_resource.name}'") | ||
end | ||
end | ||
|
||
action :delete do | ||
|
||
converge_by("Deleting pool '#{new_resource.name}'") do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 |
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.