foreman_hyperv 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65f805250cc59658795113cc0d201de9c2da857b8dc0868bc5a7450be52619ef
4
- data.tar.gz: dfbe2e15421b902d38f2747a07ff83dc68661178914a7b2de992d1d4d905003d
3
+ metadata.gz: 3cf1610103bdfad147e262399c3c50667bf4450831ebb8e9a4f20211307a3d18
4
+ data.tar.gz: a4623968a974d9de60af94cd0dfaa9957a89354f640897e8138c6c0b32f95b9a
5
5
  SHA512:
6
- metadata.gz: 3487dfa1b123b714d5fc093ff23d85fbc49253a0f7cd24308461b2117436e181c38380e9b2acdf3bc1bae3669eabb5dd87475e7946376c6da79aa1eaae5b982b
7
- data.tar.gz: 32dc60ede4f1bd60f7c74e56a7c9e648f58757a4bac64cef8e3d09858380984bdf059093e016fb72de3c2bede1f6c94f39cfb7db4a1c5071e4d846777939f0ea
6
+ metadata.gz: a1007568c30b112299208b00a5df11c8d88c0b0e390365ede46efc67900489b7cdb40b6ca83a318505e6ff6f3fc167c6bb2239c18e910710a45572e161213852
7
+ data.tar.gz: 51d064f97547b16ec490a6c9d9436c87efbed149957a6f66b6fef85d652ff0c91201e44c13a039ed53871db51b26487181ee11410bb45f45663ce6b6068ec1d3
@@ -1,17 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanHyperv
2
4
  module ComputeResourcesVmsHelper
3
5
  def hyperv_networks(compute_resource)
4
6
  compute_resource.switches(nil).map do |sw|
