Class: VSphereCloud::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud/vsphere/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_hash) ⇒ Config

Returns a new instance of Config.



9
10
11
12
13
14
15
16
17
18
# File 'lib/cloud/vsphere/config.rb', line 9

def initialize(config_hash)
  @config = config_hash
  @vcenter_host = nil
  @vcenter_user = nil
  @vcenter_password = nil
  @rest_client = nil
  @default_overcommit_ratio = 1.0

  @is_validated = false
end

Class Method Details

.build(config_hash) ⇒ Object



3
4
5
6
7
# File 'lib/cloud/vsphere/config.rb', line 3

def self.build(config_hash)
  config = new(config_hash)
  config.validate
  config
end

Instance Method Details

#agentObject



74
75
76
# File 'lib/cloud/vsphere/config.rb', line 74

def agent
  config['agent']
end

#clientObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/cloud/vsphere/config.rb', line 40

def client
  unless @client
    host = "https://#{vcenter['host']}/sdk/vimService"
    @client = Client.new(host, soap_log: soap_log)

    @client.(vcenter['user'], vcenter['password'], 'en')
  end

  @client
end

#datacenter_clustersObject



114
115
116
# File 'lib/cloud/vsphere/config.rb', line 114

def datacenter_clusters
  @cluster_objs ||= cluster_objs
end

#datacenter_datastore_patternObject



106
107
108
# File 'lib/cloud/vsphere/config.rb', line 106

def datacenter_datastore_pattern
  Regexp.new(vcenter_datacenter['datastore_pattern'])
end

#datacenter_disk_pathObject



102
103
104
# File 'lib/cloud/vsphere/config.rb', line 102

def datacenter_disk_path
  vcenter_datacenter['disk_path']
end

#datacenter_nameObject



90
91
92
# File 'lib/cloud/vsphere/config.rb', line 90

def datacenter_name
  vcenter_datacenter['name']
end

#datacenter_persistent_datastore_patternObject



110
111
112
# File 'lib/cloud/vsphere/config.rb', line 110

def datacenter_persistent_datastore_pattern
  Regexp.new(vcenter_datacenter['persistent_datastore_pattern'])
end

#datacenter_template_folderObject



98
99
100
# File 'lib/cloud/vsphere/config.rb', line 98

def datacenter_template_folder
  vcenter_datacenter['template_folder']
end

#datacenter_use_sub_folderObject



118
119
120
121
# File 'lib/cloud/vsphere/config.rb', line 118

def datacenter_use_sub_folder
  datacenter_clusters.any? { |_, cluster| cluster.resource_pool } ||
    !!vcenter_datacenter['use_sub_folder']
end

#datacenter_vm_folderObject



94
95
96
# File 'lib/cloud/vsphere/config.rb', line 94

def datacenter_vm_folder
  vcenter_datacenter['vm_folder']
end

#loggerObject



36
37
38
# File 'lib/cloud/vsphere/config.rb', line 36

def logger
  @logger ||= Bosh::Clouds::Config.logger
end

#mem_overcommitObject



70
71
72
# File 'lib/cloud/vsphere/config.rb', line 70

def mem_overcommit
  config.fetch('mem_overcommit_ratio', @default_overcommit_ratio)
end

#rest_clientObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cloud/vsphere/config.rb', line 55

def rest_client
  unless @rest_client
    @rest_client = HTTPClient.new
    @rest_client.send_timeout = 14400 # 4 hours, for stemcell uploads
    @rest_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE

    # HACK: read the session from the SOAP client so we don't leak sessions
    # when using the REST client
    cookie_str = client.soap_stub.cookie
    @rest_client.cookie_manager.parse(cookie_str, URI.parse("https://#{vcenter_host}"))
  end

  @rest_client
end

#soap_logObject



51
52
53
# File 'lib/cloud/vsphere/config.rb', line 51

def soap_log
  config['soap_log'] || config['cpi_log']
end

#validateObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cloud/vsphere/config.rb', line 20

def validate
  return true if @is_validated

  unless config['vcenters'].size == 1
    raise 'vSphere CPI only supports a single vCenter'
  end

  unless config['vcenters'].first['datacenters'].size ==1
    raise 'vSphere CPI only supports a single datacenter'
  end

  validate_schema

  @is_validated = true
end

#vcenter_hostObject



78
79
80
# File 'lib/cloud/vsphere/config.rb', line 78

def vcenter_host
  vcenter['host']
end

#vcenter_passwordObject



86
87
88
# File 'lib/cloud/vsphere/config.rb', line 86

def vcenter_password
  vcenter['password']
end

#vcenter_userObject



82
83
84
# File 'lib/cloud/vsphere/config.rb', line 82

def vcenter_user
  vcenter['user']
end