add postgresql support to nova and associated role

This commit is contained in:
Mark Washenberger 2011-04-22 14:16:01 -04:00
parent c89833859d
commit d383047d47
9 changed files with 84 additions and 2 deletions

View File

@ -29,6 +29,7 @@ default[:nova][:my_ip] = ipaddress
default[:nova][:public_interface] = "eth1"
default[:nova][:vlan_interface] = "eth1"
default[:nova][:mysql] = true
default[:nova][:postgresql] = false
default[:nova][:images] = []
default[:nova][:network] = "10.0.0.0/24 8 32"
default[:nova][:floating_range] = "10.128.0.0/24"

View File

@ -11,5 +11,6 @@ depends "mysql"
depends "openldap"
depends "openssl"
depends "python-ldap"
depends "postgresql"
depends "rabbitmq"
depends "runit"

View File

@ -53,6 +53,21 @@ if node[:nova][:mysql]
Chef::Log.info("Using local mysql at #{mysql[:mysql][:bind_address]}")
end
sql_connection = "mysql://#{mysql[:nova][:db][:user]}:#{mysql[:nova][:db][:password]}@#{mysql[:mysql][:bind_address]}/#{mysql[:nova][:db][:database]}"
elsif node[:nova][:postgresql]
Chef::Log.info("Using postgresql")
postgresqls = nil
unless Chef::Config[:solo]
postgresqls = search(:node, "recipes:nova\\:\\:postgresql#{env_filter}")
end
if postgresqls and postgresqls[0]
postgresql = postgresqls[0]
Chef::Log.info("PostgreSQL server found at #{postgresql[:ipaddress]}")
else
postgresql = node
Chef::Log.info("Using local PostgreSQL at #{postgresql[:ipaddress]}")
end
sql_connection = "postgresql://#{postgresql[:nova][:db][:user]}:#{postgresql[:nova][:db][:password]}@#{postgresql[:ipaddress]}/#{postgresql[:nova][:db][:database]}"
end
rabbits = nil

View File

@ -0,0 +1,36 @@
#
# Cookbook Name:: nova
# Recipe:: postgresql
#
Chef::Log.info("PostgreSQL recipe included")
package "python-psycopg2"
bash "postgresql-grant-nova-user-privileges" do
code <<-EOH
echo "GRANT ALL ON DATABASE #{node[:nova][:db][:database]} TO #{node[:nova][:db][:user]}" | su - postgres -c psql
EOH
action :nothing
end
bash "postgresql-create-nova-user" do
code <<-EOH
echo "CREATE USER #{node[:nova][:db][:user]} WITH PASSWORD '#{node[:nova][:db][:password]}'" | su - postgres -c psql
EOH
action :nothing
notifies :run, "bash[postgresql-grant-nova-user-privileges]", :immediately
end
bash "postgresql-create-nova-db" do
code <<-EOH
echo "CREATE DATABASE #{node[:nova][:db][:database]}" | su - postgres -c psql
EOH
notifies :run, "bash[postgresql-create-nova-user]", :immediately
end
# save data so it can be found by search
unless Chef::Config[:solo]
Chef::Log.info("Saving node data")
node.save
end

View File

@ -66,3 +66,5 @@ else
default[:postgresql][:version] = "8.4"
set[:postgresql][:dir] = "/etc/postgresql/#{node[:postgresql][:version]}/main"
end
default[:postgresql][:hba_records] = []

View File

@ -38,6 +38,9 @@ template "#{node[:postgresql][:dir]}/pg_hba.conf" do
owner "postgres"
group "postgres"
mode 0600
variables(
:records => node[:postgresql][:hba_records]
)
notifies :reload, resources(:service => "postgresql")
end
@ -46,5 +49,5 @@ template "#{node[:postgresql][:dir]}/postgresql.conf" do
owner "postgres"
group "postgres"
mode 0600
notifies :restart, resources(:service => "postgresql")
notifies :restart, resources(:service => "postgresql"), :immediately
end

View File

@ -81,3 +81,8 @@ local all all ident
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Chef-defined records
<% for @record in @records %>
<%= @record %>
<% end %>

View File

@ -53,7 +53,7 @@ external_pid_file = '/var/run/postgresql/<%= node.postgresql.version -%>-main.pi
# - Connection Settings -
#listen_addresses = 'localhost' # what IP address(es) to listen on;
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost', '*' = all
# (change requires restart)

View File

@ -0,0 +1,19 @@
name "nova-postgresql-server"
description "PostgreSQL server for Nova"
run_list(
"recipe[postgresql::server]",
"recipe[nova::postgresql]"
)
default_attributes(
"nova" => {
"mysql" => false,
"postgresql" => true
},
"postgresql" => {
"hba_records" => [
"host all all 0.0.0.0/0 md5"
]
}
)