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.



12
13
14
15
16
17
18
19
20
21
# File 'lib/cloud/vsphere/config.rb', line 12

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



6
7
8
9
10
# File 'lib/cloud/vsphere/config.rb', line 6

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

Instance Method Details

#agentObject



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

def agent
  config['agent']
end

#clientObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/cloud/vsphere/config.rb', line 43

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

#copy_disksObject



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

def copy_disks
  !!config['copy_disks']
end

#datacenter_allow_mixed_datastoresObject



125
126
127
# File 'lib/cloud/vsphere/config.rb', line 125

def datacenter_allow_mixed_datastores
  !!vcenter_datacenter['allow_mixed_datastores']
end

#datacenter_clustersObject



121
122
123
# File 'lib/cloud/vsphere/config.rb', line 121

def datacenter_clusters
  @cluster_objs ||= cluster_objs
end

#datacenter_datastore_patternObject



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

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

#datacenter_disk_pathObject



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

def datacenter_disk_path
  vcenter_datacenter['disk_path']
end

#datacenter_nameObject



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

def datacenter_name
  vcenter_datacenter['name']
end

#datacenter_persistent_datastore_patternObject



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

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

#datacenter_template_folderObject



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

def datacenter_template_folder
  vcenter_datacenter['template_folder']
end

#datacenter_use_sub_folderObject



129
130
131
132
# File 'lib/cloud/vsphere/config.rb', line 129

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

#datacenter_vm_folderObject



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

def datacenter_vm_folder
  vcenter_datacenter['vm_folder']
end

#loggerObject



39
40
41
# File 'lib/cloud/vsphere/config.rb', line 39

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

#mem_overcommitObject



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

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

#rest_clientObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cloud/vsphere/config.rb', line 58

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



54
55
56
# File 'lib/cloud/vsphere/config.rb', line 54

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

#validateObject



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

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



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

def vcenter_host
  vcenter['host']
end

#vcenter_passwordObject



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

def vcenter_password
  vcenter['password']
end

#vcenter_userObject



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

def vcenter_user
  vcenter['user']
end