summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrenton Leanhardt <bleanhar@redhat.com>2008-03-28 09:14:24 -0400
committerBrenton Leanhardt <bleanhar@redhat.com>2008-04-03 09:55:30 -0400
commit0eb8b72d713b76908a7314d2afae26c51cf3b850 (patch)
treecaefe0c36ed5fd366f0b573a61274732ace18837
parent657845ad0181c3da2505b3f7c2df3982bdf085ea (diff)
downloadpuppet-mysql-0eb8b72d713b76908a7314d2afae26c51cf3b850.tar.gz
puppet-mysql-0eb8b72d713b76908a7314d2afae26c51cf3b850.tar.xz
puppet-mysql-0eb8b72d713b76908a7314d2afae26c51cf3b850.zip
Adding mysql_schema type
Added definition wrap the creation of the various mysql types
-rw-r--r--plugins/puppet/provider/mysql_schema/mysql.rb29
-rw-r--r--plugins/puppet/type/mysql_schema.rb25
2 files changed, 54 insertions, 0 deletions
diff --git a/plugins/puppet/provider/mysql_schema/mysql.rb b/plugins/puppet/provider/mysql_schema/mysql.rb
new file mode 100644
index 0000000..2b582c1
--- /dev/null
+++ b/plugins/puppet/provider/mysql_schema/mysql.rb
@@ -0,0 +1,29 @@
+require 'puppet/provider/package'
+
+Puppet::Type.type(:mysql_schema).provide(:mysql) do
+
+ desc "Create a Mysql schema."
+ commands :mysqladmin => '/usr/bin/mysqladmin'
+ commands :mysql => '/usr/bin/mysql'
+
+ def create
+ # Pipe the ddl to mysql
+ open("| #{command(:mysql)} -u root -p#{@resource[:rootpw]} #{@resource[:db]}", "w") do |pipe|
+ pipe.puts(File.read(@resource[:name]))
+ end
+ end
+
+ def destroy
+ #noop
+ end
+
+ def exists?
+ if mysql("-u", "root", "-p", @resource[:rootpw], "-NBe", "show tables", @resource[:db]).empty?
+ false
+ else
+ true
+ end
+ end
+end
+
+
diff --git a/plugins/puppet/type/mysql_schema.rb b/plugins/puppet/type/mysql_schema.rb
new file mode 100644
index 0000000..7ae5289
--- /dev/null
+++ b/plugins/puppet/type/mysql_schema.rb
@@ -0,0 +1,25 @@
+# This has to be a separate type to enable collecting
+Puppet::Type.newtype(:mysql_schema) do
+ @doc = "Manage a database user's rights."
+ ensurable
+
+ autorequire :exec do
+ ["mysql_rootpw_flush"]
+ end
+
+ autorequire :mysql_database do
+ [self[:db]]
+ end
+
+ newparam(:name) do
+ desc "The file used to create the schema. This will be autorequired."
+ end
+
+ newparam(:rootpw) do
+ desc "The mysql root user password"
+ end
+
+ newparam(:db) do
+ desc "The database on which the schema is created"
+ end
+end