Class: DevLXC::Cluster
- Inherits:
-
Object
- Object
- DevLXC::Cluster
- Defined in:
- lib/dev-lxc/cluster.rb
Instance Attribute Summary collapse
-
#analytics_bootstrap_backend ⇒ Object
readonly
Returns the value of attribute analytics_bootstrap_backend.
-
#analytics_fqdn ⇒ Object
readonly
Returns the value of attribute analytics_fqdn.
-
#api_fqdn ⇒ Object
readonly
Returns the value of attribute api_fqdn.
-
#chef_server_bootstrap_backend ⇒ Object
readonly
Returns the value of attribute chef_server_bootstrap_backend.
-
#lxc_config_path ⇒ Object
readonly
Returns the value of attribute lxc_config_path.
Instance Method Summary collapse
- #analytics_config ⇒ Object
- #chef_repo(force = false, pivotal = false) ⇒ Object
- #chef_server_config ⇒ Object
-
#initialize(cluster_config) ⇒ Cluster
constructor
A new instance of Cluster.
- #servers ⇒ Object
Constructor Details
#initialize(cluster_config) ⇒ Cluster
Returns a new instance of Cluster.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dev-lxc/cluster.rb', line 7 def initialize(cluster_config) @cluster_config = cluster_config @lxc_config_path = @cluster_config["lxc_config_path"] @lxc_config_path ||= "/var/lib/dev-lxc" if @cluster_config["chef-server"] @chef_server_topology = @cluster_config["chef-server"]["topology"] @api_fqdn = @cluster_config["chef-server"]["api_fqdn"] @chef_server_servers = @cluster_config["chef-server"]["servers"] @chef_server_frontends = Array.new @chef_server_servers.each do |name, config| case @chef_server_topology when 'open-source', 'standalone' @chef_server_bootstrap_backend = name if config["role"].nil? when 'tier' @chef_server_bootstrap_backend = name if config["role"] == "backend" && config["bootstrap"] == true @chef_server_frontends << name if config["role"] == "frontend" end end end if @cluster_config["analytics"] @analytics_topology = @cluster_config["analytics"]["topology"] @analytics_fqdn = @cluster_config["analytics"]["analytics_fqdn"] @analytics_servers = @cluster_config["analytics"]["servers"] @analytics_frontends = Array.new @analytics_servers.each do |name, config| case @analytics_topology when 'standalone' @analytics_bootstrap_backend = name if config["role"].nil? when 'tier' @analytics_bootstrap_backend = name if config["role"] == "backend" && config["bootstrap"] == true @analytics_frontends << name if config["role"] == "frontend" end end end end |
Instance Attribute Details
#analytics_bootstrap_backend ⇒ Object (readonly)
Returns the value of attribute analytics_bootstrap_backend.
5 6 7 |
# File 'lib/dev-lxc/cluster.rb', line 5 def analytics_bootstrap_backend @analytics_bootstrap_backend end |
#analytics_fqdn ⇒ Object (readonly)
Returns the value of attribute analytics_fqdn.
5 6 7 |
# File 'lib/dev-lxc/cluster.rb', line 5 def analytics_fqdn @analytics_fqdn end |
#api_fqdn ⇒ Object (readonly)
Returns the value of attribute api_fqdn.
5 6 7 |
# File 'lib/dev-lxc/cluster.rb', line 5 def api_fqdn @api_fqdn end |
#chef_server_bootstrap_backend ⇒ Object (readonly)
Returns the value of attribute chef_server_bootstrap_backend.
5 6 7 |
# File 'lib/dev-lxc/cluster.rb', line 5 def chef_server_bootstrap_backend @chef_server_bootstrap_backend end |
#lxc_config_path ⇒ Object (readonly)
Returns the value of attribute lxc_config_path.
5 6 7 |
# File 'lib/dev-lxc/cluster.rb', line 5 def lxc_config_path @lxc_config_path end |
Instance Method Details
#analytics_config ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/dev-lxc/cluster.rb', line 150 def analytics_config analytics_config = %Q(analytics_fqdn "#{@analytics_fqdn}" topology "#{@analytics_topology}" ) if @analytics_topology == 'tier' analytics_config += %Q( server "#{@analytics_bootstrap_backend}", :ipaddress => "#{@analytics_servers[@analytics_bootstrap_backend]["ipaddress"]}", :role => "backend", :bootstrap => true backend_vip "#{@analytics_bootstrap_backend}", :ipaddress => "#{@analytics_servers[@analytics_bootstrap_backend]["ipaddress"]}" ) @analytics_frontends.each do |frontend_name| analytics_config += %Q( server "#{frontend_name}", :ipaddress => "#{@analytics_servers[frontend_name]["ipaddress"]}", :role => "frontend" ) end end return analytics_config end |
#chef_repo(force = false, pivotal = false) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 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 |
# File 'lib/dev-lxc/cluster.rb', line 64 def chef_repo(force=false, pivotal=false) if @chef_server_bootstrap_backend.nil? puts "ERROR: A bootstrap backend Chef Server is not defined in the cluster's config. Please define it first." exit 1 end chef_server = Server.new(@chef_server_bootstrap_backend, 'chef-server', @cluster_config) if ! chef_server.server.defined? puts "ERROR: 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") pem_files = Dir.glob("#{chef_server.realpath('/root/chef-repo/.chef')}/*.pem") if pem_files.empty? puts "The pem files can not be copied because they do not exist in '#{chef_server.server.name}' Chef Server's `/root/chef-repo/.chef` directory" else pem_files.delete_if { |pem_file| pem_file.end_with?("/pivotal.pem") } unless pivotal FileUtils.cp( pem_files, "./chef-repo/.chef" ) end if @chef_server_topology == "open-source" chef_server_url = "https://#{@api_fqdn}" validator_name = "chef-validator" else chef_server_root = "https://#{@api_fqdn}" chef_server_url = "https://#{@api_fqdn}/organizations/ponyville" validator_name = "ponyville-validator" if pivotal if File.exists?("./chef-repo/.chef/pivotal.rb") && ! force puts "Skipping pivotal.rb because it already exists in `./chef-repo/.chef`" else pivotal_rb_path = "#{chef_server.realpath('/root/chef-repo/.chef')}/pivotal.rb" if File.exists?(pivotal_rb_path) pivotal_rb = IO.read(pivotal_rb_path) pivotal_rb.sub!(/^chef_server_root .*/, "chef_server_root \"#{chef_server_root}\"") pivotal_rb.sub!(/^chef_server_url .*/, "chef_server_url \"#{chef_server_url}\"") IO.write("./chef-repo/.chef/pivotal.rb", pivotal_rb) else puts "The pivotal.rb file can not be copied because it does not exist in '#{chef_server.server.name}' Chef Server's `/root/chef-repo/.chef` directory" end end end end if File.exists?("./chef-repo/.chef/knife.rb") && ! force puts "Skipping knife.rb because it already exists in `./chef-repo/.chef`" else knife_rb_path = "#{chef_server.realpath('/root/chef-repo/.chef')}/knife.rb" if File.exists?(knife_rb_path) knife_rb = IO.read(knife_rb_path) knife_rb.sub!(/^chef_server_url .*/, "chef_server_url \"#{chef_server_url}\"") IO.write("./chef-repo/.chef/knife.rb", knife_rb) else puts "The knife.rb file can not be copied because it does not exist in '#{chef_server.server.name}' Chef Server's `/root/chef-repo/.chef` directory" end end end |
#chef_server_config ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/dev-lxc/cluster.rb', line 125 def chef_server_config chef_server_config = %Q(api_fqdn "#{@api_fqdn}"\n) if @chef_server_topology == 'tier' chef_server_config += %Q( topology "#{@chef_server_topology}" server "#{@chef_server_bootstrap_backend}", :ipaddress => "#{@chef_server_servers[@chef_server_bootstrap_backend]["ipaddress"]}", :role => "backend", :bootstrap => true backend_vip "#{@chef_server_bootstrap_backend}", :ipaddress => "#{@chef_server_servers[@chef_server_bootstrap_backend]["ipaddress"]}" ) @chef_server_frontends.each do |frontend_name| chef_server_config += %Q( server "#{frontend_name}", :ipaddress => "#{@chef_server_servers[frontend_name]["ipaddress"]}", :role => "frontend" ) end end return chef_server_config end |
#servers ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dev-lxc/cluster.rb', line 46 def servers chef_servers = Array.new chef_servers << Server.new(@chef_server_bootstrap_backend, 'chef-server', @cluster_config) if @chef_server_bootstrap_backend if @chef_server_topology == "tier" @chef_server_frontends.each do |frontend_name| chef_servers << Server.new(frontend_name, 'chef-server', @cluster_config) end end analytics_servers = Array.new analytics_servers << Server.new(@analytics_bootstrap_backend, 'analytics', @cluster_config) if @analytics_bootstrap_backend if @analytics_topology == "tier" @analytics_frontends.each do |frontend_name| analytics_servers << Server.new(frontend_name, 'analytics', @cluster_config) end end servers = chef_servers + analytics_servers end |