Browse Source

Factor out the logic to determine the actual database server; whether that comes from a search, or is manually specified. In particular, this makes it possible to specify a host that is not managed in chef, per COOK-730.

There is a bit of a layering violation here (not all respond to :database), but it just makes sense to share this code.
Andrea Campi 12 years ago
parent
commit
8557b625f0
1 changed files with 13 additions and 0 deletions
  1. 13 0
      libraries/default.rb

+ 13 - 0
libraries/default.rb

@@ -112,6 +112,19 @@ class Chef
           end
         end
       end
+
+      def find_database_server(role)
+        dbm = find_matching_role(role)
+        Chef::Log.warn("No node with role #{role}") if role && !dbm
+
+        if respond_to?(:database) && database.has_key?('host')
+          database['host']
+        elsif dbm && dbm.attribute?('cloud')
+          dbm['cloud']['local_ipv4']
+        elsif dbm
+          dbm['ipaddress']
+        end
+      end
     end
   end