diff --git a/packstack/plugins/mysql_003.py b/packstack/plugins/mysql_003.py index a0b625649..84d7f8277 100644 --- a/packstack/plugins/mysql_003.py +++ b/packstack/plugins/mysql_003.py @@ -86,13 +86,13 @@ def initSequences(controller): def create_manifest(config, messages): if config['CONFIG_MYSQL_INSTALL'] == 'y': - install = True suffix = 'install' + host = config['CONFIG_MYSQL_HOST'] else: - install = False suffix = 'noinstall' + host = config['CONFIG_CONTROLLER_HOST'] - manifestfile = "%s_mysql.pp" % config['CONFIG_MYSQL_HOST'] + manifestfile = "%s_mysql.pp" % host manifestdata = [getManifestTemplate('mysql_%s.pp' % suffix)] def append_for(module, suffix): diff --git a/packstack/plugins/puppet_950.py b/packstack/plugins/puppet_950.py index c8c1c5640..9fefc6b2a 100644 --- a/packstack/plugins/puppet_950.py +++ b/packstack/plugins/puppet_950.py @@ -160,9 +160,9 @@ def copy_puppet_modules(config, messages): 'concat', 'firewall', 'glance', 'heat', 'horizon', 'inifile', 'keystone', 'memcached', 'mongodb', 'mysql', 'neutron', 'nova', 'nssdb', 'openstack', - 'packstack', 'qpid', 'rabbitmq', 'rsync', 'ssh', - 'stdlib', 'swift', 'sysctl', 'tempest', 'vcsrepo', - 'vlan', 'vswitch', 'xinetd')) + 'packstack', 'qpid', 'rabbitmq', 'remote', 'rsync', + 'ssh', 'stdlib', 'swift', 'sysctl', 'tempest', + 'vcsrepo', 'vlan', 'vswitch', 'xinetd')) # write puppet manifest to disk manifestfiles.writeManifests() diff --git a/packstack/puppet/modules/packstack/lib/puppet/provider/remote_database/mysql.rb b/packstack/puppet/modules/packstack/lib/puppet/provider/remote_database/mysql.rb deleted file mode 100644 index 08a7c9da3..000000000 --- a/packstack/puppet/modules/packstack/lib/puppet/provider/remote_database/mysql.rb +++ /dev/null @@ -1,47 +0,0 @@ -Puppet::Type.type(:remote_database).provide(:mysql) do - - desc "Manages remote MySQL database." - - defaultfor :kernel => 'Linux' - - optional_commands :mysql => 'mysql' - optional_commands :mysqladmin => 'mysqladmin' - - def self.instances - mysql("--host=#{@resource[:db_host]}", "--user=#{@resource[:db_user]}", - "--password=#{@resource[:db_password]}", '-NBe', "show databases").split("\n").collect do |name| - new(:name => name) - end - end - - def create - mysql("--host=#{@resource[:db_host]}", "--user=#{@resource[:db_user]}", - "--password=#{@resource[:db_password]}", '-NBe', "create database `#{@resource[:name]}` character set #{resource[:charset]}") - end - - def destroy - mysqladmin("--host=#{@resource[:db_host]}", "--user=#{@resource[:db_user]}", - "--password=#{@resource[:db_password]}", '-f', 'drop', @resource[:name]) - end - - def charset - mysql("--host=#{@resource[:db_host]}", "--user=#{@resource[:db_user]}", - "--password=#{@resource[:db_password]}", '-NBe', "show create database `#{resource[:name]}`").match(/.*?(\S+)\s\*\//)[1] - end - - def charset=(value) - mysql("--host=#{@resource[:db_host]}", "--user=#{@resource[:db_user]}", - "--password=#{@resource[:db_password]}", '-NBe', "alter database `#{resource[:name]}` CHARACTER SET #{value}") - end - - def exists? - begin - mysql("--host=#{@resource[:db_host]}", "--user=#{@resource[:db_user]}", - "--password=#{@resource[:db_password]}", '-NBe', "show databases").match(/^#{@resource[:name]}$/) - rescue => e - debug(e.message) - return nil - end - end - -end diff --git a/packstack/puppet/modules/remote/lib/puppet/provider/remote_database/mysql.rb b/packstack/puppet/modules/remote/lib/puppet/provider/remote_database/mysql.rb new file mode 100644 index 000000000..fe14d723c --- /dev/null +++ b/packstack/puppet/modules/remote/lib/puppet/provider/remote_database/mysql.rb @@ -0,0 +1,99 @@ +Puppet::Type.type(:remote_database).provide(:mysql) do + + desc "Manages remote MySQL database." + + defaultfor :kernel => 'Linux' + + optional_commands :mysql => 'mysql' + optional_commands :mysqladmin => 'mysqladmin' + + def self.instances + mysql( + "--host=#{@resource[:db_host]}", + "--user=#{@resource[:db_user]}", + "--password=#{@resource[:db_password]}", + "-NBe", + "show databases" + ).split("\n").collect do |name| + new(:name => name) + end + end + + def create + mysql( + "--host=#{@resource[:db_host]}", + "--user=#{@resource[:db_user]}", + "--password=#{@resource[:db_password]}", + "-NBe", + "create database `#{@resource[:name]}` + character set #{@resource[:charset]} + collate #{@resource[:collate]}" + ) + end + + def destroy + mysqladmin( + "--host=#{@resource[:db_host]}", + "--user=#{@resource[:db_user]}", + "--password=#{@resource[:db_password]}", + '-f', + 'drop', @resource[:name] + ) + end + + def charset + mysql( + "--host=#{@resource[:db_host]}", + "--user=#{@resource[:db_user]}", + "--password=#{@resource[:db_password]}", + "-NBe", + "show create database `#{resource[:name]}`").match(/.*?(\S+)\s\*\// + )[1] + end + + def charset=(value) + mysql( + "--host=#{@resource[:db_host]}", + "--user=#{@resource[:db_user]}", + "--password=#{@resource[:db_password]}", + "-NBe", + "alter database `#{resource[:name]}` character set #{value}" + ) + end + + def collate + mysql( + "--host=#{@resource[:db_host]}", + "--user=#{@resource[:db_user]}", + "--password=#{@resource[:db_password]}", + "-NBe", + "use #{resource[:name]}; show variables like 'collation_database'" + ).match(/\s*collation_database\s+(\S+)/)[1] + end + + def collate=(value) + mysql( + "--host=#{@resource[:db_host]}", + "--user=#{@resource[:db_user]}", + "--password=#{@resource[:db_password]}", + "-NBe", + "alter database `#{resource[:name]}` collate #{value}" + ) + end + + def exists? + begin + mysql( + "--host=#{@resource[:db_host]}", + "--user=#{@resource[:db_user]}", + "--password=#{@resource[:db_password]}", + "-NBe", + "show databases" + ).match(/^#{@resource[:name]}$/) + rescue => e + debug(e.message) + return nil + end + end + +end diff --git a/packstack/puppet/modules/packstack/lib/puppet/provider/remote_database_grant/mysql.rb b/packstack/puppet/modules/remote/lib/puppet/provider/remote_database_grant/mysql.rb similarity index 100% rename from packstack/puppet/modules/packstack/lib/puppet/provider/remote_database_grant/mysql.rb rename to packstack/puppet/modules/remote/lib/puppet/provider/remote_database_grant/mysql.rb diff --git a/packstack/puppet/modules/packstack/lib/puppet/provider/remote_database_user/mysql.rb b/packstack/puppet/modules/remote/lib/puppet/provider/remote_database_user/mysql.rb similarity index 100% rename from packstack/puppet/modules/packstack/lib/puppet/provider/remote_database_user/mysql.rb rename to packstack/puppet/modules/remote/lib/puppet/provider/remote_database_user/mysql.rb diff --git a/packstack/puppet/modules/packstack/lib/puppet/type/remote_database.rb b/packstack/puppet/modules/remote/lib/puppet/type/remote_database.rb similarity index 81% rename from packstack/puppet/modules/packstack/lib/puppet/type/remote_database.rb rename to packstack/puppet/modules/remote/lib/puppet/type/remote_database.rb index ac272cd3c..ea6a0c8b9 100644 --- a/packstack/puppet/modules/packstack/lib/puppet/type/remote_database.rb +++ b/packstack/puppet/modules/remote/lib/puppet/type/remote_database.rb @@ -26,4 +26,10 @@ Puppet::Type.newtype(:remote_database) do newvalue(/^\S+$/) end + newproperty(:collate) do + desc 'The collate setting for the database' + defaultto :utf8_general_ci + newvalue(/^\S+$/) + end + end diff --git a/packstack/puppet/modules/packstack/lib/puppet/type/remote_database_grant.rb b/packstack/puppet/modules/remote/lib/puppet/type/remote_database_grant.rb similarity index 100% rename from packstack/puppet/modules/packstack/lib/puppet/type/remote_database_grant.rb rename to packstack/puppet/modules/remote/lib/puppet/type/remote_database_grant.rb diff --git a/packstack/puppet/modules/packstack/lib/puppet/type/remote_database_user.rb b/packstack/puppet/modules/remote/lib/puppet/type/remote_database_user.rb similarity index 100% rename from packstack/puppet/modules/packstack/lib/puppet/type/remote_database_user.rb rename to packstack/puppet/modules/remote/lib/puppet/type/remote_database_user.rb diff --git a/packstack/puppet/modules/remote/manifests/db.pp b/packstack/puppet/modules/remote/manifests/db.pp new file mode 100644 index 000000000..28eaafbfb --- /dev/null +++ b/packstack/puppet/modules/remote/manifests/db.pp @@ -0,0 +1,15 @@ + +class remote::db ( + $mysql_client_package = $remote::params::mysql_client_package, + $mysql_client_package_ensure = 'present', +) inherits remote::params { + + package { $mysql_client_package: + ensure => $mysql_client_package_ensure, + } + + Package[$mysql_client_package] -> Remote_database<||> + Package[$mysql_client_package] -> Remote_database_user<||> + Package[$mysql_client_package] -> Remote_database_grant<||> + +} diff --git a/packstack/puppet/modules/remote/manifests/params.pp b/packstack/puppet/modules/remote/manifests/params.pp new file mode 100644 index 000000000..ce1909cf9 --- /dev/null +++ b/packstack/puppet/modules/remote/manifests/params.pp @@ -0,0 +1,38 @@ + +class remote::params { + + case $::osfamily { + 'RedHat': { + case $::operatingsystem { + + 'Fedora': { + if (is_integer($::operatingsystemrelease) and $::operatingsystemrelease >= 19) or $::operatingsystemrelease == 'Rawhide' { + $mysql_client_package = 'mariadb' + } else { + $mysql_client_package = 'mysql' + } + } + + 'RedHat', 'CentOS', 'Scientific': { + if $::operatingsystemmajrelease >= 7 { + $mysql_client_package = 'mariadb' + } else { + $mysql_client_package = 'mysql' + } + } + + default: { + $mysql_client_package = 'mysql' + } + } + } + + 'Debian': { + $mysql_client_package = 'mysql' + } + + default: { + fail("Unsupported platform") + } + } +} diff --git a/packstack/puppet/templates/mysql_noinstall.pp b/packstack/puppet/templates/mysql_noinstall.pp index 69356c573..626ee88fa 100644 --- a/packstack/puppet/templates/mysql_noinstall.pp +++ b/packstack/puppet/templates/mysql_noinstall.pp @@ -1,8 +1,3 @@ -package { 'mysql': - ensure => 'present', +class { 'remote::db': } - -Package ['mysql'] -> Remote_database<||> -Package ['mysql'] -> Remote_database_user<||> -Package ['mysql'] -> Remote_database_grant<||> diff --git a/setup.py b/setup.py index af7ca3058..4d8e65b4f 100644 --- a/setup.py +++ b/setup.py @@ -56,13 +56,18 @@ class InstallModulesCommand(Command): out, err = proc.communicate() if proc.returncode: raise RuntimeError('Failed:\n%s' % err) - # install Packstack module - packstack_path = os.path.join(self.destination, 'packstack') - print 'Copying Packstack module to %(packstack_path)s' % locals() - source = os.path.join(os.path.dirname(__file__), - 'packstack/puppet/modules/packstack') - shutil.rmtree(packstack_path, ignore_errors=True) - shutil.copytree(source, packstack_path) + # install Packstack modules + module_source = os.path.join(os.path.dirname(__file__), + 'packstack/puppet/modules') + for module in os.listdir(module_source): + source = os.path.join(module_source, module) + if not os.path.isdir(source): + continue + + dest = os.path.join(self.destination, module) + print 'Copying module %(module)s to %(dest)s' % locals() + shutil.rmtree(dest, ignore_errors=True) + shutil.copytree(source, dest) # Utility function to read the README file.