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 2019/08/05 12:59:14 UTC

[GitHub] [cloudstack] DaanHoogland commented on a change in pull request #3532: Add new "Add volume" button, to add volume to VM instance directly

DaanHoogland commented on a change in pull request #3532: Add new "Add volume" button, to add volume to VM instance directly
URL: https://github.com/apache/cloudstack/pull/3532#discussion_r310590076
 
 

 ##########
 File path: server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
 ##########
 @@ -736,8 +717,47 @@ public VolumeVO allocVolume(CreateVolumeCmd cmd) throws ResourceAllocationExcept
 
         String userSpecifiedName = getVolumeNameFromCommand(cmd);
 
-        return commitVolume(cmd, caller, owner, displayVolume, zoneId, diskOfferingId, provisioningType, size, minIops, maxIops, parentVolume, userSpecifiedName,
+        VolumeVO volume= commitVolume(cmd, caller, owner, displayVolume, zoneId, diskOfferingId, provisioningType, size,
+                minIops,
+                maxIops, parentVolume, userSpecifiedName,
                 _uuidMgr.generateUuid(Volume.class, cmd.getCustomId()));
+
+        // one step operation - create volume in VM's cluster and attach it
+        // to the VM
+        Long vmId = cmd.getVirtualMachineId();
+        if (vmId != null) {
+            // Check that the virtual machine ID is valid and it's a user vm
+            UserVmVO vm = _userVmDao.findById(vmId);
+            if (vm == null || vm.getType() != VirtualMachine.Type.User) {
+                throw new InvalidParameterValueException("Please specify a valid User VM.");
+            }
+
+            // Check that the VM is in the correct state
+            if (vm.getState() != State.Running && vm.getState() != State.Stopped) {
+                throw new InvalidParameterValueException("Please specify a VM that is either running or stopped.");
+            }
+
+            // permission check
+            _accountMgr.checkAccess(caller, null, false, vm);
+            {
 
 Review comment:
   why this extra block level?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services