diff --git a/providers/pool.rb b/providers/pool.rb new file mode 100644 index 0000000..60d6b09 --- /dev/null +++ b/providers/pool.rb @@ -0,0 +1,49 @@ +# +# Cookbook Name:: ceph +# Provider:: pool +# +# Author:: Hunter Nield +# +# 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 + 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") + else + command("rados rmpool #{new_resource.name}") + end + Chef::Log.info("Deleted pool '#{new_resource.name}'") + end + end +end \ No newline at end of file diff --git a/providers/rbd_image.rb b/providers/rbd_image.rb new file mode 100644 index 0000000..cca31dc --- /dev/null +++ b/providers/rbd_image.rb @@ -0,0 +1,89 @@ +# +# Cookbook Name:: ceph +# Provider:: rbd_image +# +# Author:: Hunter Nield +# +# 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}" + 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}" + command("rbd rm #{pool} #{new_resource.name}") + end + Chef::Log.info("Deleted block device '#{new_resource.name}'") + end + +end + +action :map do + + 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 diff --git a/resources/pool.rb b/resources/pool.rb new file mode 100644 index 0000000..29c3ad3 --- /dev/null +++ b/resources/pool.rb @@ -0,0 +1,26 @@ +# +# Author:: Hunter Nield () +# 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 \ No newline at end of file diff --git a/resources/rbd_image.rb b/resources/rbd_image.rb new file mode 100644 index 0000000..80a09f6 --- /dev/null +++ b/resources/rbd_image.rb @@ -0,0 +1,26 @@ +# +# Author:: Hunter Nield () +# 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