vmpooler 0.16.1 → 0.18.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'vmpooler/providers/base'
4
+ require 'bigdecimal'
5
+ require 'bigdecimal/util'
4
6
 
5
7
  module Vmpooler
6
8
  class PoolManager
@@ -49,9 +51,7 @@ module Vmpooler
49
51
  end
50
52
 
51
53
  def folder_configured?(folder_title, base_folder, configured_folders, whitelist)
52
- if whitelist
53
- return true if whitelist.include?(folder_title)
54
- end
54
+ return true if whitelist&.include?(folder_title)
55
55
  return false unless configured_folders.keys.include?(folder_title)
56
56
  return false unless configured_folders[folder_title] == base_folder
57
57
 
@@ -68,7 +68,7 @@ module Vmpooler
68
68
  redis.hset("vmpooler__vm__#{vm_name}", 'destroy', Time.now)
69
69
 
70
70
  # Auto-expire metadata key
71
- redis.expire('vmpooler__vm__' + vm_name, (data_ttl * 60 * 60))
71
+ redis.expire("vmpooler__vm__#{vm_name}", (data_ttl * 60 * 60))
72
72
  redis.exec
73
73
  end
74
74
 
@@ -203,9 +203,7 @@ module Vmpooler
203
203
  return
204
204
  end
205
205
  wait_for_host_selection(dc, target, loop_delay, max_age) if target[dc].key?('checking')
206
- if target[dc].key?('check_time_finished')
207
- select_target_hosts(target, cluster, datacenter) if now - target[dc]['check_time_finished'] > max_age
208
- end
206
+ select_target_hosts(target, cluster, datacenter) if target[dc].key?('check_time_finished') && now - target[dc]['check_time_finished'] > max_age
209
207
  end
210
208
 
211
209
  def wait_for_host_selection(dc, target, maxloop = 0, loop_delay = 1, max_age = 60)
@@ -306,19 +304,26 @@ module Vmpooler
306
304
 
307
305
  template_vm_object = find_template_vm(pool, connection)
308
306
 
307
+ extra_config = [
308
+ { key: 'guestinfo.hostname', value: new_vmname }
309
+ ]
310
+
311
+ if pool.key?('snapshot_mainMem_ioBlockPages')
312
+ ioblockpages = pool['snapshot_mainMem_ioBlockPages']
313
+ extra_config.push(
314
+ { key: 'mainMem.ioBlockPages', value: ioblockpages }
315
+ )
316
+ end
317
+ if pool.key?('snapshot_mainMem_iowait')
318
+ iowait = pool['snapshot_mainMem_iowait']
319
+ extra_config.push(
320
+ { key: 'mainMem.iowait', value: iowait }
321
+ )
322
+ end
323
+
309
324
  # Annotate with creation time, origin template, etc.
310
325
  # Add extraconfig options that can be queried by vmtools
311
- config_spec = RbVmomi::VIM.VirtualMachineConfigSpec(
312
- annotation: JSON.pretty_generate(
313
- name: new_vmname,
314
- created_by: provider_config['username'],
315
- base_template: template_path,
316
- creation_timestamp: Time.now.utc
317
- ),
318
- extraConfig: [
319
- { key: 'guestinfo.hostname', value: new_vmname }
320
- ]
321
- )
326
+ config_spec = create_config_spec(new_vmname, template_path, extra_config)
322
327
 
323
328
  # Check if alternate network configuration is specified and add configuration
324
329
  if pool.key?('network')
@@ -358,6 +363,18 @@ module Vmpooler
358
363
  vm_hash
359
364
  end
360
365
 
366
+ def create_config_spec(vm_name, template_name, extra_config)
367
+ RbVmomi::VIM.VirtualMachineConfigSpec(
368
+ annotation: JSON.pretty_generate(
369
+ name: vm_name,
370
+ created_by: provider_config['username'],
371
+ base_template: template_name,
372
+ creation_timestamp: Time.now.utc
373
+ ),
374
+ extraConfig: extra_config
375
+ )
376
+ end
377
+
361
378
  def create_relocate_spec(target_datastore, target_datacenter_name, pool_name, connection)
362
379
  pool = pool_config(pool_name)
363
380
  target_cluster_name = get_target_cluster_from_config(pool_name)
@@ -399,15 +416,15 @@ module Vmpooler
399
416
  # Determine network device type
