Skip to content

Commit

Permalink
Update disk's controller type parsing
Browse files Browse the repository at this point in the history
Disk controller type parsing was completely wrong, since it relied on

a) parent disk
b) description

But there is no such thing as "parent disk", `disk.parent` actually points
to "parent controller". Inventoring crashed hard when such "parent disk" was
not found!

With this commit we update refresh parser to now properly inventory controller
type based on disk's bus subtype. Also, we prevent distinguising real disks from
simple ones (like CD) based on "disk.description", which is rather unreliable,
and now distinguish based on disk's bus type.

Signed-off-by: Miha Pleško <[email protected]>
  • Loading branch information
miha-plesko committed Mar 8, 2018
1 parent e1fcf19 commit af42e32
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,11 @@ def parse_vm(vm)
stack = @data_index.fetch_path(:orchestration_stacks, vapp_uid)
disk_capacity = vm.hard_disks.inject(0) { |sum, x| sum + x.values[0] } * 1.megabyte

vm_disks = vm.disks.all

disks = vm_disks.select { |d| d.description == "Hard disk" }.map do |disk|
parent = vm_disks.find { |d| d.id == disk.parent }

disks = vm.disks.all.select { |d| hdd? d.bus_type }.map do |disk|
{
:device_name => disk.name,
:device_type => "disk",
:controller_type => parent.description,
:controller_type => controller_description(disk.bus_sub_type),
:size => disk.capacity * 1.megabyte,
:location => "#{vm.id}-#{disk.id}",
:filename => "#{vm.id}-#{disk.id}",
Expand Down Expand Up @@ -237,4 +233,27 @@ def parse_snapshot(vm)
return nil
end
end

# See https://pubs.vmware.com/vcd-80/index.jsp#com.vmware.vcloud.api.sp.doc_90/GUID-E1BA999D-87FA-4E2C-B638-24A211AB8160.html
def controller_description(bus_subtype)
case bus_subtype
when 'buslogic'
'BusLogic Parallel SCSI controller'
when 'lsilogic'
'LSI Logic Parallel SCSI controller'
when 'lsilogicsas'
'LSI Logic SAS SCSI controller'
when 'VirtualSCSI'
'Paravirtual SCSI controller'
when 'vmware.sata.ahci'
'SATA controller'
else
'IDE controller'
end
end

# See https://pubs.vmware.com/vcd-80/index.jsp#com.vmware.vcloud.api.sp.doc_90/GUID-E1BA999D-87FA-4E2C-B638-24A211AB8160.html
def hdd?(bus_type)
[5, 6, 20].include?(bus_type)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def assert_specific_vm_powered_on
expect(v.hardware.disks.first).to have_attributes(
:device_name => "Hard disk 1",
:device_type => "disk",
:controller_type => "SCSI Controller",
:controller_type => "LSI Logic Parallel SCSI controller",
:size => 17_179_869_184,
)
expect(v.hardware.guest_devices.size).to eq(0)
Expand Down Expand Up @@ -320,7 +320,7 @@ def assert_specific_vm_powered_off
expect(v.hardware.disks.first).to have_attributes(
:device_name => "Hard disk 1",
:device_type => "disk",
:controller_type => "SCSI Controller",
:controller_type => "LSI Logic Parallel SCSI controller",
:size => 17_179_869_184,
)
expect(v.hardware.guest_devices.size).to eq(0)
Expand Down

0 comments on commit af42e32

Please sign in to comment.