Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to return VM Hardware #148

Merged
merged 2 commits into from
May 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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