5
- [ sw.id, "#{sw.name}#{sw.switch_type ? " (#{sw.switch_type})" : nil}" ]
7
+ [sw.id, "#{sw.name}#{" (#{sw.switch_type})" if sw.switch_type}"]
6
8
  end
7
9
  end
8
10
 
9
11
  def hyperv_generations
10
12
  Fog::Hyperv::Compute::Server::VM_GENERATION_VALUES.map { |gen, num| [gen, "Generation #{num} (#{gen})"] }
11
13
  end
14
+
12
15
  def hyperv_vlan_modes
13
16
  Fog::Hyperv::Compute::NetworkAdapterVlan::VLAN_OPERATION_MODE.map { |mode| [mode, mode] }
14
17
  end
18
+
15
19
  def hyperv_private_vlan_modes
16
20
  Fog::Hyperv::Compute::NetworkAdapterVlan::PRIVATE_VLAN_MODE.reject { |mode| mode == :Unknown }.map { |mode| [mode, mode] }
17
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FogExtensions
2
4
  module Hyperv
3
5
  module Compute
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FogExtensions
2
4
  module Hyperv
3
5
  module HardDrive
@@ -27,8 +29,8 @@ module FogExtensions
27
29
  .slice(:id)
28
30
  .merge(
29
31
  {
30
- basename:,
31
- size_bytes:
32
+ basename: basename,
33
+ size_bytes: size_bytes
32
34
  }.compact
33
35
  )
34
36
  end
@@ -7,16 +7,17 @@ module FogExtensions
7
7
 
8
8
  def mac
9
9
  return unless mac_address
10
- return if mac_address.to_i(16) == 0
10
+ return if mac_address.to_i(16).zero?
11
11
 
12
12
  # Downcase and split every 2 chars, join with :
13
- mac_address.downcase.scan(%r{.{2}}).join(':')
13
+ mac_address.downcase.scan(/.{2}/).join(':')
14
14
  end
15
15
 
16
16
  def mac=(m)
17
17
  mac_address = m&.upcase&.delete(':')
18
18
  mac_address = Fog::Hyperv::Compute::NetworkAdapter::NIC_FALLBACK_MAC if mac_address.nil? || mac_address.blank?
19
- dynamic_mac_address_enabled = (mac_address.to_i(16) == 0)
19
+ mac_address.to_i(16)
20
+ 0
20
21
  end
21
22
 
22
23
  # VLAN settings
@@ -24,6 +25,7 @@ module FogExtensions
24
25
  def vlan_operation_mode
25
26
  vlan_setting.operation_mode
26
27
  end
28
+
27
29
  def vlan_operation_mode=(mode)
28
30
  vlan_setting.operation_mode = mode
29
31
  end
@@ -33,6 +35,7 @@ module FogExtensions
33
35
 
34
36
  vlan_setting.private_vlan_mode
35
37
  end
38
+
36
39
  def vlan_private_mode=(mode)
37
40
  vlan_setting.private_vlan_mode = mode
38
41
  end
@@ -42,24 +45,23 @@ module FogExtensions
42
45
 
43
46
  vlan_setting.access_vlan_id
44
47
  end
45
- def access_vlan_id=(id)
46
- vlan_setting.access_vlan_id = id
47
- end
48
+
49
+ delegate :access_vlan_id=, to: :vlan_setting
48
50
 
49
51
  def native_vlan_id
50
52
  return nil if vlan_setting.native_vlan_id.zero?
51
53
 
52
54
  vlan_setting.native_vlan_id
53
55
  end
54
- def native_vlan_id=(id)
55
- vlan_setting.native_vlan_id = id
56
- end
56
+
57
+ delegate :native_vlan_id=, to: :vlan_setting
57
58
 
58
59
  def allowed_vlan_ids
59
60
  return nil unless vlan_setting.allowed_vlan_id_list&.any?
60
61
 
61
62
  Fog::Hyperv::Compute::NetworkAdapterVlan.render_vlan_list vlan_setting.allowed_vlan_id_list
62
63
  end
64
+
63
65
  def allowed_vlan_ids=(ids)
64
66
  ids ||= ''
65
67
  vlan_setting.allowed_vlan_id_list = parse_vlan_list(ids)
@@ -70,24 +72,23 @@ module FogExtensions
70
72
 
71
73
  vlan_setting.primary_vlan_id
72
74
  end
73
- def primary_vlan_id=(id)
74
- vlan_setting.primary_vlan_id = id
75
- end
75
+
76
+ delegate :primary_vlan_id=, to: :vlan_setting
76
77
 
77
78
  def secondary_vlan_id
78
79
  return nil if vlan_setting.secondary_vlan_id.zero?
79
80
 
80
81
  vlan_setting.secondary_vlan_id
81
82
  end
82
- def secondary_vlan_id=(id)
83
- vlan_setting.secondary_vlan_id = id
84
- end
83
+
84
+ delegate :secondary_vlan_id=, to: :vlan_setting
85
85
 
86
86
  def secondary_vlan_ids
87
87
  return nil unless vlan_setting.secondary_vlan_id_list&.any?
88
88
 
89
89
  Fog::Hyperv::Compute::NetworkAdapterVlan.render_vlan_list vlan_setting.secondary_vlan_id_list
90
90
  end
91
+
91
92
  def secondary_vlan_ids=(ids)
92
93
  ids ||= ''
93
94
  vlan_setting.secondary_vlan_id_list = parse_vlan_list(ids)
@@ -100,17 +101,20 @@ module FogExtensions
100
101
  :switch_id
101
102
  )
102
103
  .merge(
103
- {
104
- vlan_operation_mode:,
105
- vlan_private_mode:,
106
- access_vlan_id:,
107
- native_vlan_id:,
108
- allowed_vlan_ids:,
109
- primary_vlan_id:,
110
- secondary_vlan_id:,
111
- secondary_vlan_ids:
112
- }.compact
104
+ vlan_setting.attributes.slice(
105
+ :vlan_operation_mode,
106
+ :vlan_private_mode,
107
+ :access_vlan_id,
108
+ :native_vlan_id,
109
+ :primary_vlan_id,
110
+ :secondary_vlan_id
111
+ )
112
+ )
113
+ .merge(
114
+ secondary_vlan_ids: secondary_vlan_ids,
115
+ allowed_vlan_ids: allowed_vlan_ids
113
116
  )
117
+ .compact
114
118
  end
115
119
 
116
120
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FogExtensions
2
4
  module Hyperv
3
5
  module Server
@@ -9,7 +11,7 @@ module FogExtensions
9
11
  end
10
12
 
11
13
  def folder_name
12
- name.gsub(/[^0-9A-Za-z.\-]/, '_')
14
+ name.gsub(/[^0-9A-Za-z.-]/, '_')
13
15
  end
14
16
 
15
17
  def mac
@@ -40,7 +42,6 @@ module FogExtensions
40
42
  def cluster_name=(name)
41
43
  @cluster = service.clusters.get(name)
42
44
  end
43
- #
44
45
 
45
46
  def vlan
46
47
  nic = network_adapters.first
@@ -51,7 +52,7 @@ module FogExtensions
51
52
  def vlan=(vlan)
52
53
  logger.warn "using vlan=#{vlan.inspect} on Hyper-V VM, this can lead to unexpected results"
53
54
  nic = network_adapters.first
54
- if vlan.present? && vlan.to_i > 0
55
+ if vlan.present? && vlan.to_i.positive?
55
56
  nic.vlan_operation_mode = :Access if nic.vlan_operation_mode == :Untagged
56
57
  case nic.vlan_operation_mode
57
58
  when :Access
@@ -103,29 +104,35 @@ module FogExtensions
103
104
  match ||= fog_nics.detect { |fn| fn.mac == nic.mac }
104
105
  # match ||= fog_nics.detect { |fn| fn.name == nic_attrs['name'].presence }
105
106
 
106
- if !match
107
+ unless match
107
108
  # Match on networking, limit potentials down to identical configuration and then pick the first
108
109
  potential = fog_nics.select do |fn|
109
110
  fn.switch_id == nic_attrs['switch_id'].presence || fn.switch_name == nic_attrs['switch_name'].presence
110
111
  end
111
112
  potential.select! { |fn| fn.vlan_operation_mode.to_s == nic_attrs['vlan_operation_mode'] }
112
- if nic_attrs['vlan_operation_mode'] == 'Access'
113
+ case nic_attrs['vlan_operation_mode']
114
+ when 'Access'
113
115
  potential.select! { |fn| fn.access_vlan_id.to_s == nic_attrs['access_vlan_id'] }
114
- elsif nic_attrs['vlan_operation_mode'] == 'Trunk'
116
+ when 'Trunk'
115
117
  potential.select! { |fn| fn.native_vlan_id.to_s == nic_attrs['native_vlan_id'] }
116
- potential.select! { |fn| fn.allowed_vlan_ids.split(',').map(&:strip) == nic_attrs['allowed_vlan_ids'].split(',').map(&:strip) } \
117
- if nic_attrs['allowed_vlan_ids'].present?
118
- elsif nic_attrs['vlan_operation_mode'] == 'Private'
118
+ if nic_attrs['allowed_vlan_ids'].present?
119
+ potential.select! do |fn|
120
+ fn.allowed_vlan_ids.split(',').map(&:strip) == nic_attrs['allowed_vlan_ids'].split(',').map(&:strip)
121
+ end
122
+ end
123
+ when 'Private'
119
124
  potential.select! { |fn| fn.vlan_private_mode.to_s == nic_attrs['vlan_private_mode'] }
120
125
  potential.select! { |fn| fn.primary_vlan_id.to_s == nic_attrs['primary_vlan_id'].to_s } \
121
126
  if nic_attrs['primary_vlan_id'].present?
122
127
 
123
128
  if nic_attrs['vlan_private_mode'] == 'Promiscuous'
124
- potential.select! { |fn| fn.secondary_vlan_ids.split(',').map(&:strip) == nic_attrs['secondary_vlan_ids'].split(',').map(&:strip) } \
125
- if nic_attrs['secondary_vlan_ids'].present?
126
- else
127
- potential.select! { |fn| fn.secondary_vlan_id.to_s == nic_attrs['secondary_vlan_id'].to_s } \
128
- if nic_attrs['secondary_vlan_id'].present?
129
+ if nic_attrs['secondary_vlan_ids'].present?
130
+ potential.select! do |fn|
131
+ fn.secondary_vlan_ids.split(',').map(&:strip) == nic_attrs['secondary_vlan_ids'].split(',').map(&:strip)
132
+ end
133
+ end
134
+ elsif nic_attrs['secondary_vlan_id'].present?
135
+ potential.select! { |fn| fn.secondary_vlan_id.to_s == nic_attrs['secondary_vlan_id'].to_s }
129
136
  end
130
137
  end
131
138
 
@@ -16,9 +16,9 @@ module ForemanHyperv
16
16
 
17
17
  begin
18
18
  hyperv_sync_interfaces
19
- rescue => e
19
+ rescue StandardError => e
20
20
  failure _("Failed to update a compute %{compute_resource} instance %{name}: %{e}") %
21
- { compute_resource:, name:, e: }, e
21
+ { compute_resource: compute_resource, name: name, e: e }, e
22
22
  end
23
23
  true
24
24
  end
@@ -41,8 +41,7 @@ module ForemanHyperv
41
41
  selected_nic = vm.select_nic(fog_nics, nic)
42
42
  if selected_nic.nil?
43
43
  logger.warn "Orchestration::Compute: Could not match network interface #{nic.inspect}"
44
- raise ArgumentError, \
45
- _("Could not find virtual machine network interface matching %s") %
44
+ raise ArgumentError, _("Could not find virtual machine network interface matching %s") %
46
45
  [nic.identifier, nic.ip, nic.name, nic.type].find(&:present?)
47
46
  end
48
47
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanHyperv
2
4
  class Hyperv < ::ComputeResource
3
5
  include ComputeResourceCaching
@@ -37,7 +39,7 @@ module ForemanHyperv
37
39
  validate_connectivity(options)
38
40
  end
39
41
 
40
- def validate_connectivity(options = {})
42
+ def validate_connectivity(_options = {})
41
43
  return unless connection_properties_valid?
42
44
  return false if errors.any?
43
45
 
@@ -66,10 +68,6 @@ module ForemanHyperv
66
68
  super.merge(mac: :mac)
67
69
  end
68
70
 
69
- def editable_network_interfaces?
70
- true
71
- end
72
-
73
71
  # TODO
74
72
  def max_cpu_count(host = nil)
75
73
  (host || hypervisor).logical_processor_count
@@ -127,7 +125,7 @@ module ForemanHyperv
127
125
  iface_nested_attrs = nested_attributes_for :interfaces, attr[:interfaces_attributes]
128
126
  vm.network_adapters = iface_nested_attrs.map do |attr|
129
127
  attr.delete :id
130
- Fog::Hyperv::Compute::NetworkAdapter.new(service: vm.service, vm:).tap do |nic|
128
+ Fog::Hyperv::Compute::NetworkAdapter.new(service: vm.service, vm: vm).tap do |nic|
131
129
  attr.select { |_, v| v.present? }.each do |k, v|
132
130
  nic.send(:"#{k}=", v)
133
131
  end
@@ -136,7 +134,7 @@ module ForemanHyperv
136
134
  volume_nested_attrs = nested_attributes_for :volumes, attr[:volumes_attributes]
137
135
  vm.hard_drives = volume_nested_attrs.map do |attr|
138
136
  attr.delete :id
139
- Fog::Hyperv::Compute::HardDrive.new(service: vm.service, vm:).tap do |hdd|
137
+ Fog::Hyperv::Compute::HardDrive.new(service: vm.service, vm: vm).tap do |hdd|
140
138
  attr.select { |_, v| v.present? }.each do |k, v|
141
139
  hdd.send(:"#{k}=", v)
142
140
  end
@@ -234,28 +232,28 @@ module ForemanHyperv
234
232
  end
235
233
 
236
234
  def update_required?(old_attrs, new_attrs)
237
- new_attrs.deep_symbolize_keys[:volumes_attributes]&.each do |_, hdd|
235
+ new_attrs.deep_symbolize_keys[:volumes_attributes]&.each_value do |hdd|
238
236
  if hdd[:id].present? && hdd[:_delete] == '1'
239
- Rails.logger.debug "Scheduling compute instance update because a volume was removed"
237
+ Rails.logger.debug 'Scheduling compute instance update because a volume was removed'
240
238
  return true
241
- elsif !hdd[:id].present? && hdd[:_delete] != '1'
242
- Rails.logger.debug "Scheduling compute instance update because a new volume was added"
239
+ elsif hdd[:id].blank? && hdd[:_delete] != '1'
240
+ Rails.logger.debug 'Scheduling compute instance update because a new volume was added'
243
241
  return true
244
242
  end
245
243
  end
246
- new_attrs.deep_symbolize_keys[:interfaces_attributes]&.each do |_, iface|
244
+ new_attrs.deep_symbolize_keys[:interfaces_attributes]&.each_value do |iface|
247
245
  if iface[:id].present? && iface[:_destroy] == '1'
248
- Rails.logger.debug "Scheduling compute instance update because an interface was removed"
246
+ Rails.logger.debug 'Scheduling compute instance update because an interface was removed'
249
247
  return true
250
- elsif !iface[:id].present? && iface[:_destroy] != '1'
251
- Rails.logger.debug "Scheduling compute instance update because a new interface was added"
248
+ elsif iface[:id].blank? && iface[:_destroy] != '1'
249
+ Rails.logger.debug 'Scheduling compute instance update because a new interface was added'
252
250
  return true
253
251
  end
254
252
  end
255
253
 
256
254
  deep_update_required = proc do |old, new|
257
255
  old.merge(new) do |k, old_v, new_v|
258
- if k == :allowed_vlan_ids || k == :secondary_vlan_ids
256
+ if %i[allowed_vlan_ids secondary_vlan_ids].include?(k)
259
257
  tmp = Fog::Hyperv::Compute::NetworkAdapter.new
260
258
 
261
259
  old_v = Fog::Hyperv::Compute::NetworkAdapterVlan.render_vlan_list(tmp.send(:parse_vlan_list, old_v.to_s))
@@ -265,7 +263,9 @@ module ForemanHyperv
265
263
  if old_v.is_a?(Hash) && new_v.is_a?(Hash)
266
264
  deep_update_required.call(old_v, new_v)
267
265
  elsif old_v.to_s != new_v.to_s
268
- Rails.logger.debug "Scheduling compute instance update because #{k} changed it's value from '#{old_v}' (#{old_v.class}) to '#{new_v}' (#{new_v.class})"
266
+ Rails.logger.debug do
267
+ "Scheduling compute instance update because #{k} changed it's value from '#{old_v}' (#{old_v.class}) to '#{new_v}' (#{new_v.class})"
268
+ end
269
269
  return true
270
270
  end
271
271
  new_v
@@ -293,8 +293,8 @@ module ForemanHyperv
293
293
  basename = attr.delete(:basename) { 'Disk' }
294
294
  size = attr.delete(:size)
295
295
 
296
- vhd = client.vhds.new({ basename:, size: }.compact)
297
- Fog::Hyperv::Compute::HardDrive.new vhd:, **attr
296
+ vhd = client.vhds.new({ basename: basename, size: size }.compact)
297
+ Fog::Hyperv::Compute::HardDrive.new vhd: vhd, **attr
298
298
  end
299
299
 
300
300
  def new_cdrom(attr = {})
@@ -303,10 +303,10 @@ module ForemanHyperv
303
303
 
304
304
  def vm_instance_defaults
305
305
  super.merge(
306
- generation: 2,
307
- memory_startup: 1024.megabytes,
306
+ generation: 2,
307
+ memory_startup: 1024.megabytes,
308
308
  processor_count: 1,
309
- interfaces: [new_interface]
309
+ interfaces: [new_interface]
310
310
  )
311
311
  end
312
312
 
@@ -344,25 +344,22 @@ module ForemanHyperv
344
344
  private
345
345
 
346
346
  def _clusters
347
- if client.respond_to? :supports_clusters?
348
- return [] unless client.supports_clusters?
349
- end
347
+ return [] if client.respond_to?(:supports_clusters?) && !client.supports_clusters?
350
348
 
351
349
  client.clusters.all
352
- rescue
350
+ rescue StandardError
353
351
  []
354
352
  end
355
353
 
356
354
  def validate_vm(attr, new: false)
357
355
  # logger.debug "Validate VM #{attr.inspect}"
358
- raise Foreman::Exception, 'VM lacks generation' if new && !attr[:generation].present?
359
- raise Foreman::Exception, 'VM lacks memory' unless attr[:memory_startup].to_i > 0
360
- raise Foreman::Exception, 'VM lacks CPUs' unless attr[:processor_count].to_i > 0
356
+ raise Foreman::Exception, 'VM lacks generation' if new && attr[:generation].blank?
357
+ raise Foreman::Exception, 'VM lacks memory' unless attr[:memory_startup].to_i.positive?
358
+ raise Foreman::Exception, 'VM lacks CPUs' unless attr[:processor_count].to_i.positive?
361
359
 
362
- if Foreman::Cast.to_bool(attr[:dynamic_memory_enabled])
363
- raise Foreman::Exception, 'VM lacks memory minimum' unless attr[:memory_minimum].to_i > 0
364
- raise Foreman::Exception, 'VM lacks memory maximum' unless attr[:memory_maximum].to_i > 0
365
- end
360
+ return unless Foreman::Cast.to_bool(attr[:dynamic_memory_enabled])
361
+ raise Foreman::Exception, 'VM lacks memory minimum' unless attr[:memory_minimum].to_i.positive?
362
+ raise Foreman::Exception, 'VM lacks memory maximum' unless attr[:memory_maximum].to_i.positive?
366
363
  end
367
364
 
368
365
  def validate_interfaces(attr)
@@ -373,18 +370,26 @@ module ForemanHyperv
373
370
  compute = iface[:compute_attributes] || iface
374
371
  case compute[:vlan_operation_mode].to_s
375
372
  when 'Untagged'
373
+ # No VLAN settings to verify
376
374
  when 'Access'
377
- raise Foreman::Exception, 'Interface is missing access VLAN' unless compute[:access_vlan_id].to_i > 0
375
+ raise Foreman::Exception, 'Interface is missing access VLAN' unless compute[:access_vlan_id].to_i.positive?
378
376
  when 'Trunk'
379
- raise Foreman::Exception, 'Interface is missing native VLAN' unless compute[:native_vlan_id].to_i > 0
380
- raise Foreman::Exception, 'Interface is missing allowed VLANs' unless compute[:allowed_vlan_ids].present?
377
+ raise Foreman::Exception, 'Interface is missing native VLAN' unless compute[:native_vlan_id].to_i.positive?
378
+ raise Foreman::Exception, 'Interface is missing allowed VLANs' if compute[:allowed_vlan_ids].blank?
381
379
  when 'Private'
382
- raise Foreman::Exception, 'Interface is missing primary VLAN' unless compute[:primary_vlan_id].to_i > 0
380
+ raise Foreman::Exception, 'Interface is missing primary VLAN' unless compute[:primary_vlan_id].to_i.positive?
381
+
383
382
  case compute[:vlan_private_mode].to_s
384
383
  when 'Promiscuous'
385
- raise Foreman::Exception, 'Interface is missing secondary VLANs' unless compute[:secondary_vlan_ids].present?
384
+ if compute[:secondary_vlan_ids].blank?
385
+ raise Foreman::Exception,
386
+ 'Interface is missing secondary VLANs'
387
+ end
386
388
  else
387
- raise Foreman::Exception, 'Interface is missing secondary VLAN' unless compute[:secondary_vlan_id].to_i > 0
389
+ unless compute[:secondary_vlan_id].to_i.positive?
390
+ raise Foreman::Exception,
391
+ 'Interface is missing secondary VLAN'
392
+ end
388
393
  end
389
394
  else
390
395
  raise Foreman::Exception, 'Interface has unknown VLAN mode'
@@ -411,7 +416,9 @@ module ForemanHyperv
411
416
  nic.save
412
417
  end
413
418
 
414
- return unless vm.network_adapters.all(_return_fields: %i[dynamic_mac_address_enabled]).any?(&:dynamic_mac_address_enabled)
419
+ unless vm.network_adapters.all(_return_fields: %i[dynamic_mac_address_enabled]).any?(&:dynamic_mac_address_enabled)
420
+ return
421
+ end
415
422
 
416
423
  # Populate all non-populated MAC addresses
417
424
  vm.start
@@ -456,11 +463,13 @@ module ForemanHyperv
456
463
  volumes.reject! { |vol| vol[:_delete] == '1' }
457
464
  # logger.debug "Validate Volume #{volumes.inspect}"
458
465
  volumes.each do |vol|
459
- raise Foreman::Exception, 'Volume lacks name' unless vol[:basename].present?
466
+ raise Foreman::Exception, 'Volume lacks name' if vol[:basename].blank?
460
467
  raise Foreman::Exception, 'Volume name should not include a file extension' if vol[:basename] =~ /\.vhd[sx]?$/
461
- raise Foreman::Exception, 'Volume lacks size' unless vol[:size_bytes].to_i > 0
468
+ raise Foreman::Exception, 'Volume lacks size' unless vol[:size_bytes].to_i.positive?
462
469
  end
463
- raise Foreman::Exception, 'Volume names need to be unique' if volumes.group_by { |vol| vol[:basename].downcase }.any? { |k, v| v.count > 1 }
470
+ return unless volumes.group_by { |vol| vol[:basename].downcase }.any? { |_k, v| v.many? }
471
+
472
+ raise Foreman::Exception, 'Volume names need to be unique'
464
473
  end
465
474
 
466
475
  def create_volumes(vm, attr)
@@ -468,7 +477,7 @@ module ForemanHyperv
468
477
  logger.debug "Creating volumes with: #{volumes}"
469
478
  volumes.each do |vol|
470
479
  vhd = vm.vhds.create basename: vol[:basename], size: vol[:size_bytes].to_i
471
- vm.hard_drives.create vhd:
480
+ vm.hard_drives.create vhd: vhd
472
481
  end
473
482
  end
474
483
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanHyperv
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_hyperv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Olofsson
@@ -51,6 +51,34 @@ dependencies:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rubocop
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rubocop-rails
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
54
82
  - !ruby/object:Gem::Dependency
55
83
  name: minitest
56
84
  requirement: !ruby/object:Gem::Requirement
@@ -105,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
133
  requirements:
106
134
  - - ">="
107
135
  - !ruby/object:Gem::Version
108
- version: '0'
136
+ version: '3.0'
109
137
  required_rubygems_version: !ruby/object:Gem::Requirement
110
138
  requirements:
111
139
  - - ">="