Once we install a newer version of an image, we might want to remove the older versions. This program enables that. To use it, an operator is expect to run the following in the REPL: ``` > boot_image = BootImage[... id ...] > st = boot_image.remove_boot_image ``` Then it'll wait for storage volumes using that boot image to drain and after that it'll remove the image files and db records.
30 lines
685 B
Ruby
30 lines
685 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Prog::RemoveBootImage < Prog::Base
|
|
subject_is :boot_image
|
|
|
|
label def start
|
|
boot_image.update(activated_at: nil)
|
|
hop_wait_volumes
|
|
end
|
|
|
|
label def wait_volumes
|
|
nap 30 if boot_image.vm_storage_volumes.count > 0
|
|
hop_remove
|
|
end
|
|
|
|
label def remove
|
|
boot_image.vm_host.sshable.cmd("sudo rm -rf #{boot_image.path.shellescape}")
|
|
|
|
hop_update_database
|
|
end
|
|
|
|
label def update_database
|
|
StorageDevice.where(vm_host_id: boot_image.vm_host.id, name: "DEFAULT").update(
|
|
available_storage_gib: Sequel[:available_storage_gib] + boot_image.size_gib
|
|
)
|
|
boot_image.destroy
|
|
pop "Boot image was removed."
|
|
end
|
|
end
|