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

Update resize_disk.rb #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

dodge245
Copy link

@dodge245 dodge245 commented Jun 13, 2019

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
Copy link
Collaborator

@itewk itewk left a comment

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants