Skip to content

Commit d76fdad

Browse files
author
Damien Bergamini
committed
refactor build_proc_config_spec to satisfy codeclimate
Signed-off-by: Damien Bergamini <[email protected]>
1 parent f67640e commit d76fdad

File tree

1 file changed

+11
-14
lines changed
  • app/models/manageiq/providers/ibm_power_hmc/infra_manager/vm

1 file changed

+11
-14
lines changed

app/models/manageiq/providers/ibm_power_hmc/infra_manager/vm/reconfigure.rb

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def max_total_vcpus
77
# 64 is based on the CEC's CurrentMaximumVirtualProcessorsPerAIXOrLinuxPartition and
88
# CurrentMaximumVirtualProcessorsPerVirtualIOServerPartition settings.
99
# This can be further reduced by the partition's MaximumVirtualProcessors setting.
10-
host && processor_share_type == "dedicated" ? host.cpu_total_cores : 64
10+
host && try(:processor_share_type) == "dedicated" ? host.cpu_total_cores : 64
1111
end
1212

1313
def max_vcpus
@@ -36,8 +36,7 @@ def build_config_spec(options)
3636

3737
spec = {}
3838
build_memory_config_spec(lpar, spec, options) if options.key?(:vm_memory)
39-
build_proc_config_spec(lpar, spec, options) if options.key?(:number_of_cpus) && lpar.dedicated == "true"
40-
build_vproc_config_spec(lpar, spec, options) if options.key?(:number_of_cpus) && lpar.dedicated != "true"
39+
build_proc_config_spec(lpar, spec, options) if options.key?(:number_of_cpus)
4140
build_netadap_create_config_spec(spec, options) if options.key?(:network_adapter_add)
4241
build_netadap_delete_config_spec(spec, options) if options.key?(:network_adapter_remove)
4342

@@ -56,19 +55,17 @@ def build_memory_config_spec(lpar, spec, options)
5655
def build_proc_config_spec(lpar, spec, options)
5756
desired_procs = options[:number_of_cpus].to_i
5857

59-
raise MiqException::MiqVmError, "Processor count cannot be lower than #{lpar.minimum_procs}" if desired_procs < lpar.minimum_procs.to_i
60-
raise MiqException::MiqVmError, "Processor count cannot be greater than #{lpar.maximum_procs}" if desired_procs > lpar.maximum_procs.to_i
58+
if lpar.dedicated == "true"
59+
raise MiqException::MiqVmError, "Processor count cannot be lower than #{lpar.minimum_procs}" if desired_procs < lpar.minimum_procs.to_i
60+
raise MiqException::MiqVmError, "Processor count cannot be greater than #{lpar.maximum_procs}" if desired_procs > lpar.maximum_procs.to_i
6161

62-
spec[:desired_procs] = desired_procs
63-
end
64-
65-
def build_vproc_config_spec(lpar, spec, options)
66-
desired_vprocs = options[:number_of_cpus].to_i
62+
spec[:desired_procs] = desired_procs
63+
else
64+
raise MiqException::MiqVmError, "Virtual processor count cannot be lower than #{lpar.minimum_vprocs}" if desired_procs < lpar.minimum_vprocs.to_i
65+
raise MiqException::MiqVmError, "Virtual processor count cannot be greater than #{lpar.maximum_vprocs}" if desired_procs > lpar.maximum_vprocs.to_i
6766

68-
raise MiqException::MiqVmError, "Virtual processor count cannot be lower than #{lpar.minimum_vprocs}" if desired_vprocs < lpar.minimum_vprocs.to_i
69-
raise MiqException::MiqVmError, "Virtual processor count cannot be greater than #{lpar.maximum_vprocs}" if desired_vprocs > lpar.maximum_vprocs.to_i
70-
71-
spec[:desired_vprocs] = desired_vprocs
67+
spec[:desired_vprocs] = desired_procs
68+
end
7269
end
7370

7471
def build_netadap_create_config_spec(spec, options)

0 commit comments

Comments
 (0)