From 0eb8b72d713b76908a7314d2afae26c51cf3b850 Mon Sep 17 00:00:00 2001 From: Brenton Leanhardt Date: Fri, 28 Mar 2008 09:14:24 -0400 Subject: Adding mysql_schema type Added definition wrap the creation of the various mysql types --- plugins/puppet/provider/mysql_schema/mysql.rb | 29 +++++++++++++++++++++++++++ plugins/puppet/type/mysql_schema.rb | 25 +++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 plugins/puppet/provider/mysql_schema/mysql.rb create mode 100644 plugins/puppet/type/mysql_schema.rb 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 -- cgit