Class: Bosh::Director::Config
Overview
We want to shift from class methods to instance methods here.
Class Attribute Summary collapse
-
.base_dir ⇒ Object
Returns the value of attribute base_dir.
-
.cloud_options ⇒ Object
Returns the value of attribute cloud_options.
-
.current_job ⇒ Object
Returns the value of attribute current_job.
-
.db ⇒ Object
Returns the value of attribute db.
-
.db_config ⇒ Object
readonly
Returns the value of attribute db_config.
-
.default_ssh_options ⇒ Object
Returns the value of attribute default_ssh_options.
-
.dns ⇒ Object
Returns the value of attribute dns.
-
.dns_db ⇒ Object
Returns the value of attribute dns_db.
-
.dns_domain_name ⇒ Object
Returns the value of attribute dns_domain_name.
-
.enable_snapshots ⇒ Object
Returns the value of attribute enable_snapshots.
-
.encryption ⇒ Object
Returns the value of attribute encryption.
-
.event_log ⇒ Object
Returns the value of attribute event_log.
-
.fix_stateful_nodes ⇒ Object
Returns the value of attribute fix_stateful_nodes.
-
.ignore_missing_gateway ⇒ Object
readonly
Returns the value of attribute ignore_missing_gateway.
-
.keep_unreachable_vms ⇒ Object
Returns the value of attribute keep_unreachable_vms.
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.max_tasks ⇒ Object
Returns the value of attribute max_tasks.
-
.max_threads ⇒ Object
Returns the value of attribute max_threads.
-
.max_vm_create_tries ⇒ Object
Returns the value of attribute max_vm_create_tries.
-
.name ⇒ Object
Returns the value of attribute name.
-
.nats_uri ⇒ Object
Returns the value of attribute nats_uri.
-
.process_uuid ⇒ Object
Returns the value of attribute process_uuid.
-
.redis_logger_level ⇒ Object
readonly
Returns the value of attribute redis_logger_level.
-
.result ⇒ Object
Returns the value of attribute result.
-
.revision ⇒ Object
Returns the value of attribute revision.
-
.task_checkpoint_interval ⇒ Object
Returns the value of attribute task_checkpoint_interval.
-
.trusted_certs ⇒ Object
Returns the value of attribute trusted_certs.
-
.uuid ⇒ Object
Returns the value of attribute uuid.
Class Method Summary collapse
- .clear ⇒ Object
- .cloud ⇒ Object
- .cloud_type ⇒ Object
- .compiled_package_cache_blobstore ⇒ Object
- .compiled_package_cache_provider ⇒ Object
- .configure(config) ⇒ Object
- .configure_db(db_config) ⇒ Object
- .cpi_task_log ⇒ Object
- .encryption? ⇒ Boolean
- .generate_temp_dir ⇒ Object
- .get_revision ⇒ Object
- .job_cancelled? ⇒ Boolean (also: task_checkpoint)
- .load_file(path) ⇒ Object
- .load_hash(hash) ⇒ Object
- .log_dir ⇒ Object
- .nats_rpc ⇒ Object
-
.override_uuid ⇒ Object
Migrates director UUID to database Currently used by integration tests to set director UUID.
- .patch_sqlite ⇒ Object
- .redis ⇒ Object
- .redis? ⇒ Boolean
- .redis_logger=(logger) ⇒ Object
- .redis_options ⇒ Object
- .redis_options=(options) ⇒ Object
- .threaded ⇒ Object
- .use_compiled_package_cache? ⇒ Boolean
Instance Method Summary collapse
- #backup_blobstore_config ⇒ Object
- #blobstore_config ⇒ Object
- #configure_evil_config_singleton! ⇒ Object
- #identity_provider ⇒ Object
- #name ⇒ Object
- #port ⇒ Object
- #resque_logger ⇒ Object
- #scheduled_jobs ⇒ Object
Class Attribute Details
.base_dir ⇒ Object
Returns the value of attribute base_dir.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def base_dir @base_dir end |
.cloud_options ⇒ Object
Returns the value of attribute cloud_options.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def end |
.current_job ⇒ Object
Returns the value of attribute current_job.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def current_job @current_job end |
.db ⇒ Object
Returns the value of attribute db.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def db @db end |
.db_config ⇒ Object (readonly)
Returns the value of attribute db_config.
39 40 41 |
# File 'lib/bosh/director/config.rb', line 39 def db_config @db_config end |
.default_ssh_options ⇒ Object
Returns the value of attribute default_ssh_options.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def end |
.dns ⇒ Object
Returns the value of attribute dns.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def dns @dns end |
.dns_db ⇒ Object
Returns the value of attribute dns_db.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def dns_db @dns_db end |
.dns_domain_name ⇒ Object
Returns the value of attribute dns_domain_name.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def dns_domain_name @dns_domain_name end |
.enable_snapshots ⇒ Object
Returns the value of attribute enable_snapshots.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def enable_snapshots @enable_snapshots end |
.encryption ⇒ Object
Returns the value of attribute encryption.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def encryption @encryption end |
.event_log ⇒ Object
Returns the value of attribute event_log.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def event_log @event_log end |
.fix_stateful_nodes ⇒ Object
Returns the value of attribute fix_stateful_nodes.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def fix_stateful_nodes @fix_stateful_nodes end |
.ignore_missing_gateway ⇒ Object (readonly)
Returns the value of attribute ignore_missing_gateway.
39 40 41 |
# File 'lib/bosh/director/config.rb', line 39 def ignore_missing_gateway @ignore_missing_gateway end |
.keep_unreachable_vms ⇒ Object
Returns the value of attribute keep_unreachable_vms.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def keep_unreachable_vms @keep_unreachable_vms end |
.logger ⇒ Object
Returns the value of attribute logger.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def logger @logger end |
.max_tasks ⇒ Object
Returns the value of attribute max_tasks.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def max_tasks @max_tasks end |
.max_threads ⇒ Object
Returns the value of attribute max_threads.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def max_threads @max_threads end |
.max_vm_create_tries ⇒ Object
Returns the value of attribute max_vm_create_tries.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def max_vm_create_tries @max_vm_create_tries end |
.name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def name @name end |
.nats_uri ⇒ Object
Returns the value of attribute nats_uri.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def nats_uri @nats_uri end |
.process_uuid ⇒ Object
Returns the value of attribute process_uuid.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def process_uuid @process_uuid end |
.redis_logger_level ⇒ Object (readonly)
Returns the value of attribute redis_logger_level.
39 40 41 |
# File 'lib/bosh/director/config.rb', line 39 def redis_logger_level @redis_logger_level end |
.result ⇒ Object
Returns the value of attribute result.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def result @result end |
.revision ⇒ Object
Returns the value of attribute revision.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def revision @revision end |
.task_checkpoint_interval ⇒ Object
Returns the value of attribute task_checkpoint_interval.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def task_checkpoint_interval @task_checkpoint_interval end |
.trusted_certs ⇒ Object
Returns the value of attribute trusted_certs.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def trusted_certs @trusted_certs end |
.uuid ⇒ Object
Returns the value of attribute uuid.
10 11 12 |
# File 'lib/bosh/director/config.rb', line 10 def uuid @uuid end |
Class Method Details
.clear ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bosh/director/config.rb', line 45 def clear self.instance_variables.each do |ivar| self.instance_variable_set(ivar, nil) end Thread.list.each do |thr| thr[:bosh] = nil end @blobstore = nil @compiled_package_cache = nil @compiled_package_blobstore = nil = nil @nats = nil @nats_rpc = nil @cloud = nil end |
.cloud ⇒ Object
232 233 234 235 236 237 238 239 |
# File 'lib/bosh/director/config.rb', line 232 def cloud @lock.synchronize do if @cloud.nil? @cloud = Bosh::Clouds::Provider.create(, @uuid) end end @cloud end |
.cloud_type ⇒ Object
226 227 228 229 230 |
# File 'lib/bosh/director/config.rb', line 226 def cloud_type if ['plugin'] || ['provider']['name'] end end |
.compiled_package_cache_blobstore ⇒ Object
211 212 213 214 215 216 217 218 219 220 |
# File 'lib/bosh/director/config.rb', line 211 def compiled_package_cache_blobstore @lock.synchronize do if @compiled_package_cache_blobstore.nil? && use_compiled_package_cache? provider = ['provider'] = ['options'] @compiled_package_cache_blobstore = Bosh::Blobstore::Client.safe_create(provider, ) end end @compiled_package_cache_blobstore end |
.compiled_package_cache_provider ⇒ Object
222 223 224 |
# File 'lib/bosh/director/config.rb', line 222 def compiled_package_cache_provider use_compiled_package_cache? ? ['provider'] : nil end |
.configure(config) ⇒ Object
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/bosh/director/config.rb', line 65 def configure(config) @max_vm_create_tries = Integer(config.fetch('max_vm_create_tries', 5)) @base_dir = config['dir'] FileUtils.mkdir_p(@base_dir) # checkpoint task progress every 30 secs @task_checkpoint_interval = 30 logging_config = config.fetch('logging', {}) if logging_config.has_key?('file') @log_file_path = logging_config.fetch('file') shared_appender = Logging.appenders.file( 'DirectorLogFile', filename: @log_file_path, layout: ThreadFormatter.layout ) else shared_appender = Logging.appenders.io( 'DirectorStdOut', STDOUT, layout: ThreadFormatter.layout ) end @logger = Logging::Logger.new('Director') @logger.add_appenders(shared_appender) @logger.level = Logging.levelify(logging_config.fetch('level', 'debug')) # use a separate logger with the same appender to avoid multiple file writers redis_logger = Logging::Logger.new('DirectorRedis') redis_logger.add_appenders(shared_appender) logging_config = config.fetch('redis', {}).fetch('logging', {}) @redis_logger_level = Logging.levelify(logging_config.fetch('level', 'info')) redis_logger.level = @redis_logger_level # Event logger supposed to be overridden per task, # the default one does nothing @event_log = EventLog::Log.new # by default keep only last 100 tasks of each type in disk @max_tasks = config.fetch('max_tasks', 100).to_i @max_threads = config.fetch('max_threads', 32).to_i self. = { :host => config['redis']['host'], :port => config['redis']['port'], :password => config['redis']['password'], :logger => redis_logger } @revision = get_revision @logger.info("Starting BOSH Director: #{VERSION} (#{@revision})") @process_uuid = SecureRandom.uuid @nats_uri = config['mbus'] = config['default_ssh_options'] = config['cloud'] = config['compiled_package_cache'] @name = config['name'] || '' @compiled_package_cache = nil @db_config = config['db'] @db = configure_db(config['db']) @dns = config['dns'] if @dns && @dns['db'] @dns_db = configure_db(@dns['db']) if @dns_db # Load these constants early. # These constants are not 'require'd, they are 'autoload'ed # in models.rb. We're seeing that in 1.9.3 that sometimes # the constants loaded from one thread are not visible to other threads, # causing failures. # These constants cannot be required because they are Sequel model classes # that refer to database configuration that is only present when the (optional) # powerdns job is present and configured and points to a valid DB. # This is an attempt to make sure the constants are loaded # before forking off to other threads, hopefully eliminating the errors. Bosh::Director::Models::Dns::Record.class Bosh::Director::Models::Dns::Domain.class end end @dns_manager = DnsManagerProvider.create @uuid = override_uuid || Bosh::Director::Models::DirectorAttribute.find_or_create_uuid(@logger) @logger.info("Director UUID: #{@uuid}") @encryption = config['encryption'] @fix_stateful_nodes = config.fetch('scan_and_fix', {}) .fetch('auto_fix_stateful_nodes', false) @enable_snapshots = config.fetch('snapshots', {}).fetch('enabled', false) @trusted_certs = config['trusted_certs'] || '' @ignore_missing_gateway = config['ignore_missing_gateway'] @keep_unreachable_vms = config.fetch('keep_unreachable_vms', false) Bosh::Clouds::Config.configure(self) @lock = Monitor.new end |
.configure_db(db_config) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/bosh/director/config.rb', line 188 def configure_db(db_config) patch_sqlite if db_config['adapter'] == 'sqlite' = db_config.delete('connection_options') {{}} db_config.delete_if { |_, v| v.to_s.empty? } db_config = db_config.merge() db = Sequel.connect(db_config) Bosh::Common.retryable(sleep: 0.5, tries: 20, on: [Exception]) do db.extension :connection_validator true end db.pool.connection_validation_timeout = -1 if logger db.logger = logger db.sql_log_level = :debug end db end |
.cpi_task_log ⇒ Object
241 242 243 |
# File 'lib/bosh/director/config.rb', line 241 def cpi_task_log Config..fetch('properties', {}).fetch('cpi_log') end |
.encryption? ⇒ Boolean
298 299 300 |
# File 'lib/bosh/director/config.rb', line 298 def encryption? @encryption end |
.generate_temp_dir ⇒ Object
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/bosh/director/config.rb', line 306 def generate_temp_dir temp_dir = Dir.mktmpdir ENV["TMPDIR"] = temp_dir FileUtils.mkdir_p(temp_dir) at_exit do begin if $! status = $!.is_a?(::SystemExit) ? $!.status : 1 else status = 0 end FileUtils.rm_rf(temp_dir) ensure exit status end end temp_dir end |
.get_revision ⇒ Object
180 181 182 183 184 185 186 |
# File 'lib/bosh/director/config.rb', line 180 def get_revision Dir.chdir(File.('../../../../../..', __FILE__)) revision_command = '(cat REVISION 2> /dev/null || ' + 'git show-ref --head --hash=8 2> /dev/null || ' + 'echo 00000000) | head -n1' `#{revision_command}`.strip end |
.job_cancelled? ⇒ Boolean Also known as: task_checkpoint
245 246 247 |
# File 'lib/bosh/director/config.rb', line 245 def job_cancelled? @current_job.task_checkpoint if @current_job end |
.load_file(path) ⇒ Object
392 393 394 |
# File 'lib/bosh/director/config.rb', line 392 def load_file(path) Config.new(Psych.load_file(path)) end |
.load_hash(hash) ⇒ Object
396 397 398 |
# File 'lib/bosh/director/config.rb', line 396 def load_hash(hash) Config.new(hash) end |
.log_dir ⇒ Object
172 173 174 |
# File 'lib/bosh/director/config.rb', line 172 def log_dir File.dirname(@log_file_path) if @log_file_path end |
.nats_rpc ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/bosh/director/config.rb', line 270 def nats_rpc # double-check locking to reduce synchronization if @nats_rpc.nil? @lock.synchronize do if @nats_rpc.nil? @nats_rpc = NatsRpc.new(@nats_uri) end end end @nats_rpc end |
.override_uuid ⇒ Object
Migrates director UUID to database Currently used by integration tests to set director UUID
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/bosh/director/config.rb', line 357 def override_uuid new_uuid = nil state_file = File.join(base_dir, 'state.json') begin open(state_file, 'r+') do |file| # Lock before read to avoid director/worker race condition file.flock(File::LOCK_EX) state = Yajl::Parser.parse(file) || {} # Empty state file to prevent blocked processes from attempting to set UUID file.truncate(0) if state['uuid'] Bosh::Director::Models::DirectorAttribute.update_or_create_uuid(state['uuid'], @logger) @logger.info("Using director UUID #{state['uuid']} from #{state_file}") new_uuid = state['uuid'] end # Unlock after storing UUID file.flock(File::LOCK_UN) end FileUtils.rm_f(state_file) rescue Errno::ENOENT # Catch race condition since another process (director/worker) might migrated the state end new_uuid end |
.patch_sqlite ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/bosh/director/config.rb', line 325 def patch_sqlite return if @patched_sqlite @patched_sqlite = true require 'sequel' require 'sequel/adapters/sqlite' Sequel::SQLite::Database.class_eval do def connect(server) opts = server_opts(server) opts[:database] = ':memory:' if blank_object?(opts[:database]) db = ::SQLite3::Database.new(opts[:database]) db.busy_handler do |retries| Bosh::Director::Config.logger.debug "SQLITE BUSY, retry ##{retries}" sleep(0.1) retries < 20 end connection_pragmas.each { |s| log_yield(s) { db.execute_batch(s) } } class << db attr_reader :prepared_statements end db.instance_variable_set(:@prepared_statements, {}) db end end end |
.redis ⇒ Object
282 283 284 |
# File 'lib/bosh/director/config.rb', line 282 def redis threaded[:redis] ||= Redis.new() end |
.redis? ⇒ Boolean
294 295 296 |
# File 'lib/bosh/director/config.rb', line 294 def redis? !threaded[:redis].nil? end |
.redis_logger=(logger) ⇒ Object
286 287 288 289 290 291 292 |
# File 'lib/bosh/director/config.rb', line 286 def redis_logger=(logger) if redis? redis.client.logger = logger else [:logger] = logger end end |
.redis_options ⇒ Object
251 252 253 |
# File 'lib/bosh/director/config.rb', line 251 def ||= {} end |
.redis_options=(options) ⇒ Object
259 260 261 |
# File 'lib/bosh/director/config.rb', line 259 def () = end |
.threaded ⇒ Object
302 303 304 |
# File 'lib/bosh/director/config.rb', line 302 def threaded Thread.current[:bosh] ||= {} end |
.use_compiled_package_cache? ⇒ Boolean
176 177 178 |
# File 'lib/bosh/director/config.rb', line 176 def use_compiled_package_cache? !.nil? end |
Instance Method Details
#backup_blobstore_config ⇒ Object
453 454 455 |
# File 'lib/bosh/director/config.rb', line 453 def backup_blobstore_config hash['backup_destination'] end |
#blobstore_config ⇒ Object
449 450 451 |
# File 'lib/bosh/director/config.rb', line 449 def blobstore_config hash.fetch('blobstore') end |
#configure_evil_config_singleton! ⇒ Object
457 458 459 |
# File 'lib/bosh/director/config.rb', line 457 def configure_evil_config_singleton! Config.configure(hash) end |
#identity_provider ⇒ Object
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/bosh/director/config.rb', line 413 def identity_provider @identity_provider ||= begin # no fetching w defaults? user_management = hash['user_management'] user_management ||= {'provider' => 'local'} provider_name = user_management['provider'] providers = { 'uaa' => Bosh::Director::Api::UAAIdentityProvider, 'local' => Bosh::Director::Api::LocalIdentityProvider, } provider_class = providers[provider_name] if provider_class.nil? raise ArgumentError, "Unknown user management provider '#{provider_name}', " + "available providers are: #{providers.keys.join(", ")}" end Config.logger.debug("Director configured with '#{provider_name}' user management provider") provider_class.new(user_management[provider_name] || {}, Bosh::Director::Api::DirectorUUIDProvider.new(Config)) end end |
#name ⇒ Object
401 402 403 |
# File 'lib/bosh/director/config.rb', line 401 def name hash['name'] end |
#port ⇒ Object
405 406 407 |
# File 'lib/bosh/director/config.rb', line 405 def port hash['port'] end |
#resque_logger ⇒ Object
437 438 439 440 441 442 443 444 445 446 447 |
# File 'lib/bosh/director/config.rb', line 437 def resque_logger logger = Logging::Logger.new('DirectorWorker') resque_logging = hash.fetch('resque', {}).fetch('logging', {}) if resque_logging.has_key?('file') logger.add_appenders(Logging.appenders.file('DirectorWorkerFile', filename: resque_logging.fetch('file'), layout: ThreadFormatter.layout)) else logger.add_appenders(Logging.appenders.stdout('DirectorWorkerIO', layout: ThreadFormatter.layout)) end logger.level = Logging.levelify(resque_logging.fetch('level', 'info')) logger end |
#scheduled_jobs ⇒ Object
409 410 411 |
# File 'lib/bosh/director/config.rb', line 409 def scheduled_jobs hash['scheduled_jobs'] || [] end |