Module: Bosh::Registry

Defined in:
lib/bosh/registry/config.rb,
lib/bosh/registry.rb,
lib/bosh/registry/client.rb,
lib/bosh/registry/errors.rb,
lib/bosh/registry/models.rb,
lib/bosh/registry/runner.rb,
lib/bosh/registry/version.rb,
lib/bosh/registry/yaml_helper.rb,
lib/bosh/registry/api_controller.rb,
lib/bosh/registry/instance_manager.rb,
lib/bosh/registry/instance_manager/aws.rb,
lib/bosh/registry/instance_manager/openstack.rb

Overview

Copyright © 2009-2013 VMware, Inc.

Defined Under Namespace

Modules: Models, YamlHelper Classes: AWSError, ApiController, Client, ConfigError, ConnectionError, Error, FatalError, InstanceError, InstanceManager, InstanceNotFound, Runner

Constant Summary collapse

VERSION =
'1.2710.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dbObject

Returns the value of attribute db.



11
12
13
# File 'lib/bosh/registry/config.rb', line 11

def db
  @db
end

.http_passwordObject

Returns the value of attribute http_password.



10
11
12
# File 'lib/bosh/registry/config.rb', line 10

def http_password
  @http_password
end

.http_portObject

Returns the value of attribute http_port.



8
9
10
# File 'lib/bosh/registry/config.rb', line 8

def http_port
  @http_port
end

.http_userObject

Returns the value of attribute http_user.



9
10
11
# File 'lib/bosh/registry/config.rb', line 9

def http_user
  @http_user
end

.instance_managerObject

Returns the value of attribute instance_manager.



12
13
14
# File 'lib/bosh/registry/config.rb', line 12

def instance_manager
  @instance_manager
end

.loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/bosh/registry/config.rb', line 7

def logger
  @logger
end

Class Method Details

.configure(config) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bosh/registry/config.rb', line 14

def configure(config)
  validate_config(config)

  @logger ||= Logger.new(config["logfile"] || STDOUT)
  if config["loglevel"].kind_of?(String)
    @logger.level = Logger.const_get(config["loglevel"].upcase)
  end

  @http_port = config["http"]["port"]
  @http_user = config["http"]["user"]
  @http_password = config["http"]["password"]

  @db = connect_db(config["db"])

  plugin = config["cloud"]["plugin"]
  begin
    require "bosh/registry/instance_manager/#{plugin}"
  rescue LoadError
    raise ConfigError, "Could not find Provider Plugin: #{plugin}"
  end
  @instance_manager = Bosh::Registry::InstanceManager.const_get(plugin.capitalize).new(config["cloud"])
end

.connect_db(db_config) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bosh/registry/config.rb', line 37

def connect_db(db_config)
  connection_options = db_config.delete('connection_options') {{}}
  db_config.delete_if { |_, v| v.to_s.empty? }
  db_config = db_config.merge(connection_options)

  db = Sequel.connect(db_config)
  if logger
    db.logger = @logger
    db.sql_log_level = :debug
  end

  db
end

.validate_config(config) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bosh/registry/config.rb', line 51

def validate_config(config)
  unless config.is_a?(Hash)
    raise ConfigError, "Invalid config format, Hash expected, " \
                       "#{config.class} given"
  end

  unless config.has_key?("http") && config["http"].is_a?(Hash)
    raise ConfigError, "HTTP configuration is missing from config file"
  end

  unless config.has_key?("db") && config["db"].is_a?(Hash)
    raise ConfigError, "Database configuration is missing from config file"
  end

  unless config.has_key?("cloud") && config["cloud"].is_a?(Hash)
    raise ConfigError, "Cloud configuration is missing from config file"
  end

  if config["cloud"]["plugin"].nil?
    raise ConfigError, "Cloud plugin is missing from config file"
  end
end