Currently, I'm Setting up a custom button in Cloudforms to allow for the removal of a drive from a Virtual Machine that has been provisioned using Cloudforms(hooked into ansible)
I've been looking at this a little while and after some digging discovered the following https://github.com/ManageIQ/manageiq-automation_engine/blob/master/lib/miq_automation_engine/service_models/miq_ae_service_manageiq-providers-vmware-infra_manager-vm.rb
More specifically:
def remove_disk(disk_name, options = {})
sync_or_async_ems_operation(options[:sync], "remove_disk", [disk_name, options])
end
I've assumed two things, that this would probably take the vmdk name and would work the same as "add_disk" (vm.add_disk("[#{vm.storage_name}]", size * 1024, :sync => true)).
I AM AWARE that you can edit disks using the built-in functionality of CLoudforms via the provided configuration button, however, due to customer requirements we needed to edit the HAML files to remove some functionality. Redoing the HAML on every update of CloudForms is rather counterproductive. Creating our own custom dialogs provides us with the customization we needed.
# Get vm object
vm = $evm.root['vm']
raise "Missing $evm.root['vm'] object" unless vm
def log(level, message)
@method = 'Remove_Disk'
$evm.log(level, "#{@method} - #{message}")
end
$evm.create_notification(:audience => 'user', :level => :success, :message => "Lifecycle action 'Remove Disk' Initiated")
log(:info, "Started LCA to remove disk on vm: <#{vm}>")
# Remove disk from the VM
disk_choice = $evm.root['dialog_availabledisks'].to_i
if disk_choice.zero?
disk_name = "#{vm}"
$evm.create_notification(:audience => 'user', :level => :failure, :message => "Lifecycle action 'Remove Disk' Failed, OS Drive cannot be removed.")
log(:error, "C: Drive cannot be deleted")
exit MIQ_ABORT
else
disk_name = "#{vm}_#{disk_choice}"
end
log(:info, "Removing disk:<#{disk_name}> from #{vm}")
begin
vm.remove_disk(disk_name, :sync => true)
rescue => e
log(:error, "e: #{e}")
log(:error, "e.inspect: #{e.inspect}")
log(:error,"[#{e}]\n#{e.backtrace.join("\n")}")
log(:error, "e.message: #{e.message}")
end
exit MIQ_OK
My code runs through without any errors, however, does not actually do anything, the disk selected is not removed from the VM. Fairly sure I am just missing something obvious(Or my assumptions are incorrect), any ideas?