Hot add disk to already provisioned Vmware VM


#1

Hi,

I would like to be able to add an extra disk to an already provisioned VM. I have created a button, that calls a custom dialog with a single field : new disk size in GB (interger). When the user submits the dialog, a request is generated and caught by the following method:

# Get the size for the new disk from the root object
size = $evm.root['dialog_option_0_size'].to_i

# Add disk to a VM
if size.zero?
  $evm.log("error", "Size:<#{size}> invalid")
else
  $evm.log("info", "Creating a new #{size}GB disk on Storage:<#{vm.storage_name}>")
  vm.add_disk(nil, size * 1024, :sync => true, :thin_provisioned => true)
end

In /var/www/miq/vmdb/log/evm.log, I get the following error:

[----] I, [2015-05-28T12:15:07.298715 #2075:4fbe88]  INFO -- : MIQ(EmsVmware.with_provider_connection) Connecting through EmsVmware: [VMWARE]
[----] I, [2015-05-28T12:15:07.749701 #2075:4fbe88]  INFO -- : MIQ(MiqFaultTolerantVim._connect) EMS: [VMWARE] [Broker] Connecting with address: [10.231.0.112], userid: [ADJCDRES\mallet2]...
[----] I, [2015-05-28T12:15:07.985349 #2075:4fbe88]  INFO -- : MIQ(MiqFaultTolerantVim._connect) EMS: [VMWARE] [Broker] 10.231.0.112 is VC, API version: 5.1
[----] I, [2015-05-28T12:15:07.985606 #2075:4fbe88]  INFO -- : MIQ(MiqFaultTolerantVim._connect) EMS: [VMWARE] [Broker] Connected
[----] I, [2015-05-28T12:15:08.033266 #2075:4fbe88]  INFO -- : MIQ(EmsVmware.invoke_vim_ws) EMS: [VMWARE] VmVmware: id [1015], name [LX1941], ems_ref [vm-5872] Invoking [addDisk]...
[----] E, [2015-05-28T12:15:08.054264 #2075:4fbe88] ERROR -- : MIQ(MiqQueue.deliver)    Message id: [89158], Error: [addDisk: no SCSI controller found]
[----] E, [2015-05-28T12:15:08.054632 #2075:4fbe88] ERROR -- : [RuntimeError]: addDisk: no SCSI controller found  Method:[rescue in deliver]
[----] E, [2015-05-28T12:15:08.054750 #2075:4fbe88] ERROR -- : (druby://127.0.0.1:50917) /var/www/miq/lib/VMwareWebService/MiqVimVm.rb:740:in `addDisk'
(druby://127.0.0.1:50917) /opt/rubies/ruby-2.0.0-p645/lib/ruby/2.0.0/drb/drb.rb:1588:in `perform_without_block'
(druby://127.0.0.1:50917) /opt/rubies/ruby-2.0.0-p645/lib/ruby/2.0.0/drb/drb.rb:1548:in `perform'
(druby://127.0.0.1:50917) /opt/rubies/ruby-2.0.0-p645/lib/ruby/2.0.0/drb/drb.rb:1626:in `block (2 levels) in main_loop'
(druby://127.0.0.1:50917) /opt/rubies/ruby-2.0.0-p645/lib/ruby/2.0.0/drb/drb.rb:1622:in `loop'
(druby://127.0.0.1:50917) /opt/rubies/ruby-2.0.0-p645/lib/ruby/2.0.0/drb/drb.rb:1622:in `block in main_loop'
(druby://127.0.0.1:50917) /var/www/miq/vmdb/lib/extensions/ar_thread.rb:22:in `block in start_with_release'
/var/www/miq/vmdb/app/models/ems_vmware.rb:410:in `block in invoke_vim_ws'
/var/www/miq/vmdb/app/models/mixins/provider_object_mixin.rb:16:in `block in with_provider_object'
/var/www/miq/vmdb/app/models/mixins/vim_connect_mixin.rb:39:in `with_provider_connection'
/var/www/miq/vmdb/app/models/mixins/provider_object_mixin.rb:13:in `with_provider_object'
/var/www/miq/vmdb/app/models/ems_vmware.rb:406:in `invoke_vim_ws'
/var/www/miq/vmdb/app/models/ems_vmware.rb:354:in `vm_add_disk'
/var/www/miq/vmdb/app/models/vm_or_template.rb:336:in `run_command_via_parent'
/var/www/miq/vmdb/app/models/vm_or_template/operations/configuration.rb:76:in `raw_add_disk'
/var/www/miq/vmdb/app/models/vm_or_template/operations/configuration.rb:81:in `add_disk'
/var/www/miq/vmdb/app/models/miq_queue.rb:356:in `block in deliver'
/opt/rubies/ruby-2.0.0-p645/lib/ruby/2.0.0/timeout.rb:66:in `timeout'
/var/www/miq/vmdb/app/models/miq_queue.rb:352:in `deliver'
/var/www/miq/vmdb/lib/workers/queue_worker_base.rb:107:in `deliver_queue_message'
/var/www/miq/vmdb/lib/workers/queue_worker_base.rb:135:in `deliver_message'
/var/www/miq/vmdb/lib/workers/queue_worker_base.rb:152:in `block in do_work'
/var/www/miq/vmdb/lib/workers/queue_worker_base.rb:146:in `loop'
/var/www/miq/vmdb/lib/workers/queue_worker_base.rb:146:in `do_work'
/var/www/miq/vmdb/lib/workers/worker_base.rb:323:in `block in do_work_loop'
/var/www/miq/vmdb/lib/workers/worker_base.rb:320:in `loop'
/var/www/miq/vmdb/lib/workers/worker_base.rb:320:in `do_work_loop'
/var/www/miq/vmdb/lib/workers/worker_base.rb:141:in `run'
/var/www/miq/vmdb/lib/workers/worker_base.rb:122:in `start'
/var/www/miq/vmdb/lib/workers/worker_base.rb:23:in `start_worker'
/var/www/miq/vmdb/lib/workers/bin/worker.rb:3:in `<top (required)>'
/opt/rubies/ruby-2.0.0-p645/lib/ruby/gems/2.0.0/bundler/gems/rails-4842a8377644/railties/lib/rails/commands/runner.rb:52:in `eval'
/opt/rubies/ruby-2.0.0-p645/lib/ruby/gems/2.0.0/bundler/gems/rails-4842a8377644/railties/lib/rails/commands/runner.rb:52:in `<top (required)>'
/opt/rubies/ruby-2.0.0-p645/lib/ruby/gems/2.0.0/bundler/gems/rails-4842a8377644/railties/lib/rails/commands.rb:64:in `require'
/opt/rubies/ruby-2.0.0-p645/lib/ruby/gems/2.0.0/bundler/gems/rails-4842a8377644/railties/lib/rails/commands.rb:64:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'
[----] I, [2015-05-28T12:15:08.055119 #2075:4fbe88]  INFO -- : MIQ(MiqQueue.delivered)  Message id: [89158], State: [error], Delivered in [1.725558781] seconds
[----] I, [2015-05-28T12:15:08.058580 #2075:4fbe88]  INFO -- : MIQ(MiqQueue.m_callback) Message id: [89158], Invoking Callback with args: ["Finished", "error", "addDisk: no SCSI controller found", "nil"]

From my own analysis, the important part is:

[----] E, [2015-05-28T12:15:08.054264 #2075:4fbe88] ERROR -- : MIQ(MiqQueue.deliver)    Message id: [89158], Error: [addDisk: no SCSI controller found]

But I don’t understand why I have this message. I have checked the code for this message and I have found that it is sent in /var/www/miq/lib/VMwareWebService/MiqVimVm.rb. From what I understand of the code, it calls a method named “getScsiCandU” that returns the VM Scsi Controlers in a hash. And in my case, this hash is empty.

I am running ManageIQ “botvinnik-1-rc3.20150528120417_2f740b4” and I have enabled C&U roles.


Resize VMWare Disk During Provisioning (w/ Fat Template)
#2

Try:

vm.add_disk("[#{vm.storage_name}]", size * 1024, :sync => true)


#3

I had started with this. And it fails with the same message :frowning:


#4

vm.add_disk is limited to only being able to add a scsi disk to a vmware vm. It appears you are attempting to add a disk to a vm that does not have a scsi controller attached to it and does not use scsi disks.


#5

Well, the VM I am trying to add a disk to has a SCSI controler, with LSI driver.


#6

I guess you may have figured out an answer already, but in case not, this works…

# Get vm object
vm = $evm.root['vm']

# Get the vimVm object
vim_vm = vm.object_send('instance_eval', 'with_provider_object { | vimVm | return vimVm }')

# Get the size for the new disk from the root object
size = $evm.root['dialog_size'].to_i

# Add disk to a VM
unless size.zero?
  $evm.log(:info, "Creating a new #{size}GB disk on Storage: #{vm.storage_name}")
  vim_vm.addDisk("[#{vm.storage_name}]", size * 1024 )
end

#7

Hi,
Apologize for reopening this. May I know for code vim_vm. addDisk() to work, do we require to install vmware vddk? Or other packages? Thanks.

Cheers,
Casius.


#8

HI Casius

I’m sorry I can’t respond regarding the requirement or not for VDDK. I know it was installed on the engines we used this on, so if it isn’t working for you, I would certainly suggest installing it. We install it on all our smart proxy engines, as we need it for Smart State Analysis anyway.

Good luck!

Regards
Stephen


#9

@casius No, the VDDK should not be required to change the guest configuration.

What issue are you seeing in the logs and what is the hard drive configuration of the VM (controller, # of disks, etc).


#10

Thanks @ewannema and @Stephen_McKay, I managed to solve my problem and it more of my own codes. Previously at bonvinik, I had created a service catalog where I allowed user to add multiple disks of different sizes. When I checked that the disk size is “0”, I infer that no new disk need to be added. The code check breaks when I migrated to Darga. Instead of check by string, I converted the string to integer and then check by integer. This could be due to different version of ruby?

The root cause took me some debugging to identify as I run into some ruby dump whenever I tried to add a zero size disk. Thanks.

Cheers,
Casius.