From 8e56551b11fe28cc4f29f4fcdcf6c38516bdc833 Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Fri, 8 Jun 2012 10:54:34 -0700 Subject: [PATCH] Cleanup: combine ceph::single_mon into ceph::mon. --- ceph/recipes/mon.rb | 112 ++++++++++++++++++++++++++++++------- ceph/recipes/single_mon.rb | 94 ------------------------------- 2 files changed, 93 insertions(+), 113 deletions(-) delete mode 100644 ceph/recipes/single_mon.rb diff --git a/ceph/recipes/mon.rb b/ceph/recipes/mon.rb index 9ec4369..4347e9e 100644 --- a/ceph/recipes/mon.rb +++ b/ceph/recipes/mon.rb @@ -1,20 +1,94 @@ -# -# Author:: Kyle Bader -# Cookbook Name:: ceph -# Recipe:: mon -# -# Copyright 2011, DreamHost Web Hosting -# -# 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. - +# this recipe creates a monitor cluster + +require 'json' + include_recipe "ceph::default" +include_recipe "ceph::conf" + +if is_crowbar? + ipaddress = Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin").address +else + ipaddress = node['ipaddress'] +end + +service "ceph-mon-all-starter" do + provider Chef::Provider::Service::Upstart + action [:enable] +end + +# TODO cluster name +cluster = 'ceph' + +execute 'ceph-mon mkfs' do + command <<-EOH +set -e +# TODO chef creates doesn't seem to suppressing re-runs, do it manually +if [ -e '/var/lib/ceph/mon/ceph-#{node["hostname"]}/done' ]; then + echo 'ceph-mon mkfs already done, skipping' + exit 0 +fi +KR='/var/lib/ceph/tmp/#{cluster}-#{node['hostname']}.mon.keyring' +# TODO don't put the key in "ps" output, stdout +ceph-authtool "$KR" --create-keyring --name=mon. --add-key='#{node["ceph"]["monitor-secret"]}' --cap mon 'allow *' + +ceph-mon --mkfs -i #{node['hostname']} --keyring "$KR" +rm -f -- "$KR" +touch /var/lib/ceph/mon/ceph-#{node['hostname']}/done +EOH + # TODO built-in done-ness flag for ceph-mon? + creates '/var/lib/ceph/mon/ceph-#{node["hostname"]}/done' + notifies :start, "service[ceph-mon-all-starter]", :immediately +end + +ruby_block "create client.admin keyring" do + block do + if not ::File.exists?('/etc/ceph/ceph.client.admin.keyring') then + if not have_quorum? then + puts 'ceph-mon is not in quorum, skipping bootstrap-osd key generation for this run' + else + # TODO --set-uid=0 + key = %x[ + ceph \ + --name mon. \ + --keyring '/var/lib/ceph/mon/#{cluster}-#{node['hostname']}/keyring' \ + auth get-or-create-key client.admin \ + mon 'allow *' \ + osd 'allow *' \ + mds allow + ] + raise 'adding or getting admin key failed' unless $?.exitstatus == 0 + # TODO don't put the key in "ps" output, stdout + system 'ceph-authtool', \ + '/etc/ceph/ceph.client.admin.keyring', \ + '--create-keyring', \ + '--name=client.admin', \ + "--add-key=#{key}" + raise 'creating admin keyring failed' unless $?.exitstatus == 0 + end + end + end +end + +ruby_block "save osd bootstrap key in node attributes" do + block do + if node['ceph_bootstrap_osd_key'].nil? then + if not have_quorum? then + puts 'ceph-mon is not in quorum, skipping bootstrap-osd key generation for this run' + else + key = %x[ + ceph \ + --name mon. \ + --keyring '/var/lib/ceph/mon/#{cluster}-#{node['hostname']}/keyring' \ + auth get-or-create-key client.bootstrap-osd mon \ + "allow command osd create ...; \ + allow command osd crush set ...; \ + allow command auth add * osd allow\\ * mon allow\\ rwx; \ + allow command mon getmap" + ] + raise 'adding or getting bootstrap-osd key failed' unless $?.exitstatus == 0 + node.override['ceph_bootstrap_osd_key'] = key + node.save + end + end + end +end diff --git a/ceph/recipes/single_mon.rb b/ceph/recipes/single_mon.rb deleted file mode 100644 index 028d918..0000000 --- a/ceph/recipes/single_mon.rb +++ /dev/null @@ -1,94 +0,0 @@ -# this recipe creates a monitor cluster - -require 'json' - -include_recipe "ceph::mon" -include_recipe "ceph::conf" - -if is_crowbar? - ipaddress = Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin").address -else - ipaddress = node['ipaddress'] -end - -service "ceph-mon-all-starter" do - provider Chef::Provider::Service::Upstart - action [:enable] -end - -# TODO cluster name -cluster = 'ceph' - -execute 'ceph-mon mkfs' do - command <<-EOH -set -e -# TODO chef creates doesn't seem to suppressing re-runs, do it manually -if [ -e '/var/lib/ceph/mon/ceph-#{node["hostname"]}/done' ]; then - echo 'ceph-mon mkfs already done, skipping' - exit 0 -fi -KR='/var/lib/ceph/tmp/#{cluster}-#{node['hostname']}.mon.keyring' -# TODO don't put the key in "ps" output, stdout -ceph-authtool "$KR" --create-keyring --name=mon. --add-key='#{node["ceph"]["monitor-secret"]}' --cap mon 'allow *' - -ceph-mon --mkfs -i #{node['hostname']} --keyring "$KR" -rm -f -- "$KR" -touch /var/lib/ceph/mon/ceph-#{node['hostname']}/done -EOH - # TODO built-in done-ness flag for ceph-mon? - creates '/var/lib/ceph/mon/ceph-#{node["hostname"]}/done' - notifies :start, "service[ceph-mon-all-starter]", :immediately -end - -ruby_block "create client.admin keyring" do - block do - if not ::File.exists?('/etc/ceph/ceph.client.admin.keyring') then - if not have_quorum? then - puts 'ceph-mon is not in quorum, skipping bootstrap-osd key generation for this run' - else - # TODO --set-uid=0 - key = %x[ - ceph \ - --name mon. \ - --keyring '/var/lib/ceph/mon/#{cluster}-#{node['hostname']}/keyring' \ - auth get-or-create-key client.admin \ - mon 'allow *' \ - osd 'allow *' \ - mds allow - ] - raise 'adding or getting admin key failed' unless $?.exitstatus == 0 - # TODO don't put the key in "ps" output, stdout - system 'ceph-authtool', \ - '/etc/ceph/ceph.client.admin.keyring', \ - '--create-keyring', \ - '--name=client.admin', \ - "--add-key=#{key}" - raise 'creating admin keyring failed' unless $?.exitstatus == 0 - end - end - end -end - -ruby_block "save osd bootstrap key in node attributes" do - block do - if node['ceph_bootstrap_osd_key'].nil? then - if not have_quorum? then - puts 'ceph-mon is not in quorum, skipping bootstrap-osd key generation for this run' - else - key = %x[ - ceph \ - --name mon. \ - --keyring '/var/lib/ceph/mon/#{cluster}-#{node['hostname']}/keyring' \ - auth get-or-create-key client.bootstrap-osd mon \ - "allow command osd create ...; \ - allow command osd crush set ...; \ - allow command auth add * osd allow\\ * mon allow\\ rwx; \ - allow command mon getmap" - ] - raise 'adding or getting bootstrap-osd key failed' unless $?.exitstatus == 0 - node.override['ceph_bootstrap_osd_key'] = key - node.save - end - end - end -end -- 2.47.3