Class: Bosh::Deployer::Configuration

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/bosh/deployer/configuration.rb

Constant Summary

Constants included from Helpers

Helpers::DEPLOYMENTS_FILE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#close_ssh_sessions, #cloud_plugin, #dig_hash, #is_tgz?, #process_exists?, #remote_tunnel, #socket_readable?, #strip_relative_path

Instance Attribute Details

#agent_propertiesObject

Returns the value of attribute agent_properties.



5
6
7
# File 'lib/bosh/deployer/configuration.rb', line 5

def agent_properties
  @agent_properties
end

#bosh_ipObject

Returns the value of attribute bosh_ip.



5
6
7
# File 'lib/bosh/deployer/configuration.rb', line 5

def bosh_ip
  @bosh_ip
end

#cloud_optionsObject

Returns the value of attribute cloud_options.



5
6
7
# File 'lib/bosh/deployer/configuration.rb', line 5

def cloud_options
  @cloud_options
end

#dbObject

Returns the value of attribute db.



5
6
7
# File 'lib/bosh/deployer/configuration.rb', line 5

def db
  @db
end

#envObject

Returns the value of attribute env.



5
6
7
# File 'lib/bosh/deployer/configuration.rb', line 5

def env
  @env
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/bosh/deployer/configuration.rb', line 5

def logger
  @logger
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/bosh/deployer/configuration.rb', line 5

def name
  @name
end

#net_confObject

Returns the value of attribute net_conf.



5
6
7
# File 'lib/bosh/deployer/configuration.rb', line 5

def net_conf
  @net_conf
end

#resourcesObject

Returns the value of attribute resources.



5
6
7
# File 'lib/bosh/deployer/configuration.rb', line 5

def resources
  @resources
end

#spec_propertiesObject

Returns the value of attribute spec_properties.



5
6
7
# File 'lib/bosh/deployer/configuration.rb', line 5

def spec_properties
  @spec_properties
end

#uuidObject

Returns the value of attribute uuid.



5
6
7
# File 'lib/bosh/deployer/configuration.rb', line 5

def uuid
  @uuid
end

Instance Method Details

#agentObject



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/bosh/deployer/configuration.rb', line 71

def agent
  uri = URI.parse(agent_url)
  user, password = uri.userinfo.split(':', 2)
  uri.userinfo = nil
  uri.host = bosh_ip
  Bosh::Agent::HTTPClient.new(uri.to_s, {
    'user' => user,
    'password' => password,
    'reply_to' => uuid,
  })
end

#agent_urlObject



83
84
85
# File 'lib/bosh/deployer/configuration.rb', line 83

def agent_url
  @cloud_options['properties']['agent']['mbus']
end

#cloudObject

rubocop:enable MethodLength



63
64
65
66
67
68
69
# File 'lib/bosh/deployer/configuration.rb', line 63

def cloud
  if @cloud.nil?
    @cloud = Bosh::Clouds::Provider.create(
      @cloud_options['plugin'], @cloud_options['properties'])
  end
  @cloud
end

#configure(config) ⇒ Object

rubocop:disable MethodLength



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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bosh/deployer/configuration.rb', line 9

def configure(config)
  plugin = cloud_plugin(config)

  config = deep_merge(load_defaults(plugin), config)

  @base_dir = config['dir']
  FileUtils.mkdir_p(@base_dir)

  @name = config['name']
  @cloud_options = config['cloud']
  @net_conf = config['network']
  @bosh_ip = @net_conf['ip']
  @resources = config['resources']
  @env = config['env']

  @logger = Logger.new(config['logging']['file'] || STDOUT)
  @logger.level = Logger.const_get(config['logging']['level'].upcase)
  @logger.formatter = ThreadFormatter.new

  apply_spec = config['apply_spec']
  @spec_properties = apply_spec['properties']
  @agent_properties = apply_spec['agent']

  @db = Sequel.sqlite

  migrate_cpi

  @db.create_table :instances do
    primary_key :id
    column :name, :text, unique: true, null: false
    column :uuid, :text
    column :stemcell_cid, :text
    column :stemcell_sha1, :text
    column :stemcell_name, :text
    column :config_sha1, :text
    column :vm_cid, :text
    column :disk_cid, :text
  end

  Sequel::Model.plugin :validation_helpers

  Bosh::Clouds::Config.configure(self)

  require 'bosh/deployer/models/instance'

  @cloud_options['properties']['agent']['mbus'] ||=
    'https://vcap:[email protected]:6868'

  @disk_model = nil
  @cloud = nil
  @networks = nil
end

#networksObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/bosh/deployer/configuration.rb', line 87

def networks
  return @networks if @networks

  @networks = {
    'bosh' => {
      'cloud_properties' => @net_conf['cloud_properties'],
      'netmask' => @net_conf['netmask'],
      'gateway' => @net_conf['gateway'],
      'ip' => @net_conf['ip'],
      'dns' => @net_conf['dns'],
      'type' => @net_conf['type'],
      'default' => %w(dns gateway)
    }
  }
  if @net_conf['vip']
    @networks['vip'] = {
      'ip' => @net_conf['vip'],
      'type' => 'vip',
      'cloud_properties' => {}
    }
  end

  @networks
end

#task_checkpointObject



112
113
114
115
116
117
# File 'lib/bosh/deployer/configuration.rb', line 112

def task_checkpoint
  # Bosh::Clouds::Config (bosh_cli >= 0.5.1) delegates task_checkpoint
  # method to periodically check if director task is cancelled,
  # so we need to define a void method in Bosh::Deployer::Config to avoid
  # NoMethodError exceptions.
end