Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
detach cdrom if host installed
Browse files Browse the repository at this point in the history
  • Loading branch information
simonfuhrer committed Apr 19, 2021
1 parent c9bc45d commit 45a5fb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/models/concerns/foreman_xen/host_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ module HostExtensions
extend ActiveSupport::Concern

def built(installed = true)
compute_resource.cleanup_configdrive(uuid) if compute_resource && compute_resource.type == 'ForemanXen::Xenserver'
if compute_resource && compute_resource.type == 'ForemanXen::Xenserver'
compute_resource.detach_cdrom(uuid)
compute_resource.cleanup_configdrive(uuid)
end
super(installed)
end

Expand Down
16 changes: 16 additions & 0 deletions app/models/foreman_xen/xenserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def iso_library_mountpoint=(path)
attrs[:iso_library_mountpoint] = mountpoint
end

def detach_cdrom(uuid)
begin
vm = find_vm_by_uuid(uuid)
detach_cdrom_vbd(vm) if vm
rescue => e
logger.error "unable to detach cdrom:#{e}"
end
end

def cleanup_configdrive(uuid)
iso_file_name = "foreman-configdrive-#{uuid}.iso"
begin
Expand Down Expand Up @@ -497,6 +506,13 @@ def attach_iso(vm, iso_vdi)
true
end

def detach_cdrom_vbd(vm)
cd_drive = client.vbds.find { |v| v.vm == vm && v.type == 'CD' }
unless cd_drive&.empty
client.eject_vbd cd_drive.reference
end
end

def find_free_userdevice(vm)
# Find next free userdevice id for vbd
# vm.vbds is not current, vm.reload not working.
Expand Down

0 comments on commit 45a5fb3

Please sign in to comment.