Skip to content

Commit 759579c

Browse files
committed
Fix merge issues
1 parent a94104d commit 759579c

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.vm;
1818

19+
import java.util.Objects;
20+
import java.util.stream.Stream;
21+
1922
import org.apache.cloudstack.api.ACL;
2023
import org.apache.cloudstack.api.APICommand;
2124
import org.apache.cloudstack.api.ApiConstants;
@@ -24,8 +27,10 @@
2427
import org.apache.cloudstack.api.ResponseObject.ResponseView;
2528
import org.apache.cloudstack.api.ServerApiException;
2629
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
30+
import org.apache.cloudstack.api.response.SnapshotResponse;
2731
import org.apache.cloudstack.api.response.TemplateResponse;
2832
import org.apache.cloudstack.api.response.UserVmResponse;
33+
import org.apache.cloudstack.api.response.VolumeResponse;
2934
import org.apache.cloudstack.context.CallContext;
3035

3136
import com.cloud.exception.ConcurrentOperationException;
@@ -34,6 +39,7 @@
3439
import com.cloud.exception.ResourceAllocationException;
3540
import com.cloud.exception.ResourceUnavailableException;
3641
import com.cloud.uservm.UserVm;
42+
import com.cloud.utils.exception.CloudRuntimeException;
3743
import com.cloud.vm.VirtualMachine;
3844

3945
@APICommand(name = "deployVirtualMachine", description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class},
@@ -51,11 +57,13 @@ public class DeployVMCmd extends BaseDeployVMCmd {
5157
@ACL
5258
@Parameter(name = ApiConstants.TEMPLATE_ID, type = CommandType.UUID, entityType = TemplateResponse.class, description = "the ID of the template for the virtual machine")
5359
private Long templateId;
60+
5461
@Parameter(name = ApiConstants.VOLUME_ID, type = CommandType.UUID, entityType = VolumeResponse.class, since = "4.21")
5562
private Long volumeId;
5663

5764
@Parameter(name = ApiConstants.SNAPSHOT_ID, type = CommandType.UUID, entityType = SnapshotResponse.class, since = "4.21")
5865
private Long snapshotId;
66+
5967
/////////////////////////////////////////////////////
6068
/////////////////// Accessors ///////////////////////
6169
/////////////////////////////////////////////////////

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6191,10 +6191,6 @@ private void verifyTemplate(BaseDeployVMCmd cmd, VirtualMachineTemplate template
61916191
throw new InvalidParameterValueException("Can't deploy VNF appliance from a non-VNF template");
61926192
}
61936193

6194-
if (cmd.isVolumeOrSnapshotProvided() &&
6195-
(!(HypervisorType.KVM.equals(template.getHypervisorType()) || HypervisorType.KVM.equals(cmd.getHypervisor())))) {
6196-
throw new InvalidParameterValueException("Deploying a virtual machine with existing volume/snapshot is supported only from KVM hypervisors");
6197-
}
61986194
ServiceOfferingJoinVO svcOffering = serviceOfferingJoinDao.findById(serviceOfferingId);
61996195

62006196
if (template.isDeployAsIs()) {
@@ -6269,6 +6265,10 @@ public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityE
62696265
} else {
62706266
template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
62716267
}
6268+
if (cmd.isVolumeOrSnapshotProvided() &&
6269+
(!(HypervisorType.KVM.equals(template.getHypervisorType()) || HypervisorType.KVM.equals(cmd.getHypervisor())))) {
6270+
throw new InvalidParameterValueException("Deploying a virtual machine with existing volume/snapshot is supported only from KVM hypervisors");
6271+
}
62726272
verifyTemplate(cmd, template, serviceOfferingId);
62736273

62746274
Long diskOfferingId = cmd.getDiskOfferingId();
@@ -6304,12 +6304,12 @@ public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityE
63046304
networkIds = new ArrayList<>(userVmNetworkMap.values());
63056305
}
63066306

6307-
return createVirtualMachine(cmd, zone, owner, serviceOffering, template, cmd.getHypervisor(), diskOfferingId, cmd.getSize(), overrideDiskOfferingId, dataDiskOfferingsInfo, networkIds, cmd.getIpToNetworkMap());
6307+
return createVirtualMachine(cmd, zone, owner, serviceOffering, template, cmd.getHypervisor(), diskOfferingId, cmd.getSize(), overrideDiskOfferingId, dataDiskOfferingsInfo, networkIds, cmd.getIpToNetworkMap(), volume, snapshot);
63086308
}
63096309

63106310
private UserVm createVirtualMachine(BaseDeployVMCmd cmd, DataCenter zone, Account owner, ServiceOffering serviceOffering, VirtualMachineTemplate template,
63116311
HypervisorType hypervisor, Long diskOfferingId, Long size, Long overrideDiskOfferingId, List<DiskOfferingInfo> dataDiskOfferingsInfo,
6312-
List<Long> networkIds, Map<Long, IpAddresses> ipToNetworkMap) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, ResourceAllocationException {
6312+
List<Long> networkIds, Map<Long, IpAddresses> ipToNetworkMap, Volume volume, Snapshot snapshot) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, ResourceAllocationException {
63136313

63146314
ServiceOfferingJoinVO svcOffering = serviceOfferingJoinDao.findById(serviceOffering.getId());
63156315
boolean isLeaseFeatureEnabled = VMLeaseManager.InstanceLeaseEnabled.value();
@@ -9525,7 +9525,7 @@ public UserVm allocateVMFromBackup(CreateVMFromBackupCmd cmd) throws Insufficien
95259525
ipToNetworkMap = backupManager.getIpToNetworkMapFromBackup(backup, cmd.getPreserveIp(), networkIds);
95269526
}
95279527

9528-
return createVirtualMachine(cmd, zone, owner, serviceOffering, template, hypervisorType, diskOfferingId, size, overrideDiskOfferingId, dataDiskOfferingsInfo, networkIds, ipToNetworkMap);
9528+
return createVirtualMachine(cmd, zone, owner, serviceOffering, template, hypervisorType, diskOfferingId, size, overrideDiskOfferingId, dataDiskOfferingsInfo, networkIds, ipToNetworkMap, null, null);
95299529
}
95309530

95319531
@Override

server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,6 @@
181181
import com.cloud.vm.snapshot.VMSnapshotVO;
182182
import com.cloud.vm.snapshot.dao.VMSnapshotDao;
183183

184-
import org.apache.cloudstack.vm.lease.VMLeaseManager;
185-
186-
import org.mockito.MockedStatic;
187-
188184
import java.text.SimpleDateFormat;
189185
import java.time.LocalDateTime;
190186
import java.time.ZoneOffset;
@@ -3329,15 +3325,15 @@ public void testAllocateVMFromBackupUsingCmdValues() throws InsufficientCapacity
33293325

33303326
Mockito.doReturn(userVmVoMock).when(userVmManagerImpl).createAdvancedVirtualMachine(any(), any(), any(), any(), any(), any(), any(),
33313327
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), nullable(Boolean.class), any(), any(), any(),
3332-
any(), any(), any(), any(), eq(true), any(), any());
3328+
any(), any(), any(), any(), eq(true), any(), any(), any(), any());
33333329

33343330
UserVm result = userVmManagerImpl.allocateVMFromBackup(cmd);
33353331

33363332
assertNotNull(result);
33373333
Mockito.verify(backupDao).findById(backupId);
33383334
Mockito.verify(userVmManagerImpl).createAdvancedVirtualMachine(any(), any(), any(), any(), any(), any(), any(),
33393335
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), nullable(Boolean.class), any(), any(), any(),
3340-
any(), any(), any(), any(), eq(true), any(), any());
3336+
any(), any(), any(), any(), eq(true), any(), any(), any(), any());
33413337
}
33423338

33433339
@Test
@@ -3385,14 +3381,14 @@ public void testAllocateVMFromBackupUsingBackupValues() throws InsufficientCapac
33853381

33863382
Mockito.doReturn(userVmVoMock).when(userVmManagerImpl).createAdvancedVirtualMachine(any(), any(), any(), any(), any(), any(), any(),
33873383
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), eq(false), any(), any(), any(),
3388-
any(), any(), any(), any(), eq(false), any(), any());
3384+
any(), any(), any(), any(), eq(false), any(), any(), any(), any());
33893385

33903386
UserVm result = userVmManagerImpl.allocateVMFromBackup(cmd);
33913387

