Class: DevLXC::ChefCluster
- Inherits:
-
Object
- Object
- DevLXC::ChefCluster
- Defined in:
- lib/dev-lxc/chef-cluster.rb
Instance Attribute Summary collapse
-
#api_fqdn ⇒ Object
readonly
Returns the value of attribute api_fqdn.
-
#bootstrap_backend ⇒ Object
readonly
Returns the value of attribute bootstrap_backend.
-
#frontends ⇒ Object
readonly
Returns the value of attribute frontends.
-
#secondary_backend ⇒ Object
readonly
Returns the value of attribute secondary_backend.
-
#topology ⇒ Object
readonly
Returns the value of attribute topology.
Instance Method Summary collapse
- #abspath(rootfs_path) ⇒ Object
- #chef_server_config ⇒ Object
- #chef_servers ⇒ Object
- #destroy ⇒ Object
- #destroy_base_container(type) ⇒ Object
-
#initialize(cluster_config) ⇒ ChefCluster
constructor
A new instance of ChefCluster.
- #run_command(command) ⇒ Object
- #start ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(cluster_config) ⇒ ChefCluster
Returns a new instance of ChefCluster.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dev-lxc/chef-cluster.rb', line 7 def initialize(cluster_config) @cluster_config = cluster_config @api_fqdn = @cluster_config["api_fqdn"] @topology = @cluster_config["topology"] @servers = @cluster_config["servers"] if %w(tier ha).include?(@topology) @bootstrap_backend = @servers.select {|k,v| v["role"] == "backend" && v["bootstrap"] == true}.first.first @frontends = @servers.select {|k,v| v["role"] == "frontend"}.keys end if @topology == "ha" @secondary_backend = @servers.select {|k,v| v["role"] == "backend" && v["bootstrap"] == nil}.first.first end end |
Instance Attribute Details
#api_fqdn ⇒ Object (readonly)
Returns the value of attribute api_fqdn.
5 6 7 |
# File 'lib/dev-lxc/chef-cluster.rb', line 5 def api_fqdn @api_fqdn end |
#bootstrap_backend ⇒ Object (readonly)
Returns the value of attribute bootstrap_backend.
5 6 7 |
# File 'lib/dev-lxc/chef-cluster.rb', line 5 def bootstrap_backend @bootstrap_backend end |
#frontends ⇒ Object (readonly)
Returns the value of attribute frontends.
5 6 7 |
# File 'lib/dev-lxc/chef-cluster.rb', line 5 def frontends @frontends end |
#secondary_backend ⇒ Object (readonly)
Returns the value of attribute secondary_backend.
5 6 7 |
# File 'lib/dev-lxc/chef-cluster.rb', line 5 def secondary_backend @secondary_backend end |
#topology ⇒ Object (readonly)
Returns the value of attribute topology.
5 6 7 |
# File 'lib/dev-lxc/chef-cluster.rb', line 5 def topology @topology end |
Instance Method Details
#abspath(rootfs_path) ⇒ Object
46 47 48 49 50 |
# File 'lib/dev-lxc/chef-cluster.rb', line 46 def abspath(rootfs_path) abspath = Array.new chef_servers.each { |cs| abspath << cs.abspath(rootfs_path) } abspath.compact end |
#chef_server_config ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/dev-lxc/chef-cluster.rb', line 84 def chef_server_config chef_server_config = %Q(api_fqdn "#{@api_fqdn}"\n) if %w(tier ha).include?(@topology) chef_server_config += %Q( topology "#{@topology}" server "#{@bootstrap_backend}", :ipaddress => "#{@servers[@bootstrap_backend]["ipaddress"]}", :role => "backend", :bootstrap => true) case @topology when "tier" chef_server_config += %Q( backend_vip "#{@bootstrap_backend}", :ipaddress => "#{@servers[@bootstrap_backend]["ipaddress"]}" ) when "ha" backend_vip_name = config["backend_vip"].keys.first chef_server_config += %Q(, :cluster_ipaddress => "#{@servers[@bootstrap_backend]["cluster_ipaddress"]}" server "#{@secondary_backend}", :ipaddress => "#{@servers[@secondary_backend]["ipaddress"]}", :role => "backend", :cluster_ipaddress => "#{@servers[@secondary_backend]["cluster_ipaddress"]} backend_vip "#{backend_vip_name}", :ipaddress => "#{config["backend_vip"][backend_vip_name]["ipaddress"]}", :device => "#{config["backend_vip"][backend_vip_name]["device"]}", :heartbeat_device => "#{config["backend_vip"][backend_vip_name]["heartbeat_device"]}" ) end @frontends.each do |frontend_name| chef_server_config += %Q( server "#{frontend_name}", :ipaddress => "#{@servers[frontend_name]["ipaddress"]}", :role => "frontend" ) end end return chef_server_config end |
#chef_servers ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dev-lxc/chef-cluster.rb', line 21 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) @frontends.each do |frontend_name| chef_servers << ChefServer.new(frontend_name, @cluster_config) end when "ha" chef_servers << ChefServer.new(@bootstrap_backend, @cluster_config) chef_servers << ChefServer.new(@secondary_backend, @cluster_config) @frontends.each do |frontend_name| chef_servers << ChefServer.new(frontend_name, @cluster_config) end end chef_servers end |
#destroy ⇒ Object
66 67 68 69 |
# File 'lib/dev-lxc/chef-cluster.rb', line 66 def destroy puts "Destroying cluster" chef_servers.reverse_each { |cs| cs.destroy } end |
#destroy_base_container(type) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/dev-lxc/chef-cluster.rb', line 71 def destroy_base_container(type) case type when :unique @servers.keys.each do |server_name| DevLXC::ChefServer.new(server_name, @cluster_config).destroy_base_container(:unique) end when :shared DevLXC::ChefServer.new(@servers.keys.first, @cluster_config).destroy_base_container(:shared) when :platform DevLXC::ChefServer.new(@servers.keys.first, @cluster_config).destroy_base_container(:platform) end end |
#run_command(command) ⇒ Object
52 53 54 |
# File 'lib/dev-lxc/chef-cluster.rb', line 52 def run_command(command) chef_servers.each { |cs| cs.run_command(command) } end |
#start ⇒ Object
56 57 58 59 |
# File 'lib/dev-lxc/chef-cluster.rb', line 56 def start puts "Starting cluster" chef_servers.each { |cs| cs.start } end |
#status ⇒ Object
41 42 43 44 |
# File 'lib/dev-lxc/chef-cluster.rb', line 41 def status puts "Cluster is available at https://#{@api_fqdn}" chef_servers.each { |cs| cs.status } end |
#stop ⇒ Object
61 62 63 64 |
# File 'lib/dev-lxc/chef-cluster.rb', line 61 def stop puts "Stopping cluster" chef_servers.reverse_each { |cs| cs.stop } end |