Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -ru ../../ringods_cookbook/postgresql//libraries/connection.rb postgresql//libraries/connection.rb
- --- ../../ringods_cookbook/postgresql//libraries/connection.rb 2011-08-04 09:56:09.950741005 +0200
- +++ postgresql//libraries/connection.rb 2011-08-04 09:41:26.530740915 +0200
- @@ -10,8 +10,14 @@
- module Connection
- def connection
- unless @connection
- - Chef::Log.debug("Connecting to 127.0.0.1:5432, user 'postgres'")
- - @connection ||= ::PGconn.connect('127.0.0.1', 5432, nil, nil, nil, 'postgres', node[:postgresql][:password][:postgres])
- + Chef::Log.debug("Connecting to #{new_resource.db_host}:#{new_resource.db_port}, user '#{new_resource.db_username}'")
- + password = (new_resource.db_password or node[:postgresql][:password][:postgres])
- + @connection ||= ::PGconn.connect(
- + :host => new_resource.db_host,
- + :port => new_resource.db_port,
- + :user => new_resource.db_username,
- + :password => password
- + )
- Chef::Log.debug("Created postgresql connection: #{@connection} - status: #{@connection.status}")
- end
- @connection
- @@ -22,13 +28,5 @@
- @connection = nil
- end
- end
- -
- - module ConnectionUtils
- - def load_role
- -
- - end
- - end
- end
- -end
- -
- -#::PGconn.send(:include, Opscode::PostgreSQL::ConnectionUtils)
- +end
- diff -ru ../../ringods_cookbook/postgresql//providers/database.rb postgresql//providers/database.rb
- --- ../../ringods_cookbook/postgresql//providers/database.rb 2011-08-04 09:56:09.950741005 +0200
- +++ postgresql//providers/database.rb 2011-08-04 07:29:43.620740113 +0200
- @@ -23,16 +23,36 @@
- action :create do
- unless exists?
- begin
- - connection.exec("create database #{new_resource.database}")
- + create_sql = "CREATE DATABASE #{new_resource.database} WITH
- + TEMPLATE = #{new_resource.template} ENCODING = #{new_resource.encoding}
- + TABLESPACE = #{new_resource.tablespace} CONNECTION LIMIT = #{new_resource.connection_limit}"
- + create_sql += " OWNER = #{new_resource.owner}" if new_resource.owner
- +
- + connection.exec(create_sql)
- Chef::Log.info "postgresql_database: Created database #{new_resource.database}"
- new_resource.updated_by_last_action(true)
- ensure
- close
- end
- end
- +end
- +action :drop do
- + if exists? then
- + begin
- + drop_sql = "DROP DATABASE #{new_resource.database}"
- + connection.exec(drop_sql)
- + Chef::Log.info "postgresql_database: Dropped database #{new_resource.database}"
- + new_resource.updated_by_last_action(true)
- + ensure
- + close
- + end
- + else
- + Chef::Log.info "postgresql_database: Database #{new_resource.database} not exist, drop omitted"
- + end
- end
- +
- def load_current_resource
- Gem.clear_paths
- require 'pg'
- @@ -42,11 +62,11 @@
- begin
- query_result = connection.exec("select * from pg_database where datname = '#{@new_resource.database}';")
- if query_result.ntuples > 0
- - existing_role_values = query_result.values[0]
- - @current_resource.database(existing_role_values[0])
- + @current_resource.database(query_result.getvalue(0, 0))
- end
- ensure
- close
- +
- end
- @current_resource
- Tylko w postgresql//providers: database.rb~
- diff -ru ../../ringods_cookbook/postgresql//providers/role.rb postgresql//providers/role.rb
- --- ../../ringods_cookbook/postgresql//providers/role.rb 2011-08-04 09:56:09.950741005 +0200
- +++ postgresql//providers/role.rb 2011-08-04 08:44:41.670740569 +0200
- @@ -54,13 +54,13 @@
- begin
- query_result = connection.exec("select * from pg_roles where rolname = '#{@new_resource.role}';")
- if query_result.ntuples > 0
- - existing_role_values = query_result.values[0]
- - @current_resource.role(existing_role_values[0])
- - @current_resource.superuser(bool_convert existing_role_values[1])
- - @current_resource.inherit(bool_convert existing_role_values[2])
- - @current_resource.createrole(bool_convert existing_role_values[3])
- - @current_resource.createdb(bool_convert existing_role_values[4])
- - @current_resource.login(bool_convert existing_role_values[6])
- + #TODO: rewrite to fieldnames/check compatibility between postgres versions
- + @current_resource.role(query_result.getvalue(0, 0))
- + @current_resource.superuser(bool_convert query_result.getvalue(0, 1))
- + @current_resource.inherit(bool_convert query_result.getvalue(0, 2))
- + @current_resource.createrole(bool_convert query_result.getvalue(0, 3))
- + @current_resource.createdb(bool_convert query_result.getvalue(0, 4))
- + @current_resource.login(bool_convert query_result.getvalue(0, 6))
- end
- ensure
- close
- diff -ru ../../ringods_cookbook/postgresql//resources/database.rb postgresql//resources/database.rb
- --- ../../ringods_cookbook/postgresql//resources/database.rb 2011-08-04 09:56:09.960741005 +0200
- +++ postgresql//resources/database.rb 2011-08-04 10:39:18.640741266 +0200
- @@ -18,6 +18,15 @@
- # limitations under the License.
- #
- -actions :create, :query
- +actions :create, :drop, :query
- +attribute :database, :kind_of => String, :required => "required"
- +attribute :owner, :kind_of => String, :default => nil
- +attribute :template, :kind_of => String, :default => 'DEFAULT'
- +attribute :encoding, :kind_of => String, :default => 'DEFAULT'
- +attribute :tablespace, :kind_of => String, :default => 'DEFAULT'
- +attribute :connection_limit, :kind_of => String, :default => '-1'
- -attribute :database, :kind_of => String
- +attribute :db_host, :kind_of => String, :default => '127.0.0.1'
- +attribute :db_port, :default => 5432
- +attribute :db_username, :kind_of => String, :default => 'postgres'
- +attribute :db_password, :kind_of => String, :default => nil
- \ Brak znaku nowej linii na końcu pliku
- Tylko w postgresql//resources: database.rb~
- diff -ru ../../ringods_cookbook/postgresql//resources/role.rb postgresql//resources/role.rb
- --- ../../ringods_cookbook/postgresql//resources/role.rb 2011-08-04 09:56:09.960741005 +0200
- +++ postgresql//resources/role.rb 2011-08-04 09:40:03.840740906 +0200
- @@ -17,9 +17,9 @@
- # See the License for the specific language governing permissions and
- # limitations under the License.
- #
- +
- -actions :create
- -
- +actions :create
- attribute :role, :kind_of => String
- attribute :superuser, :default => false
- attribute :createdb, :default => false
- @@ -27,3 +27,8 @@
- attribute :inherit, :default => false
- attribute :login, :default => false
- attribute :exists, :default => false
- +
- +attribute :db_host, :kind_of => String, :default => '127.0.0.1'
- +attribute :db_port, :default => 5432
- +attribute :db_username, :kind_of => String, :default => 'postgres'
- +attribute :db_password, :kind_of => String, :default => nil
Add Comment
Please, Sign In to add comment