lib/dev-lxc/chef-cluster.rb in dev-lxc-0.3.1 vs lib/dev-lxc/chef-cluster.rb in dev-lxc-0.4.0
- old
+ new
@@ -1,67 +1,70 @@
require "dev-lxc/chef-server"
module DevLXC
class ChefCluster
- attr_reader :api_fqdn, :topology, :bootstrap_backend, :frontends
+ attr_reader :bootstrap_backend
def initialize(cluster_config)
@cluster_config = cluster_config
@api_fqdn = @cluster_config["api_fqdn"]
+ @analytics_fqdn = @cluster_config["analytics_fqdn"]
@topology = @cluster_config["topology"]
@servers = @cluster_config["servers"]
- if @topology == 'tier'
- @bootstrap_backend = @servers.select {|k,v| v["role"] == "backend" && v["bootstrap"] == true}.first.first
- @frontends = @servers.select {|k,v| v["role"] == "frontend"}.keys
+ @frontends = Array.new
+ @servers.each do |name, config|
+ case @topology
+ when 'open-source', 'standalone'
+ @bootstrap_backend = name if config["role"].nil?
+ when 'tier'
+ @bootstrap_backend = name if config["role"] == "backend" && config["bootstrap"] == true
+ @frontends << name if config["role"] == "frontend"
+ end
+ @analytics_server = name if config["role"] == "analytics"
end
end
def chef_servers
chef_servers = Array.new
- case @topology
- when "open-source", "standalone"
- chef_servers << ChefServer.new(@servers.keys.first, @cluster_config)
- when "tier"
- chef_servers << ChefServer.new(@bootstrap_backend, @cluster_config)
+ chef_servers << ChefServer.new(@bootstrap_backend, @cluster_config)
+ if @topology == "tier"
@frontends.each do |frontend_name|
chef_servers << ChefServer.new(frontend_name, @cluster_config)
end
end
+ chef_servers << ChefServer.new(@analytics_server, @cluster_config) if @analytics_server
chef_servers
end
def status
puts "Cluster is available at https://#{@api_fqdn}"
+ puts "Analytics is available at https://#{@analytics_fqdn}" if @analytics_fqdn
chef_servers.each { |cs| cs.status }
end
def abspath(rootfs_path)
abspath = Array.new
- chef_servers.each { |cs| abspath << cs.abspath(rootfs_path) }
+ chef_servers.each { |cs| abspath << cs.abspath(rootfs_path) unless cs.role == 'analytics' }
abspath.compact
end
def chef_repo
- case @topology
- when "open-source"
+ if @topology == "open-source"
puts "Unable to create a chef-repo for an Open Source Chef Server"
exit 1
- when "standalone"
- chef_server = ChefServer.new(@servers.keys.first, @cluster_config)
- when "tier"
- chef_server = ChefServer.new(@bootstrap_backend, @cluster_config)
end
+ chef_server = ChefServer.new(@bootstrap_backend, @cluster_config)
if ! chef_server.server.defined?
puts "The '#{chef_server.server.name}' Chef Server does not exist. Please create it first."
exit 1
end
puts "Creating chef-repo with pem files and knife.rb in the current directory"
FileUtils.mkdir_p("./chef-repo/.chef")
knife_rb = %Q(
current_dir = File.dirname(__FILE__)
-chef_server_url "https://#{api_fqdn}/organizations/ponyville"
+chef_server_url "https://#{@api_fqdn}/organizations/ponyville"
node_name "rainbowdash"
client_key "\#{current_dir}/rainbowdash.pem"
validation_client_name "ponyville-validator"
@@ -77,11 +80,11 @@
FileUtils.cp( Dir.glob("#{chef_server.abspath('/root/chef-repo/.chef')}/*.pem"), "./chef-repo/.chef" )
end
end
def run_command(command)
- chef_servers.each { |cs| cs.run_command(command) }
+ chef_servers.each { |cs| cs.run_command(command) unless cs.role == 'analytics' }
end
def start
puts "Starting cluster"
chef_servers.each { |cs| cs.start }
@@ -96,19 +99,10 @@
puts "Destroying cluster"
chef_servers.reverse_each { |cs| cs.destroy }
end
def destroy_container(type)
- case type
- when :unique
- @servers.keys.each do |server_name|
- DevLXC::ChefServer.new(server_name, @cluster_config).destroy_container(:unique)
- end
- when :shared
- DevLXC::ChefServer.new(@servers.keys.first, @cluster_config).destroy_container(:shared)
- when :platform
- DevLXC::ChefServer.new(@servers.keys.first, @cluster_config).destroy_container(:platform)
- end
+ chef_servers.each { |cs| cs.destroy_container(type) }
end
def chef_server_config
chef_server_config = %Q(api_fqdn "#{@api_fqdn}"\n)
if @topology == 'tier'