Skip to content

Commit

Permalink
Merge pull request #602 from bdunne/to_miq_a
Browse files Browse the repository at this point in the history
Prefer Array.wrap over Object#to_miq_a
  • Loading branch information
agrare committed Jul 17, 2020
2 parents 709f21b + 0524b6c commit 959e48c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def self.perf_vim_data_to_hashes(vim_data)
meth = nil

# The data is organized in an array such as [timestamp1, value1, timestamp2, value2, ...]
vim_data.to_miq_a.each_slice(2) do |t, v|
Array.wrap(vim_data).each_slice(2) do |t, v|
if t.kind_of?(String) # VimString
t = t.to_s
else
Expand Down Expand Up @@ -205,15 +205,9 @@ def self.process_entity(data, parent = nil)

if data.key?('childEntity')
raise 'composite is not supported yet'
# child_ar = Array.new
# data['childEntity'].to_miq_a.each do |c|
# child_data = process_entity(c, mor)
# child_ar << child_data
# base[:children] << child_data[:mor]
# end
end

values = data['value'].to_miq_a
values = Array.wrap(data['value'])
samples = parse_csv_safe(data['sampleInfoCSV'].to_s)

ret = []
Expand Down Expand Up @@ -408,7 +402,7 @@ class << self

def parse_csv_safe(str)
if str.include?("\"")
CSV.parse(str).first.to_miq_a
Array.wrap(CSV.parse(str).first)
else
str.split(",")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_scsi_controller_info
end

def add_scsi_controller(vmcs, busNumber, new_dev_key)
controller_settings = options[:ctrl_scsi].to_miq_a.detect { |c| c[:busnumber] == busNumber.to_i } || {}
controller_settings = Array.wrap(options[:ctrl_scsi]).detect { |c| c[:busnumber] == busNumber.to_i } || {}
_log.info "Adding SCSI controller on bus <#{busNumber}> Settings: <#{controller_settings.inspect}>"
device_type = get_config_spec_value(controller_settings, 'VirtualLsiLogicController', nil, [:devicetype])
add_device_config_spec(vmcs, VirtualDeviceConfigSpecOperation::Add) do |vdcs|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def build_config_network_adapters(vmcs)
end

# Remove any unneeded template networks
# Use .to_miq_a to handle cases where more networks are requested then exist on the source VM
# Use Array.wrap to handle cases where more networks are requested than exist on the source VM
# in which case the array [length..-1] logic will return nil. (So please do not remove it...again.)
template_networks[requested_networks.length..-1].to_miq_a.each do |vim_net_adapter|
Array.wrap(template_networks[requested_networks.length..-1]).each do |vim_net_adapter|
build_config_spec_delete_existing_vlan(vmcs, vim_net_adapter)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def customization_identity_linux(spec)
end

def collect_nic_settings
nics = options[:nic_settings].to_miq_a
nics = Array.wrap(options[:nic_settings])
nic = nics[0]
nic = {} if nic.blank?
[:dns_domain, :dns_servers, :sysprep_netbios_mode, :wins_servers, :addr_mode,
Expand Down Expand Up @@ -168,7 +168,7 @@ def adjust_nicSettingMap(spec)
return if spec.blank?

requested_network_adapter_count = options[:requested_network_adapter_count].to_i
nic_count = spec.nicSettingMap.to_miq_a.length
nic_count = Array.wrap(spec.nicSettingMap).length

if requested_network_adapter_count < nic_count
# Remove nicSettings to match network adapter count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def self.host_inv_to_firewall_rules_hashes(inv)
result = []
return result if inv.nil?

inv.to_miq_a.each do |data|
Array.wrap(inv).each do |data|
# Collect Rule Set values
current_rule_set = {:group => data['key'], :enabled => data['enabled'], :required => data['required']}

Expand All @@ -68,8 +68,8 @@ def self.host_inv_to_advanced_settings_hashes(inv)
result = []
return result if inv.nil?

settings = inv['option'].to_miq_a.index_by { |o| o['key'] }
details = inv['optionDef'].to_miq_a.index_by { |o| o['key'] }
settings = Array.wrap(inv['option']).index_by { |o| o['key'] }
details = Array.wrap(inv['optionDef']).index_by { |o| o['key'] }

settings.each do |key, setting|
detail = details[key]
Expand Down

0 comments on commit 959e48c

Please sign in to comment.