400
417
  # All possible device type options here: https://vdc-download.vmware.com/vmwb-repository/dcr-public/98d63b35-d822-47fe-a87a-ddefd469df06/2e3c7b58-f2bd-486e-8bb1-a75eb0640bee/doc/vim.vm.device.VirtualEthernetCard.html
401
418
  network_device =
402
- if template_vm_network_device.is_a? RbVmomi::VIM::VirtualVmxnet2
419
+ if template_vm_network_device.instance_of? RbVmomi::VIM::VirtualVmxnet2
403
420
  RbVmomi::VIM.VirtualVmxnet2
404
- elsif template_vm_network_device.is_a? RbVmomi::VIM::VirtualVmxnet3
421
+ elsif template_vm_network_device.instance_of? RbVmomi::VIM::VirtualVmxnet3
405
422
  RbVmomi::VIM.VirtualVmxnet3
406
- elsif template_vm_network_device.is_a? RbVmomi::VIM::VirtualE1000
423
+ elsif template_vm_network_device.instance_of? RbVmomi::VIM::VirtualE1000
407
424
  RbVmomi::VIM.VirtualE1000
408
- elsif template_vm_network_device.is_a? RbVmomi::VIM::VirtualE1000e
425
+ elsif template_vm_network_device.instance_of? RbVmomi::VIM::VirtualE1000e
409
426
  RbVmomi::VIM.VirtualE1000e
410
- elsif template_vm_network_device.is_a? RbVmomi::VIM::VirtualSriovEthernetCard
427
+ elsif template_vm_network_device.instance_of? RbVmomi::VIM::VirtualSriovEthernetCard
411
428
  RbVmomi::VIM.VirtualSriovEthernetCard
412
429
  else
413
430
  RbVmomi::VIM.VirtualPCNet32
@@ -541,7 +558,7 @@ module Vmpooler
541
558
  boottime = vm_object.runtime.bootTime if vm_object.runtime&.bootTime
542
559
  powerstate = vm_object.runtime.powerState if vm_object.runtime&.powerState
543
560
 
544
- hash = {
561
+ {
545
562
  'name' => vm_object.name,
546
563
  'hostname' => hostname,
547
564
  'template' => pool_configuration['template'],
@@ -549,8 +566,6 @@ module Vmpooler
549
566
  'boottime' => boottime,
550
567
  'powerstate' => powerstate
551
568
  }
552
-
553
- hash
554
569
  end
555
570
 
556
571
  # vSphere helper methods
@@ -775,7 +790,7 @@ module Vmpooler
775
790
  }
776
791
 
777
792
  folder_object = connection.searchIndex.FindByInventoryPath(propSpecs) # rubocop:disable Naming/VariableName
778
- return nil unless folder_object.class == RbVmomi::VIM::Folder
793
+ return nil unless folder_object.instance_of? RbVmomi::VIM::Folder
779
794
 
780
795
  folder_object
781
796
  end
@@ -791,9 +806,7 @@ module Vmpooler
791
806
  # the cpu or memory utilization is bigger than the limit param
792
807
  def get_host_utilization(host, model = nil, limit = 90)
793
808
  limit = @config[:config]['utilization_limit'] if @config[:config].key?('utilization_limit')
794
- if model
795
- return nil unless host_has_cpu_model?(host, model)
796
- end
809
+ return nil if model && !host_has_cpu_model?(host, model)
797
810
  return nil if host.runtime.inMaintenanceMode
798
811
  return nil unless host.overallStatus == 'green'
799
812
  return nil unless host.configIssue.empty?
@@ -802,9 +815,9 @@ module Vmpooler
802
815
  memory_utilization = memory_utilization_for host
803
816
 
804
817
  return nil if cpu_utilization.nil?
805
- return nil if cpu_utilization == 0.0
818
+ return nil if cpu_utilization.to_d == 0.0.to_d
806
819
  return nil if memory_utilization.nil?
807
- return nil if memory_utilization == 0.0
820
+ return nil if memory_utilization.to_d == 0.0.to_d
808
821
 
809
822
  return nil if cpu_utilization > limit
810
823
  return nil if memory_utilization > limit
@@ -819,8 +832,7 @@ module Vmpooler
819
832
  def get_host_cpu_arch_version(host)
