1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

B #5409: Add check to avoid changing disks

in vCenter VMs if they have snapshots

(cherry picked from commit e47777a1f88681e0d63029000c9c1aaeb977cc9b)
This commit is contained in:
Tino Vazquez 2021-05-21 15:18:17 +02:00
parent cf9b5bffad
commit 9678719334

View File

@ -1810,6 +1810,15 @@ module VCenterDriver
# Attach DISK to VM (hotplug)
def attach_disk(disk)
# Adding a new disk in newer vSphere versions
# automatically cleans all system snapshots
# https://github.com/OpenNebula/one/issues/5409
if snapshots? or one_snapshots?
error_message = 'Existing sytem snapshots, cannot change disks. '
error_message << 'Please remove all snapshots and try again.'
raise error_message
end
spec_hash = {}
device_change = []
@ -1935,6 +1944,12 @@ module VCenterDriver
def detach_disk(disk)
return unless disk.exists?
if snapshots? or one_snapshots?
error_message = 'Existing sytem snapshots, cannot change disks. '
error_message << 'Please remove all snapshots and try again.'
raise error_message
end
spec_hash = {}
spec_hash[:extraConfig] = [disk.config(:delete)]
spec_hash[:deviceChange] = [{
@ -2191,6 +2206,15 @@ module VCenterDriver
self['rootSnapshot'] && !self['rootSnapshot'].empty?
end
def one_snapshots?
begin
!one_item['TEMPLATE/SNAPSHOT'].nil?
rescue StandardError
# one_item may not be retrieved if deploy_id hasn't been set
false
end
end
def instantiated_as_persistent?
begin
!!one_item["TEMPLATE/CLONING_TEMPLATE_ID"]