Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REALMS #308

Merged
merged 2 commits into from
Sep 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions lib/ironfan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Ironfan
@@clusters ||= Hash.new
@@realms ||= Hash.new

# path to search for cluster definition files
def self.cluster_path
Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/ironfan/dsl/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def cluster_name() name; end
end

end
end
end
22 changes: 22 additions & 0 deletions lib/ironfan/dsl/realm.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/ironfan/requirements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down