820
833
  cpu_model = host.hardware.cpuPkg[0].description
821
834
  cpu_model_parts = cpu_model.split
822
- arch_version = cpu_model_parts[4]
823
- arch_version
835
+ cpu_model_parts[4]
824
836
  end
825
837
 
826
838
  def cpu_utilization_for(host)
@@ -912,8 +924,7 @@ module Vmpooler
912
924
  target_hosts = get_cluster_host_utilization(cluster_object)
913
925
  raise("There is no host candidate in vcenter that meets all the required conditions, check that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory'") if target_hosts.empty?
914
926
 
915
- least_used_host = target_hosts.min[1]
916
- least_used_host
927
+ target_hosts.min[1]
917
928
  end
918
929
 
919
930
  def find_cluster(cluster, connection, datacentername)
@@ -960,11 +971,10 @@ module Vmpooler
960
971
  end
961
972
 
962
973
  def build_propSpecs(datacenter, folder, vmname) # rubocop:disable Naming/MethodName
963
- propSpecs = { # rubocop:disable Naming/VariableName
974
+ {
964
975
  entity => self,
965
976
  :inventoryPath => "#{datacenter}/vm/#{folder}/#{vmname}"
966
977
  }
967
- propSpecs # rubocop:disable Naming/VariableName
968
978
  end
969
979
 
970
980
  def find_vm(pool_name, vmname, connection)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vmpooler
4
- VERSION = '0.16.1'
4
+ VERSION = '0.18.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmpooler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.1
4
+ version: 0.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-08 00:00:00.000000000 Z
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -70,100 +70,100 @@ dependencies:
70
70
  name: opentelemetry-api
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 0.7.0
75
+ version: 0.8.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 0.7.0
82
+ version: 0.8.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: opentelemetry-exporter-jaeger
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 0.7.0
89
+ version: 0.8.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 0.7.0
96
+ version: 0.8.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: opentelemetry-instrumentation-concurrent_ruby
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 0.7.0
103
+ version: 0.8.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 0.7.0
110
+ version: 0.8.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: opentelemetry-instrumentation-redis
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 0.7.0
117
+ version: 0.8.0
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 0.7.0
124
+ version: 0.8.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: opentelemetry-instrumentation-sinatra
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 0.7.0
131
+ version: 0.8.0
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 0.7.0
138
+ version: 0.8.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: opentelemetry-resource_detectors
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 0.7.0
145
+ version: 0.8.0
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "~>"
150
+ - - '='
151
151
  - !ruby/object:Gem::Version
152
- version: 0.7.0
152
+ version: 0.8.0
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: opentelemetry-sdk
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - "~>"
157
+ - - '='
158
158
  - !ruby/object:Gem::Version
159
- version: 0.7.0
159
+ version: 0.8.0
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - "~>"
164
+ - - '='
165
165
  - !ruby/object:Gem::Version
166
- version: 0.7.0
166
+ version: 0.8.0
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: pickup
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -198,14 +198,20 @@ dependencies:
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: '4.3'
201
+ version: '5.0'
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: 5.0.4
202
205
  type: :runtime
203
206
  prerelease: false
204
207
  version_requirements: !ruby/object:Gem::Requirement
205
208
  requirements:
206
209
  - - "~>"
207
210
  - !ruby/object:Gem::Version
208
- version: '4.3'
211
+ version: '5.0'
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: 5.0.4
209
215
  - !ruby/object:Gem::Dependency
210
216
  name: rack
211
217
  requirement: !ruby/object:Gem::Requirement
@@ -384,16 +390,16 @@ dependencies:
384
390
  name: rubocop
385
391
  requirement: !ruby/object:Gem::Requirement
386
392
  requirements:
387
- - - ">="
393
+ - - "~>"
388
394
  - !ruby/object:Gem::Version
389
- version: '0'
395
+ version: '1.0'
390
396
  type: :development
391
397
  prerelease: false
392
398
  version_requirements: !ruby/object:Gem::Requirement
393
399
  requirements:
394
- - - ">="
400
+ - - "~>"
395
401
  - !ruby/object:Gem::Version
396
- version: '0'
402
+ version: '1.0'
397
403
  - !ruby/object:Gem::Dependency
398
404
  name: simplecov
399
405
  requirement: !ruby/object:Gem::Requirement