diff --git a/lib/ironfan.rb b/lib/ironfan.rb index 4e561794..afb94a6f 100644 --- a/lib/ironfan.rb +++ b/lib/ironfan.rb @@ -2,6 +2,7 @@ module Ironfan @@clusters ||= Hash.new + @@realms ||= Hash.new # path to search for cluster definition files def self.cluster_path @@ -18,6 +19,12 @@ def self.clusters @@clusters end + # + # Delegates + def self.realms + @@realms + end + def self.ui=(ui) @ui = ui ; end def self.ui() @ui ; end @@ -72,6 +79,18 @@ def self.cluster(name, attrs={}, &block) end end + def self.realm(name, attrs={}, &block) + name = name.to_sym + if @@realms[name] and attrs.empty? and not block_given? + return @@realms[name] + else + rlm = Ironfan::Dsl::Realm.new(:name => name) + rlm.receive!(attrs, &block) + rlm.clusters.keys.each{|k| @@clusters[k.to_sym] = rlm.clusters[k].resolve} + @@realms[name] = rlm + end + end + # # Return cluster if it's defined. Otherwise, search Ironfan.cluster_path # for an eponymous file, load it, and return the cluster it defines. @@ -85,12 +104,14 @@ def self.load_cluster(name) raise ArgumentError, "Please supply a cluster name" if name.to_s.empty? return @@clusters[name] if @@clusters[name] - cluster_file = cluster_filenames[name] or raise("Couldn't find a definition for #{name} in cluster_path: #{cluster_path.inspect}") - - Chef::Log.info("Loading cluster #{cluster_file}") + cluster_path.each do |cp_dir| + Dir[ File.join(cp_dir, '*.rb') ].each do |filename| + Chef::Log.info("Loading cluster file #{filename}") + require filename + end + end - require cluster_file - unless @@clusters[name] then die("#{cluster_file} was supposed to have the definition for the #{name} cluster, but didn't") end + unless @@clusters[name] then die("Couldn't find a cluster definition for #{name} in #{cluster_path}") end @@clusters[name] end diff --git a/lib/ironfan/dsl/cluster.rb b/lib/ironfan/dsl/cluster.rb index 6b8641e9..32a92bb4 100644 --- a/lib/ironfan/dsl/cluster.rb +++ b/lib/ironfan/dsl/cluster.rb @@ -20,4 +20,4 @@ def cluster_name() name; end end end -end \ No newline at end of file +end diff --git a/lib/ironfan/dsl/realm.rb b/lib/ironfan/dsl/realm.rb new file mode 100644 index 00000000..1f74e55a --- /dev/null +++ b/lib/ironfan/dsl/realm.rb @@ -0,0 +1,22 @@ +module Ironfan + class Dsl + + class Realm < Ironfan::Dsl::Compute + collection :clusters, Ironfan::Dsl::Cluster, :resolver => :deep_resolve + + def initialize(attrs={},&block) + super + end + + def cluster(label, attrs={},&blk) + new_name = [realm_name, label].join '_' + cluster = Ironfan::Dsl::Cluster.new(name: new_name) + cluster.receive!(attrs, &blk) + super(new_name, cluster) + end + + def realm_name() name; end + end + + end +end diff --git a/lib/ironfan/requirements.rb b/lib/ironfan/requirements.rb index 1b2d90a2..fa3c6c9a 100644 --- a/lib/ironfan/requirements.rb +++ b/lib/ironfan/requirements.rb @@ -13,6 +13,7 @@ require 'ironfan/dsl/server' require 'ironfan/dsl/facet' require 'ironfan/dsl/cluster' +require 'ironfan/dsl/realm' require 'ironfan/dsl/role' require 'ironfan/dsl/volume'