Skip to content

Commit

Permalink
Merge pull request #148 from agrare/bz_1445874_return_vm_hardware
Browse files Browse the repository at this point in the history
Add method to return VM Hardware
  • Loading branch information
blomquisg authored May 4, 2017
2 parents f437ff8 + 7e13304 commit 6e38517
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions lib/gems/pending/VMwareWebService/MiqVimVm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,15 @@ def reconfig(vmConfigSpec)
waitForTask(taskMor)
end

def getHardware
getProp("config.hardware").try(:fetch_path, "config", "hardware") || {}
end

def getScsiControllers(hardware = nil)
hardware ||= getHardware()
hardware["device"].to_a.select { |dev| VIRTUAL_SCSI_CONTROLLERS.include?(dev.xsiType) }
end

def getMemory
getProp("summary.config.memorySizeMB")["summary"]["config"]["memorySizeMB"].to_i
end
Expand Down Expand Up @@ -853,12 +862,14 @@ def removeDiskByFile(backingFile, deleteBacking = false)
# Find a SCSI controller and
# return its key and next available unit number.
#
def available_scsi_units
def available_scsi_units(hardware = nil)
scsi_units = []
all_unit_numbers = [*0..MAX_SCSI_DEVICES]

devices = getProp("config.hardware")["config"]["hardware"]["device"]
scsi_controllers = devices.select { |dev| VIRTUAL_SCSI_CONTROLLERS.include?(dev.xsiType) }
hardware ||= getHardware()

devices = hardware["device"]
scsi_controllers = getScsiControllers(hardware)

scsi_controllers.sort_by { |s| s["key"].to_i }.each do |scsi_controller|
# Skip if all controller units are populated
Expand Down Expand Up @@ -886,12 +897,10 @@ def available_scsi_units
scsi_units
end # def available_scsi_units

def available_scsi_buses
def available_scsi_buses(hardware = nil)
scsi_controller_bus_numbers = [*0..MAX_SCSI_CONTROLLERS - 1]

devices = getProp("config.hardware")["config"]["hardware"]["device"]

scsi_controllers = devices.select { |dev| VIRTUAL_SCSI_CONTROLLERS.include?(dev.xsiType) }
scsi_controllers = getScsiControllers(hardware)
scsi_controllers.each do |controller|
scsi_controller_bus_numbers -= [controller["busNumber"].to_i]
end
Expand All @@ -903,10 +912,10 @@ def available_scsi_buses
# Returns the [controllerKey, key] pair for the virtul device
# associated with the given backing file.
#
def getDeviceKeysByBacking(backingFile)
devs = getProp("config.hardware")["config"]["hardware"]["device"]
def getDeviceKeysByBacking(backingFile, hardware = nil)
hardware ||= getHardware()

devs.each do |dev|
hardware["device"].to_a.each do |dev|
next if dev.xsiType != "VirtualDisk"
next if dev["backing"]["fileName"] != backingFile
return([dev["controllerKey"], dev["key"]])
Expand Down

0 comments on commit 6e38517

Please sign in to comment.