Class: VSphereCloud::Config
- Inherits:
-
Object
- Object
- VSphereCloud::Config
- Defined in:
- lib/cloud/vsphere/config.rb
Class Method Summary collapse
Instance Method Summary collapse
- #agent ⇒ Object
- #client ⇒ Object
- #copy_disks ⇒ Object
- #datacenter_allow_mixed_datastores ⇒ Object
- #datacenter_clusters ⇒ Object
- #datacenter_datastore_pattern ⇒ Object
- #datacenter_disk_path ⇒ Object
- #datacenter_name ⇒ Object
- #datacenter_persistent_datastore_pattern ⇒ Object
- #datacenter_template_folder ⇒ Object
- #datacenter_use_sub_folder ⇒ Object
- #datacenter_vm_folder ⇒ Object
-
#initialize(config_hash) ⇒ Config
constructor
A new instance of Config.
- #logger ⇒ Object
- #mem_overcommit ⇒ Object
- #rest_client ⇒ Object
- #soap_log ⇒ Object
- #validate ⇒ Object
- #vcenter_host ⇒ Object
- #vcenter_password ⇒ Object
- #vcenter_user ⇒ Object
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
#agent ⇒ Object
81 82 83 |
# File 'lib/cloud/vsphere/config.rb', line 81 def agent config['agent'] end |
#client ⇒ Object
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.login(vcenter['user'], vcenter['password'], 'en') end @client end |
#copy_disks ⇒ Object
77 78 79 |
# File 'lib/cloud/vsphere/config.rb', line 77 def copy_disks !!config['copy_disks'] end |
#datacenter_allow_mixed_datastores ⇒ Object
125 126 127 |
# File 'lib/cloud/vsphere/config.rb', line 125 def datacenter_allow_mixed_datastores !!vcenter_datacenter['allow_mixed_datastores'] end |
#datacenter_clusters ⇒ Object
121 122 123 |
# File 'lib/cloud/vsphere/config.rb', line 121 def datacenter_clusters @cluster_objs ||= cluster_objs end |
#datacenter_datastore_pattern ⇒ Object
113 114 115 |
# File 'lib/cloud/vsphere/config.rb', line 113 def datacenter_datastore_pattern Regexp.new(vcenter_datacenter['datastore_pattern']) end |
#datacenter_disk_path ⇒ Object
109 110 111 |
# File 'lib/cloud/vsphere/config.rb', line 109 def datacenter_disk_path vcenter_datacenter['disk_path'] end |
#datacenter_name ⇒ Object
97 98 99 |
# File 'lib/cloud/vsphere/config.rb', line 97 def datacenter_name vcenter_datacenter['name'] end |
#datacenter_persistent_datastore_pattern ⇒ Object
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_folder ⇒ Object
105 106 107 |
# File 'lib/cloud/vsphere/config.rb', line 105 def datacenter_template_folder vcenter_datacenter['template_folder'] end |
#datacenter_use_sub_folder ⇒ Object
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_folder ⇒ Object
101 102 103 |
# File 'lib/cloud/vsphere/config.rb', line 101 def datacenter_vm_folder vcenter_datacenter['vm_folder'] end |
#logger ⇒ Object
39 40 41 |
# File 'lib/cloud/vsphere/config.rb', line 39 def logger @logger ||= Bosh::Clouds::Config.logger end |
#mem_overcommit ⇒ Object
73 74 75 |
# File 'lib/cloud/vsphere/config.rb', line 73 def mem_overcommit config.fetch('mem_overcommit_ratio', @default_overcommit_ratio) end |
#rest_client ⇒ Object
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 = client.soap_stub. @rest_client..parse(, URI.parse("https://#{vcenter_host}")) end @rest_client end |
#soap_log ⇒ Object
54 55 56 |
# File 'lib/cloud/vsphere/config.rb', line 54 def soap_log config['soap_log'] || config['cpi_log'] end |
#validate ⇒ Object
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_host ⇒ Object
85 86 87 |
# File 'lib/cloud/vsphere/config.rb', line 85 def vcenter_host vcenter['host'] end |
#vcenter_password ⇒ Object
93 94 95 |
# File 'lib/cloud/vsphere/config.rb', line 93 def vcenter_password vcenter['password'] end |
#vcenter_user ⇒ Object
89 90 91 |
# File 'lib/cloud/vsphere/config.rb', line 89 def vcenter_user vcenter['user'] end |