You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2022/08/03 13:59:29 UTC

[GitHub] [cloudstack] SadiJr commented on a diff in pull request #6581: [Veeam] enable volume attach/detach in VMs with Backup Offerings

SadiJr commented on code in PR #6581:
URL: https://github.com/apache/cloudstack/pull/6581#discussion_r936701790


##########
server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java:
##########
@@ -2396,6 +2397,35 @@ private void checkDeviceId(Long deviceId, VolumeInfo volumeToAttach, UserVmVO vm
         return volumeToAttach;
     }
 
+    protected void validateIfVmHasBackups(UserVmVO vm, boolean attach) {
+        if ((vm.getBackupOfferingId() != null || CollectionUtils.isNotEmpty(vm.getBackupVolumeList())) &&
+                BooleanUtils.isFalse(BackupManager.BackupEnableAttachDetachVolumes.value())) {
+            String errorMsg = "Unable to detach volume, cannot detach volume from a VM that has backups. First remove the VM from the backup offering or "
+                    + "set the global configuration 'backup.enable.attach.detach.of.volumes' to true.";
+            if (attach)
+                errorMsg = "Unable to attach volume, please specify a VM that does not have any backups or set the global configuration "
+                        + "'backup.enable.attach.detach.of.volumes' to true.";
+            throw new InvalidParameterValueException(errorMsg);
+        }
+    }
+
+    protected String createVolumeInfoFromVolumes(List<VolumeVO> vmVolumes) {
+        try {
+            List<Backup.VolumeInfo> list = new ArrayList<>();
+            for (VolumeVO vol : vmVolumes) {
+                list.add(new Backup.VolumeInfo(vol.getUuid(), vol.getPath(), vol.getVolumeType(), vol.getSize()));
+            }
+            return new Gson().toJson(list.toArray(), Backup.VolumeInfo[].class);

Review Comment:
   Done, thanks.



##########
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/guru/VMwareGuru.java:
##########
@@ -736,12 +739,14 @@ protected VolumeVO updateVolume(VirtualDisk disk, Map<VirtualDisk, VolumeVO> dis
         volume.setPath(volumeName);
         volume.setPoolId(poolId);
         VirtualMachineDiskInfo diskInfo = getDiskInfo(vmToImport, poolId, volumeName);
-        volume.setChainInfo(new Gson().toJson(diskInfo));
+        volume.setChainInfo(GSON.toJson(diskInfo));

Review Comment:
   Done, thanks.



##########
server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java:
##########
@@ -2396,6 +2397,35 @@ private void checkDeviceId(Long deviceId, VolumeInfo volumeToAttach, UserVmVO vm
         return volumeToAttach;
     }
 
+    protected void validateIfVmHasBackups(UserVmVO vm, boolean attach) {
+        if ((vm.getBackupOfferingId() != null || CollectionUtils.isNotEmpty(vm.getBackupVolumeList())) &&

Review Comment:
   Done, thanks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org