* version bump to 13.0.0 for mitaka release * removed suse support * removed general endpoint method, since we should be able to always specify which endpoint we need * removed fallbacks in specific_endpoint method, since this behaviour is not a very obvious one to the user and it should rather return an error than an unexpected result * dry public, internal and admin endpoint methods * removed obsolete private methods * adapted method calls for admin_endpoint in libraries/cli.rb * refactored set_endpoints_by_interface recipe to directly call address_for instead of address, since the recipe already checks for an existing attribute ..['bind_interface'] and therefore address would redirect to address_for anyways * moved the nested hash order for the public, internal and admin attributes to to be more clear and to break all existing calls to fix them during the refactoring process of all cookbooks e.g: node['openstack']['endpoints']['internal']['identity'] is now node['openstack']['endpoints']['identity']['internal'] and can be moved into the identity cookbook. This also streamlines these endpoint attributes with the bind_interface and host attributes * removed dependency on openstack-identity cookbooks by moving openrc recipe to opentack-identity (same for corrensponding specs and template) * removed address method and use the address (or hostname) defined in the endpoints hash directly (logic to set this attribute should rather be done in a wrapper (with a fitting method) instead of a static and predefined one) * removed set_endpoints_by_interface recipe since logic for defining the endpoints will be moved to wrapper cookbooks * added helper method merge_config_options for generation of config hashes used in service config templates * added template for openstack-service.conf.erb which can be used by all service cookbooks * deleted all endpoints attibutes, since these are moved to the service cookbooks for easier dependency handling Implements: blueprint cookbook-refactoring Change-Id: I0547182085eed91d05384fdd7734408a839a9a2c
94 lines
2.5 KiB
Ruby
94 lines
2.5 KiB
Ruby
# Provider that uses the database cookbook to create the
|
|
# service's database and grant read/write access to the
|
|
# given user and password.
|
|
#
|
|
# A privileged 'super user' and password is determined from the
|
|
# underlying database cookbooks. For instance, if a MySQL database
|
|
# is used, the node['mysql']['server_root_password'] is used along
|
|
# with the 'root' (super)user.
|
|
|
|
include ::Openstack
|
|
|
|
use_inline_resources if defined?(use_inline_resources)
|
|
|
|
action :create do
|
|
info
|
|
create_db(@db_name, @db_prov, @connection_info, @db_type) # create database
|
|
create_db_user(@user, @user_prov, @connection_info, @pass) # create user
|
|
grant_db_privileges(@user, @user_prov, @connection_info, @pass, @db_name) # grant privileges
|
|
end
|
|
|
|
private
|
|
|
|
def info
|
|
info = node['openstack']['endpoints']['db']
|
|
service_info = db new_resource.service
|
|
@host = service_info['host'] || info['host']
|
|
@port = service_info['port'] || info['port']
|
|
user_key = node['openstack']['db']['root_user_key']
|
|
@super_password = get_password 'user', user_key
|
|
@db_type = service_info['service_type']
|
|
@db_name = service_info['db_name']
|
|
@user = new_resource.user
|
|
@pass = new_resource.pass
|
|
db_types
|
|
connection_info
|
|
end
|
|
|
|
def db_types
|
|
case @db_type
|
|
when 'postgresql', 'pgsql'
|
|
@db_prov = ::Chef::Provider::Database::Postgresql
|
|
@user_prov = ::Chef::Provider::Database::PostgresqlUser
|
|
@super_user = 'postgres'
|
|
when 'mysql', 'mariadb', 'percona-cluster', 'galera'
|
|
@db_prov = ::Chef::Provider::Database::Mysql
|
|
@user_prov = ::Chef::Provider::Database::MysqlUser
|
|
@super_user = 'root'
|
|
else
|
|
fail "Unsupported database type #{@db_type}"
|
|
end
|
|
end
|
|
|
|
def connection_info
|
|
@connection_info = {
|
|
host: @host,
|
|
port: @port.to_i,
|
|
username: @super_user,
|
|
password: @super_password
|
|
}
|
|
end
|
|
|
|
def create_db(db_name, db_prov, connection_info, db_type)
|
|
database "create database #{db_name}" do
|
|
provider db_prov
|
|
connection connection_info
|
|
database_name db_name
|
|
encoding node['openstack']['db']['charset'][db_type]
|
|
action :create
|
|
end
|
|
end
|
|
|
|
def create_db_user(user, user_prov, connection_info, pass)
|
|
database_user "create database user #{user}" do
|
|
provider user_prov
|
|
connection connection_info
|
|
username user
|
|
password pass
|
|
action :create
|
|
end
|
|
end
|
|
|
|
def grant_db_privileges(user, user_prov, connection_info, pass, db_name)
|
|
database_user "grant database user #{user}" do
|
|
provider user_prov
|
|
connection connection_info
|
|
username user
|
|
password pass
|
|
database_name db_name
|
|
host '%'
|
|
privileges [:all]
|
|
action :grant
|
|
end
|
|
end
|