15 rubocop left... good! :)
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
require 'ipaddr'
|
||||
require 'json'
|
||||
|
||||
def is_crowbar?
|
||||
def crowbar?
|
||||
!defined?(Chef::Recipe::Barclamp).nil?
|
||||
end
|
||||
|
||||
def get_mon_nodes(extra_search=nil)
|
||||
if is_crowbar?
|
||||
def get_mon_nodes(extra_search = nil)
|
||||
if crowbar?
|
||||
mon_roles = search(:role, 'name:crowbar-* AND run_list:role\[ceph-mon\]')
|
||||
if not mon_roles.empty?
|
||||
unless mon_roles.empty?
|
||||
search_string = mon_roles.map { |role_object| "roles:" + role_object.name }.join(' OR ')
|
||||
search_string = "(#{search_string}) AND ceph_config_environment:#{node['ceph']['config']['environment']}"
|
||||
end
|
||||
@@ -28,7 +28,7 @@ end
|
||||
# 1. We look if the network is IPv6 or IPv4
|
||||
# 2. We look for a route matching the network
|
||||
# 3. We grab the IP and return it with the port
|
||||
def find_node_ip_in_network(network, nodeish=nil)
|
||||
def find_node_ip_in_network(network, nodeish = nil)
|
||||
nodeish = node unless nodeish
|
||||
net = IPAddr.new(network)
|
||||
nodeish["network"]["interfaces"].each do |iface, addrs|
|
||||
@@ -43,11 +43,11 @@ def find_node_ip_in_network(network, nodeish=nil)
|
||||
nil
|
||||
end
|
||||
|
||||
def get_mon_addresses
|
||||
def mon_addresses
|
||||
mon_ips = []
|
||||
|
||||
if File.exists?("/var/run/ceph/ceph-mon.#{node['hostname']}.asok")
|
||||
mon_ips = get_quorum_members_ips
|
||||
mon_ips = quorum_members_ips
|
||||
else
|
||||
mons = []
|
||||
# make sure if this node runs ceph-mon, it's always included even if
|
||||
@@ -56,7 +56,7 @@ def get_mon_addresses
|
||||
mons << node if node['ceph']['is_mon']
|
||||
|
||||
mons += get_mon_nodes
|
||||
if is_crowbar?
|
||||
if crowbar?
|
||||
mon_ips = mons.map { |node| Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin").address }
|
||||
else
|
||||
if node['ceph']['config']['global'] && node['ceph']['config']['global']['public network']
|
||||
@@ -69,7 +69,7 @@ def get_mon_addresses
|
||||
mon_ips.reject { |m| m.nil? }.uniq
|
||||
end
|
||||
|
||||
def get_quorum_members_ips
|
||||
def quorum_members_ips
|
||||
mon_ips = []
|
||||
cmd = Mixlib::ShellOut.new("ceph --admin-daemon /var/run/ceph/ceph-mon.#{node['hostname']}.asok mon_status")
|
||||
cmd.run_command
|
||||
|
||||
@@ -5,7 +5,7 @@ end
|
||||
action :add do
|
||||
filename = @current_resource.filename
|
||||
keyname = @current_resource.keyname
|
||||
caps = @new_resource.caps.map{|k,v| "#{k} '#{v}'"}.join(' ')
|
||||
caps = @new_resource.caps.map { |k, v| "#{k} '#{v}'" }.join(' ')
|
||||
if @current_resource.exists
|
||||
Chef::Log.info "#{ @new_resource} already exists - nothing to do"
|
||||
else
|
||||
@@ -22,7 +22,7 @@ action :add do
|
||||
if get_saved_key_file(@current_resource.filename) != get_new_content.call(keyname)
|
||||
converge_by("save ceph auth key to #{filename}") do
|
||||
file filename do
|
||||
content lazy {get_new_content.call(keyname)}
|
||||
content lazy { get_new_content.call(keyname) }
|
||||
owner "root"
|
||||
group "root"
|
||||
mode "640"
|
||||
@@ -45,7 +45,7 @@ def load_current_resource
|
||||
get_new_content = method(:get_new_key)
|
||||
@current_resource.filename(@new_resource.filename || "/etc/ceph/ceph.client.#{current_resource.name}.#{node['hostname']}.secret")
|
||||
end
|
||||
if @current_resource.caps == @new_resource.caps and
|
||||
if @current_resource.caps == @new_resource.caps &&
|
||||
get_saved_key_file(@current_resource.filename) == get_new_content.call(@current_resource.keyname)
|
||||
@current_resource.exists = true
|
||||
end
|
||||
@@ -80,26 +80,24 @@ end
|
||||
def auth_set_key(keyname, caps)
|
||||
# find the monitor secret
|
||||
mon_secret = ""
|
||||
mons = get_mon_nodes()
|
||||
if not mons.empty?
|
||||
mons = get_mon_nodes
|
||||
if !mons.empty?
|
||||
mon_secret = mons[0]["ceph"]["monitor-secret"]
|
||||
elsif mons.empty? and node["ceph"]["monitor-secret"]
|
||||
elsif mons.empty? && node["ceph"]["monitor-secret"]
|
||||
mon_secret = node["ceph"]["monitor-secret"]
|
||||
else
|
||||
Chef::Log.warn("No monitor secret found")
|
||||
end
|
||||
# try to add the key
|
||||
set_cmd = "ceph auth get-or-create #{keyname} #{caps} --name mon. --key='#{mon_secret}'"
|
||||
set_cmd = Mixlib::ShellOut.new(set_cmd)
|
||||
cmd = set_cmd.run_command
|
||||
if cmd.stderr.scan(/EINVAL.*but cap.*does not match/)
|
||||
cmd = "ceph auth get-or-create #{keyname} #{caps} --name mon. --key='#{mon_secret}'"
|
||||
get_or_create = Mixlib::ShellOut.new(cmd)
|
||||
get_or_create.run_command
|
||||
if get_or_create.stderr.scan(/EINVAL.*but cap.*does not match/)
|
||||
Chef::Log.info("Deleting old key with incorrect caps")
|
||||
# delete an old key if it exists and is wrong
|
||||
Mixlib::ShellOut.new("ceph auth del #{keyname}").run_command
|
||||
# try to create again
|
||||
set_cmd = "ceph auth get-or-create #{keyname} #{caps} --name mon. --key='#{mon_secret}'"
|
||||
set_cmd = Mixlib::ShellOut.new(set_cmd)
|
||||
cmd = set_cmd.run_command
|
||||
get_or_create.run_command
|
||||
end
|
||||
cmd = set_cmd.error!
|
||||
get_or_create.error!
|
||||
end
|
||||
|
||||
@@ -29,7 +29,7 @@ ceph_client name do
|
||||
as_keyring false
|
||||
end
|
||||
|
||||
mons = get_mon_addresses.join(",") + ":/"
|
||||
mons = mon_addresses.join(",") + ":/"
|
||||
|
||||
directory node['ceph']['cephfs_mount']
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
fail "fsid must be set in config" if node["ceph"]["config"]['fsid'].nil?
|
||||
fail "mon_initial_members must be set in config" if node["ceph"]["config"]['mon_initial_members'].nil?
|
||||
|
||||
mon_addresses = get_mon_addresses
|
||||
|
||||
is_rgw = node['roles'].include?('ceph-radosgw')
|
||||
|
||||
directory "/etc/ceph" do
|
||||
|
||||
@@ -67,6 +67,6 @@ service "ceph_mds" do
|
||||
else
|
||||
service_name "ceph"
|
||||
end
|
||||
action [ :enable, :start ]
|
||||
action [:enable, :start]
|
||||
supports :restart => true
|
||||
end
|
||||
|
||||
@@ -37,17 +37,17 @@ directory "/var/lib/ceph/mon/ceph-#{node["hostname"]}" do
|
||||
action :create
|
||||
end
|
||||
|
||||
# TODO cluster name
|
||||
# TODO: cluster name
|
||||
cluster = 'ceph'
|
||||
|
||||
unless File.exists?("/var/lib/ceph/mon/ceph-#{node["hostname"]}/done")
|
||||
keyring = "#{Chef::Config[:file_cache_path]}/#{cluster}-#{node['hostname']}.mon.keyring"
|
||||
|
||||
monitor_secret = if node['ceph']['encrypted_data_bags']
|
||||
if node['ceph']['encrypted_data_bags']
|
||||
secret = Chef::EncryptedDataBagItem.load_secret(node["ceph"]["mon"]["secret_file"])
|
||||
Chef::EncryptedDataBagItem.load("ceph", "mon", secret)["secret"]
|
||||
monitor_secret = Chef::EncryptedDataBagItem.load("ceph", "mon", secret)["secret"]
|
||||
else
|
||||
node["ceph"]["monitor-secret"]
|
||||
monitor_secret = node["ceph"]["monitor-secret"]
|
||||
end
|
||||
|
||||
execute "format as keyring" do
|
||||
@@ -62,7 +62,7 @@ unless File.exists?("/var/lib/ceph/mon/ceph-#{node["hostname"]}/done")
|
||||
ruby_block "finalise" do
|
||||
block do
|
||||
["done", service_type].each do |ack|
|
||||
File.open("/var/lib/ceph/mon/ceph-#{node["hostname"]}/#{ack}", "w").close()
|
||||
::File.open("/var/lib/ceph/mon/ceph-#{node["hostname"]}/#{ack}", "w").close
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -76,7 +76,7 @@ if service_type == "upstart"
|
||||
service "ceph-mon-all" do
|
||||
provider Chef::Provider::Service::Upstart
|
||||
supports :status => true
|
||||
action [ :enable, :start ]
|
||||
action [:enable, :start]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -89,10 +89,10 @@ service "ceph_mon" do
|
||||
service_name "ceph"
|
||||
end
|
||||
supports :restart => true, :status => true
|
||||
action [ :enable, :start ]
|
||||
action [:enable, :start]
|
||||
end
|
||||
|
||||
get_mon_addresses().each do |addr|
|
||||
mon_addresses.each do |addr|
|
||||
execute "peer #{addr}" do
|
||||
command "ceph --admin-daemon '/var/run/ceph/ceph-mon.#{node['hostname']}.asok' add_bootstrap_peer_hint #{addr}"
|
||||
ignore_failure true
|
||||
|
||||
@@ -71,7 +71,7 @@ else
|
||||
creates "/var/lib/ceph/bootstrap-osd/#{cluster}.keyring"
|
||||
end
|
||||
|
||||
if is_crowbar?
|
||||
if crowbar?
|
||||
ruby_block "select new disks for ceph osd" do
|
||||
block do
|
||||
do_trigger = false
|
||||
@@ -81,7 +81,7 @@ else
|
||||
|
||||
system 'ceph-disk-prepare', \
|
||||
"/dev/#{disk}"
|
||||
raise 'ceph-disk-prepare failed' unless $?.exitstatus == 0
|
||||
fail 'ceph-disk-prepare failed' unless $?.exitstatus == 0
|
||||
|
||||
do_trigger = true
|
||||
|
||||
@@ -95,7 +95,7 @@ else
|
||||
"trigger", \
|
||||
"--subsystem-match=block", \
|
||||
"--action=add"
|
||||
raise 'udevadm trigger failed' unless $?.exitstatus == 0
|
||||
fail 'udevadm trigger failed' unless $?.exitstatus == 0
|
||||
end
|
||||
|
||||
end
|
||||
@@ -110,16 +110,15 @@ else
|
||||
# osd/$cluster-$id)
|
||||
# - $cluster should always be ceph
|
||||
# - The --dmcrypt option will be available starting w/ Cuttlefish
|
||||
unless node["ceph"]["osd_devices"].nil?
|
||||
node["ceph"]["osd_devices"].each_with_index do |osd_device,index|
|
||||
if !osd_device["status"].nil?
|
||||
if !node["ceph"]["osd_devices"].nil?
|
||||
node["ceph"]["osd_devices"].each_with_index do |osd_device, index|
|
||||
unless osd_device["status"].nil?
|
||||
Log.info("osd: osd_device #{osd_device} has already been setup.")
|
||||
next
|
||||
end
|
||||
dmcrypt = ""
|
||||
if osd_device["encrypted"] == true
|
||||
dmcrypt = "--dmcrypt"
|
||||
end
|
||||
|
||||
dmcrypt = osd_device["encrypted"] == true ? "--dmcrypt" : ""
|
||||
|
||||
create_cmd = "ceph-disk-prepare #{dmcrypt} #{osd_device['device']} #{osd_device['journal']}"
|
||||
if osd_device["type"] == "directory"
|
||||
directory osd_device["device"] do
|
||||
@@ -154,7 +153,7 @@ else
|
||||
else
|
||||
service_name "ceph"
|
||||
end
|
||||
action [ :enable, :start ]
|
||||
action [:enable, :start]
|
||||
supports :restart => true
|
||||
end
|
||||
else
|
||||
|
||||
@@ -29,7 +29,7 @@ when "debian"
|
||||
}
|
||||
packages += packages_dbg
|
||||
end
|
||||
when "rhel","fedora","suse"
|
||||
when "rhel", "fedora", "suse"
|
||||
packages = %w{
|
||||
ceph-radosgw
|
||||
}
|
||||
@@ -43,13 +43,13 @@ end
|
||||
|
||||
include_recipe "ceph::conf"
|
||||
|
||||
unless File.exists?("/var/lib/ceph/radosgw/ceph-radosgw.#{node['hostname']}/done")
|
||||
if !::File.exists?("/var/lib/ceph/radosgw/ceph-radosgw.#{node['hostname']}/done")
|
||||
if node["ceph"]["radosgw"]["webserver_companion"]
|
||||
include_recipe "ceph::radosgw_#{node["ceph"]["radosgw"]["webserver_companion"]}"
|
||||
end
|
||||
|
||||
ceph_client "radosgw" do
|
||||
caps ({"mon" => "allow rw", "osd" => "allow rwx"})
|
||||
caps ({ "mon" => "allow rw", "osd" => "allow rwx" })
|
||||
end
|
||||
|
||||
file "/var/lib/ceph/radosgw/ceph-radosgw.#{node['hostname']}/done" do
|
||||
@@ -69,7 +69,7 @@ unless File.exists?("/var/lib/ceph/radosgw/ceph-radosgw.#{node['hostname']}/done
|
||||
end
|
||||
end
|
||||
supports :restart => true
|
||||
action [ :enable, :start ]
|
||||
action [:enable, :start]
|
||||
end
|
||||
else
|
||||
Log.info("Rados Gateway already deployed")
|
||||
|
||||
@@ -12,8 +12,8 @@ when "rhel"
|
||||
end
|
||||
|
||||
branch = node['ceph']['branch']
|
||||
if branch == "dev" and platform_family != "centos" and platform_family != "fedora"
|
||||
raise "Dev branch for #{platform_family} is not yet supported"
|
||||
if branch == "dev" && platform_family != "centos" && platform_family != "fedora"
|
||||
fail "Dev branch for #{platform_family} is not yet supported"
|
||||
end
|
||||
|
||||
repo = node['ceph'][platform_family][branch]['repository']
|
||||
@@ -31,7 +31,7 @@ if branch == "dev"
|
||||
"gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CEPH\n" \
|
||||
"EOF\n"
|
||||
else
|
||||
#This is a stable or testing branch
|
||||
# This is a stable or testing branch
|
||||
system "rpm -U #{node['ceph'][platform_family][branch]['repository']}"
|
||||
end
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@ when "debian"
|
||||
packages = %w{
|
||||
tgt
|
||||
}
|
||||
|
||||
when "rhel","fedora"
|
||||
when "rhel", "fedora"
|
||||
packages = %w{
|
||||
scsi-target-utils
|
||||
}
|
||||
@@ -46,5 +45,5 @@ service "tgt" do
|
||||
service_name "tgt"
|
||||
end
|
||||
supports :restart => true
|
||||
action [ :enable, :start ]
|
||||
action [:enable, :start]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user