diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2010-02-03 14:11:18 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2010-02-03 14:11:18 -0200 |
commit | adc9c0f1168b780e6c8b78f63caa2fb51cc72399 (patch) | |
tree | 8b431784fd610e203ca3b42f03069f1c617dcddd /lib/puppet/provider/mysql_database/mysql.rb | |
parent | b5d91bdba1f0a02614fd6f6e9699c2c97ec8b725 (diff) | |
download | puppet-mysql-adc9c0f1168b780e6c8b78f63caa2fb51cc72399.tar.gz puppet-mysql-adc9c0f1168b780e6c8b78f63caa2fb51cc72399.tar.bz2 |
Adding resource types mysql_{user,database,grant} (2)
Diffstat (limited to 'lib/puppet/provider/mysql_database/mysql.rb')
-rw-r--r-- | lib/puppet/provider/mysql_database/mysql.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/puppet/provider/mysql_database/mysql.rb b/lib/puppet/provider/mysql_database/mysql.rb new file mode 100644 index 0000000..2b70e04 --- /dev/null +++ b/lib/puppet/provider/mysql_database/mysql.rb @@ -0,0 +1,55 @@ +require 'puppet/provider/package' + +Puppet::Type.type(:mysql_database).provide(:mysql, + :parent => Puppet::Provider::Package) do + + desc "Use mysql as database." + commands :mysqladmin => '/usr/bin/mysqladmin' + commands :mysql => '/usr/bin/mysql' + + # retrieve the current set of mysql users + def self.instances + dbs = [] + + cmd = "#{command(:mysql)} mysql -NBe 'show databases'" + execpipe(cmd) do |process| + process.each do |line| + dbs << new( { :ensure => :present, :name => line.chomp } ) + end + end + return dbs + end + + def query + result = { + :name => @resource[:name], + :ensure => :absent + } + + cmd = "#{command(:mysql)} mysql -NBe 'show databases'" + execpipe(cmd) do |process| + process.each do |line| + if line.chomp.eql?(@resource[:name]) + result[:ensure] = :present + end + end + end + result + end + + def create + mysqladmin "create", @resource[:name] + end + def destroy + mysqladmin "-f", "drop", @resource[:name] + end + + def exists? + if mysql("mysql", "-NBe", "show databases").match(/^#{@resource[:name]}$/) + true + else + false + end + end +end + |