Skip to content
This repository was archived by the owner on Jun 25, 2026. It is now read-only.

Update resize_disk.rb#153

Open
dodge245 wants to merge 1 commit into
RedHatOfficial:masterfrom
dodge245:patch-1
Open

Update resize_disk.rb#153
dodge245 wants to merge 1 commit into
RedHatOfficial:masterfrom
dodge245:patch-1

Conversation

@dodge245

@dodge245 dodge245 commented Jun 13, 2019

Copy link
Copy Markdown

Its possible using disk number to resize the incorrect disk if multiple remove and add operations are completed on a virtual machine. Using "UnitNumber" instead stops this mix up from occurring.

To pass the unit number from the dialog you can use the below code, which also provides the customer with a nice drop down choice.

#Get the  number of disks to loop through
i = 0
num = vm.num_disks

while i < num do
  disk_num = i
  
  if vm.hardware.disks[disk_num].device_type == "floppy"
    #i += 1
  else
    disk_location = vm.hardware.disks[disk_num].location
    disk_name = vm.hardware.disks[disk_num].filename.partition("]").last
    disk_name = disk_name.partition("/").last
    disk_size = vm.hardware.disks[disk_num].size/1024/1024/1024
    disk_type = vm.hardware.disks[disk_num].disk_type
    
    #This strips out the "0:" for the scsi device, leaving just the unit number to pass.
    unit_number = disk_location.partition(":").last
    values_hash[unit_number] = "Disk: #{disk_location}, #{disk_name}, Disk Size: #{disk_size}GB, Type: #{disk_type}"
  end
  i += 1
end

Its possible using disk number to resize the incorrect disk if multiple remove and add operations are completed on a virtual machine. Using "UnitNumber" instead stops this mix up from occurring.

To pass the unit number from the dialog you can use the below code, which also provides the customer with a nice drop down choice.

#Get the  number of disks to loop through
i = 0
num = vm.num_disks

while i < num do
  disk_num = i
  
  if vm.hardware.disks[disk_num].device_type == "floppy"
    #i += 1
  else
    disk_location = vm.hardware.disks[disk_num].location
    disk_name = vm.hardware.disks[disk_num].filename.partition("]").last
    disk_name = disk_name.partition("/").last
    disk_size = vm.hardware.disks[disk_num].size/1024/1024/1024
    disk_type = vm.hardware.disks[disk_num].disk_type
    
    #This strips out the "0:" for the scsi device, leaving just the unit number to pass.
    unit_number = disk_location.partition(":").last
    values_hash[unit_number] = "Disk: #{disk_location}, #{disk_name}, Disk Size: #{disk_size}GB, Type: #{disk_type}"
  end
  i += 1
end

@itewk itewk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just delete the line that is commented out.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants