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