Skip to content

Commit

Permalink
Fixes #19325
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernhard committed Apr 20, 2017
1 parent b9a9404 commit ccb4e08
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
28 changes: 23 additions & 5 deletions app/models/compute_resources/foreman/model/vmware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ def disk_mode_types
}
end

def controller_ids
{
"1000" => "SCSI (0:X)",
"1001" => "SCSI (1:X)",
"1002" => "SCSI (2:X)",
"1003" => "SCSI (3:X)",
"1004" => "SCSI (4:X)"
}
end

# vSphere guest OS type descriptions
# list fetched from RbVmomi::VIM::VirtualMachineGuestOsIdentifier.values and
# http://pubs.vmware.com/vsphere-60/topic/com.vmware.wssdk.apiref.doc/vim.vm.GuestOsDescriptor.GuestOsIdentifier.html
Expand Down Expand Up @@ -362,16 +372,25 @@ def test_connection(options = {})
def parse_args(args)
args = args.deep_symbolize_keys

# set the default type first and then receive the configured type
scsi_controller_type = scsi_controller_default_type
if args[:scsi_controller_type].present?
scsi_controller_type = args.delete(:scsi_controller_type)
end

scsi_controllers = Hash.new
args[:volumes_attributes].each do |k,v|
Rails.logger.info("Will add #{v[:controller_key]} vmware controller with type #{scsi_controller_type}")
scsi_controllers[v[:controller_key]] = {:type => scsi_controller_type, :key => v[:controller_key]}
end
args[:scsi_controllers] = scsi_controllers.values

# convert rails nested_attributes into a plain, symbolized hash
[:interfaces, :volumes].each do |collection|
nested_attrs = args.delete("#{collection}_attributes".to_sym)
args[collection] = nested_attributes_for(collection, nested_attrs) if nested_attrs
end

if args[:scsi_controller_type].present?
args[:scsi_controller] = {:type => args.delete(:scsi_controller_type)}
end

add_cdrom = args.delete(:add_cdrom)
args[:cdroms] = [new_cdrom] if add_cdrom == '1'

Expand Down Expand Up @@ -575,7 +594,6 @@ def vm_instance_defaults
:memory_mb => 768,
:interfaces => [new_interface],
:volumes => [new_volume],
:scsi_controller => { :type => scsi_controller_default_type },
:datacenter => datacenter,
:firmware => 'automatic',
:boot_order => ['network', 'disk']
Expand Down
3 changes: 3 additions & 0 deletions app/models/concerns/fog_extensions/vsphere/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def vm_description
end

def scsi_controller_type
# if the scsi_controller is a array, we are using the first
# to get the type
return scsi_controller[0][:type] if scsi_controller.is_a?(Array)
return scsi_controller[:type] if scsi_controller.is_a?(Hash)
scsi_controller.type
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
"true",
"false" %>
<%= select_f f, :mode, compute_resource.disk_mode_types, :first, :last, { }, :class => "span5", :label => _("Disk mode"), :label_size => "col-md-2", :disabled => !new_host %>
<%= select_f f, :controller_key, compute_resource.controller_ids, :first, :last, { }, :class => "span5", :label => _("SCSI Controller ID"), :label_size => "col-md-2" , :disabled => !new_host %>

0 comments on commit ccb4e08

Please sign in to comment.