diff options
author | root <root@puppetmaster.black.co.at> | 2007-10-10 17:23:20 +0200 |
---|---|---|
committer | root <root@puppetmaster.black.co.at> | 2007-10-10 17:23:20 +0200 |
commit | d33c7aa10e3a4bd9e97e947c471ee3ed36e9d1e2 (patch) | |
tree | ce6a9ac08f46ab845eda0c7a77d1a3f4dd670d86 | |
parent | 9a22e7d41a84ec2585b6b7200f8fd08c3b46a04c (diff) | |
download | puppet-mysql-d33c7aa10e3a4bd9e97e947c471ee3ed36e9d1e2.tar.gz puppet-mysql-d33c7aa10e3a4bd9e97e947c471ee3ed36e9d1e2.tar.xz puppet-mysql-d33c7aa10e3a4bd9e97e947c471ee3ed36e9d1e2.zip |
mysql: implement native types and test them
-rw-r--r-- | manifests/init.pp | 4 | ||||
-rw-r--r-- | plugins/puppet/provider/mysql_database/mysql.rb | 20 | ||||
-rw-r--r-- | plugins/puppet/provider/mysql_user/mysql.rb | 19 | ||||
-rw-r--r-- | plugins/puppet/type/mysql_database.rb | 9 | ||||
-rw-r--r-- | plugins/puppet/type/mysql_user.rb | 15 |
5 files changed, 67 insertions, 0 deletions
diff --git a/manifests/init.pp b/manifests/init.pp index 6765733..6899c09 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -18,4 +18,8 @@ class mysql::server { require => Package["mysql-server"], } + # Collect all databases and users + Mysql_database<<||>> + Mysql_user<<||>> + } diff --git a/plugins/puppet/provider/mysql_database/mysql.rb b/plugins/puppet/provider/mysql_database/mysql.rb new file mode 100644 index 0000000..b12d042 --- /dev/null +++ b/plugins/puppet/provider/mysql_database/mysql.rb @@ -0,0 +1,20 @@ +Puppet::Type.type(:mysql_database).provide(:mysql) do + desc "Use mysql as database." + commands :mysqladmin => '/usr/bin/mysqladmin' + commands :mysqlshow => '/usr/bin/mysqlshow' + + def create + mysqladmin "create", @resource[:name] + end + def destroy + mysqladmin "-f", "drop", @resource[:name] + end + def exists? + if /\| #{@resource[:name]} /.match(mysqlshow) + true + else + false + end + end +end + diff --git a/plugins/puppet/provider/mysql_user/mysql.rb b/plugins/puppet/provider/mysql_user/mysql.rb new file mode 100644 index 0000000..a1c2896 --- /dev/null +++ b/plugins/puppet/provider/mysql_user/mysql.rb @@ -0,0 +1,19 @@ +Puppet::Type.type(:mysql_user).provide(:mysql) do + desc "Use mysql as database." + commands :mysql => '/usr/bin/mysql' + + def create + mysql "mysql", "-e", "create user '%s@%s' identified by '%s'" % [ @resource[:name], @resource[:host], @resource[:password] ] + end + def destroy + mysql "mysql", "-e", "drop user '%s@%s'" % [ @resource[:name], @resource[:host] ] + end + def exists? + if /^#{@resource[:name]}@#{@resource[:host]}$/.match( mysql( "mysql", "-Be", 'SELECT CONCAT(user, "@", host) FROM user' ) ) + true + else + false + end + end +end + diff --git a/plugins/puppet/type/mysql_database.rb b/plugins/puppet/type/mysql_database.rb new file mode 100644 index 0000000..5dd96d4 --- /dev/null +++ b/plugins/puppet/type/mysql_database.rb @@ -0,0 +1,9 @@ +# This has to be a separate type to enable collecting +Puppet::Type.newtype(:mysql_database) do + @doc = "Manage a database." + ensurable + newparam(:name) do + desc "The name of the database." + end +end + diff --git a/plugins/puppet/type/mysql_user.rb b/plugins/puppet/type/mysql_user.rb new file mode 100644 index 0000000..0005aed --- /dev/null +++ b/plugins/puppet/type/mysql_user.rb @@ -0,0 +1,15 @@ +# This has to be a separate type to enable collecting +Puppet::Type.newtype(:mysql_user) do + @doc = "Manage a database user." + ensurable + newparam(:name) do + desc "The name of the user." + end + newparam(:host) do + desc "The host from where to connect." + end + newparam(:password) do + desc "The password of the user." + end +end + |