summaryrefslogtreecommitdiff
path: root/lib/puppet/provider/package/mysql_database.rb
diff options
context:
space:
mode:
authordrebs <drebs@riseup.net>2011-03-27 17:15:43 -0300
committerdrebs <drebs@riseup.net>2011-03-27 17:15:43 -0300
commitb436e0428e8efc2addbfe0866eb255a6700fb011 (patch)
tree8b9543c471d79ebfca43bb09b96c18ef26234dec /lib/puppet/provider/package/mysql_database.rb
parent14dbafc286141d62ed70d4e171f7a5aeac62482b (diff)
downloadpuppet-mysql-b436e0428e8efc2addbfe0866eb255a6700fb011.tar.gz
puppet-mysql-b436e0428e8efc2addbfe0866eb255a6700fb011.tar.bz2
fixing providers' path
Diffstat (limited to 'lib/puppet/provider/package/mysql_database.rb')
-rw-r--r--lib/puppet/provider/package/mysql_database.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/puppet/provider/package/mysql_database.rb b/lib/puppet/provider/package/mysql_database.rb
new file mode 100644
index 0000000..2b70e04
--- /dev/null
+++ b/lib/puppet/provider/package/mysql_database.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
+