Guest User

Untitled

a guest
Jan 25th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.81 KB | None | 0 0
  1. diff -ru ../../ringods_cookbook/postgresql//libraries/connection.rb postgresql//libraries/connection.rb
  2. --- ../../ringods_cookbook/postgresql//libraries/connection.rb 2011-08-04 09:56:09.950741005 +0200
  3. +++ postgresql//libraries/connection.rb 2011-08-04 09:41:26.530740915 +0200
  4. @@ -10,8 +10,14 @@
  5. module Connection
  6. def connection
  7. unless @connection
  8. - Chef::Log.debug("Connecting to 127.0.0.1:5432, user 'postgres'")
  9. - @connection ||= ::PGconn.connect('127.0.0.1', 5432, nil, nil, nil, 'postgres', node[:postgresql][:password][:postgres])
  10. + Chef::Log.debug("Connecting to #{new_resource.db_host}:#{new_resource.db_port}, user '#{new_resource.db_username}'")
  11. + password = (new_resource.db_password or node[:postgresql][:password][:postgres])
  12. + @connection ||= ::PGconn.connect(
  13. + :host => new_resource.db_host,
  14. + :port => new_resource.db_port,
  15. + :user => new_resource.db_username,
  16. + :password => password
  17. + )
  18. Chef::Log.debug("Created postgresql connection: #{@connection} - status: #{@connection.status}")
  19. end
  20. @connection
  21. @@ -22,13 +28,5 @@
  22. @connection = nil
  23. end
  24. end
  25. -
  26. - module ConnectionUtils
  27. - def load_role
  28. -
  29. - end
  30. - end
  31. end
  32. -end
  33. -
  34. -#::PGconn.send(:include, Opscode::PostgreSQL::ConnectionUtils)
  35. +end
  36.  
  37. diff -ru ../../ringods_cookbook/postgresql//providers/database.rb postgresql//providers/database.rb
  38. --- ../../ringods_cookbook/postgresql//providers/database.rb 2011-08-04 09:56:09.950741005 +0200
  39. +++ postgresql//providers/database.rb 2011-08-04 07:29:43.620740113 +0200
  40. @@ -23,16 +23,36 @@
  41. action :create do
  42. unless exists?
  43. begin
  44. - connection.exec("create database #{new_resource.database}")
  45. + create_sql = "CREATE DATABASE #{new_resource.database} WITH
  46. + TEMPLATE = #{new_resource.template} ENCODING = #{new_resource.encoding}
  47. + TABLESPACE = #{new_resource.tablespace} CONNECTION LIMIT = #{new_resource.connection_limit}"
  48. + create_sql += " OWNER = #{new_resource.owner}" if new_resource.owner
  49. +
  50. + connection.exec(create_sql)
  51. Chef::Log.info "postgresql_database: Created database #{new_resource.database}"
  52. new_resource.updated_by_last_action(true)
  53. ensure
  54. close
  55. end
  56. end
  57. +end
  58.  
  59. +action :drop do
  60. + if exists? then
  61. + begin
  62. + drop_sql = "DROP DATABASE #{new_resource.database}"
  63. + connection.exec(drop_sql)
  64. + Chef::Log.info "postgresql_database: Dropped database #{new_resource.database}"
  65. + new_resource.updated_by_last_action(true)
  66. + ensure
  67. + close
  68. + end
  69. + else
  70. + Chef::Log.info "postgresql_database: Database #{new_resource.database} not exist, drop omitted"
  71. + end
  72. end
  73.  
  74. +
  75. def load_current_resource
  76. Gem.clear_paths
  77. require 'pg'
  78. @@ -42,11 +62,11 @@
  79. begin
  80. query_result = connection.exec("select * from pg_database where datname = '#{@new_resource.database}';")
  81. if query_result.ntuples > 0
  82. - existing_role_values = query_result.values[0]
  83. - @current_resource.database(existing_role_values[0])
  84. + @current_resource.database(query_result.getvalue(0, 0))
  85. end
  86. ensure
  87. close
  88. +
  89. end
  90.  
  91. @current_resource
  92. Tylko w postgresql//providers: database.rb~
  93. diff -ru ../../ringods_cookbook/postgresql//providers/role.rb postgresql//providers/role.rb
  94. --- ../../ringods_cookbook/postgresql//providers/role.rb 2011-08-04 09:56:09.950741005 +0200
  95. +++ postgresql//providers/role.rb 2011-08-04 08:44:41.670740569 +0200
  96. @@ -54,13 +54,13 @@
  97. begin
  98. query_result = connection.exec("select * from pg_roles where rolname = '#{@new_resource.role}';")
  99. if query_result.ntuples > 0
  100. - existing_role_values = query_result.values[0]
  101. - @current_resource.role(existing_role_values[0])
  102. - @current_resource.superuser(bool_convert existing_role_values[1])
  103. - @current_resource.inherit(bool_convert existing_role_values[2])
  104. - @current_resource.createrole(bool_convert existing_role_values[3])
  105. - @current_resource.createdb(bool_convert existing_role_values[4])
  106. - @current_resource.login(bool_convert existing_role_values[6])
  107. + #TODO: rewrite to fieldnames/check compatibility between postgres versions
  108. + @current_resource.role(query_result.getvalue(0, 0))
  109. + @current_resource.superuser(bool_convert query_result.getvalue(0, 1))
  110. + @current_resource.inherit(bool_convert query_result.getvalue(0, 2))
  111. + @current_resource.createrole(bool_convert query_result.getvalue(0, 3))
  112. + @current_resource.createdb(bool_convert query_result.getvalue(0, 4))
  113. + @current_resource.login(bool_convert query_result.getvalue(0, 6))
  114. end
  115. ensure
  116. close
  117.  
  118. diff -ru ../../ringods_cookbook/postgresql//resources/database.rb postgresql//resources/database.rb
  119. --- ../../ringods_cookbook/postgresql//resources/database.rb 2011-08-04 09:56:09.960741005 +0200
  120. +++ postgresql//resources/database.rb 2011-08-04 10:39:18.640741266 +0200
  121. @@ -18,6 +18,15 @@
  122. # limitations under the License.
  123. #
  124.  
  125. -actions :create, :query
  126. +actions :create, :drop, :query
  127. +attribute :database, :kind_of => String, :required => "required"
  128. +attribute :owner, :kind_of => String, :default => nil
  129. +attribute :template, :kind_of => String, :default => 'DEFAULT'
  130. +attribute :encoding, :kind_of => String, :default => 'DEFAULT'
  131. +attribute :tablespace, :kind_of => String, :default => 'DEFAULT'
  132. +attribute :connection_limit, :kind_of => String, :default => '-1'
  133.  
  134. -attribute :database, :kind_of => String
  135. +attribute :db_host, :kind_of => String, :default => '127.0.0.1'
  136. +attribute :db_port, :default => 5432
  137. +attribute :db_username, :kind_of => String, :default => 'postgres'
  138. +attribute :db_password, :kind_of => String, :default => nil
  139. \ Brak znaku nowej linii na końcu pliku
  140. Tylko w postgresql//resources: database.rb~
  141. diff -ru ../../ringods_cookbook/postgresql//resources/role.rb postgresql//resources/role.rb
  142. --- ../../ringods_cookbook/postgresql//resources/role.rb 2011-08-04 09:56:09.960741005 +0200
  143. +++ postgresql//resources/role.rb 2011-08-04 09:40:03.840740906 +0200
  144. @@ -17,9 +17,9 @@
  145. # See the License for the specific language governing permissions and
  146. # limitations under the License.
  147. #
  148. +
  149.  
  150. -actions :create
  151. -
  152. +actions :create
  153. attribute :role, :kind_of => String
  154. attribute :superuser, :default => false
  155. attribute :createdb, :default => false
  156. @@ -27,3 +27,8 @@
  157. attribute :inherit, :default => false
  158. attribute :login, :default => false
  159. attribute :exists, :default => false
  160. +
  161. +attribute :db_host, :kind_of => String, :default => '127.0.0.1'
  162. +attribute :db_port, :default => 5432
  163. +attribute :db_username, :kind_of => String, :default => 'postgres'
  164. +attribute :db_password, :kind_of => String, :default => nil
Add Comment
Please, Sign In to add comment