33923388
assertNotNull(result);
33933389
Mockito.verify(userVmManagerImpl).createAdvancedVirtualMachine(any(), any(), any(), any(), any(), any(), any(),
33943390
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), eq(false), any(), any(), any(),
3395-
any(), any(), any(), any(), eq(false), any(), any());
3391+
any(), any(), any(), any(), eq(false), any(), any(), any(), any());
33963392
}
33973393

33983394
@Test
@@ -3499,15 +3495,15 @@ public void testAllocateVMFromBackupUsingCmdValuesWithISO() throws InsufficientC
34993495

35003496
Mockito.doReturn(userVmVoMock).when(userVmManagerImpl).createAdvancedVirtualMachine(any(), any(), any(), any(), any(), any(), any(),
35013497
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), nullable(Boolean.class), any(), any(), any(),
3502-
any(), any(), any(), any(), eq(true), any(), any());
3498+
any(), any(), any(), any(), eq(true), any(), any(), any(), any());
35033499

35043500
UserVm result = userVmManagerImpl.allocateVMFromBackup(cmd);
35053501

35063502
assertNotNull(result);
35073503
Mockito.verify(backupDao).findById(backupId);
35083504
Mockito.verify(userVmManagerImpl).createAdvancedVirtualMachine(any(), any(), any(), any(), any(), any(), any(),
35093505
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), nullable(Boolean.class), any(), any(), any(),
3510-
any(), any(), any(), any(), eq(true), any(), any());
3506+
any(), any(), any(), any(), eq(true), any(), any(), any(), any());
35113507
}
35123508

35133509
@Test
@@ -3560,14 +3556,14 @@ public void testAllocateVMFromBackupUsingBackupValuesWithISO() throws Insufficie
35603556

35613557
Mockito.doReturn(userVmVoMock).when(userVmManagerImpl).createAdvancedVirtualMachine(any(), any(), any(), any(), any(), any(), any(),
35623558
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), eq(false), any(), any(), any(),
3563-
any(), any(), any(), any(), eq(false), any(), any());
3559+
any(), any(), any(), any(), eq(false), any(), any(), any(), any());
35643560

35653561
UserVm result = userVmManagerImpl.allocateVMFromBackup(cmd);
35663562

35673563
assertNotNull(result);
35683564
Mockito.verify(userVmManagerImpl).createAdvancedVirtualMachine(any(), any(), any(), any(), any(), any(), any(),
35693565
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), eq(false), any(), any(), any(),
3570-
any(), any(), any(), any(), eq(false), any(), any());
3566+
any(), any(), any(), any(), eq(false), any(), any(), any(), any());
35713567
}
35723568

35733569
@Test
@@ -3862,7 +3858,7 @@ public void createVirtualMachineWithExistingVolume() throws ResourceUnavailableE
38623858
when(_dcMock.isLocalStorageEnabled()).thenReturn(false);
38633859
when(_dcMock.getNetworkType()).thenReturn(DataCenter.NetworkType.Basic);
38643860
Mockito.doReturn(userVmVoMock).when(userVmManagerImpl).createBasicSecurityGroupVirtualMachine(any(), any(), any(), any(), any(), any(), any(),
3865-
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), nullable(Boolean.class), any(), any(), any(),
3861+
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), nullable(Boolean.class), any(), any(), any(),
38663862
any(), any(), any(), any(), eq(true), any(), any(), any());
38673863

38683864

@@ -3900,7 +3896,7 @@ public void createVirtualMachineWithExistingSnapshot() throws ResourceUnavailabl
39003896
when(_dcMock.isLocalStorageEnabled()).thenReturn(false);
39013897
when(_dcMock.getNetworkType()).thenReturn(DataCenter.NetworkType.Basic);
39023898
Mockito.doReturn(userVmVoMock).when(userVmManagerImpl).createBasicSecurityGroupVirtualMachine(any(), any(), any(), any(), any(), any(), any(),
3903-
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), nullable(Boolean.class), any(), any(), any(),
3899+
any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), nullable(Boolean.class), any(), any(), any(),
39043900
any(), any(), any(), any(), eq(true), any(), any(), any());
39053901

39063902

0 commit comments

Comments
 (0)