Skip to content

Commit 4290367

Browse files
committed
server: add external hypervisor check for vm related apis
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 7939d74 commit 4290367

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
import javax.xml.parsers.DocumentBuilder;
6060
import javax.xml.parsers.ParserConfigurationException;
6161

62-
import com.cloud.deploy.DeploymentPlan;
63-
import com.cloud.network.NetworkService;
6462
import org.apache.cloudstack.acl.ControlledEntity;
6563
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
6664
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
@@ -116,6 +114,8 @@
116114
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
117115
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
118116
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
117+
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
118+
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
119119
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
120120
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
121121
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
@@ -140,9 +140,9 @@
140140
import org.apache.cloudstack.userdata.UserDataManager;
141141
import org.apache.cloudstack.utils.bytescale.ByteScaleUtils;
142142
import org.apache.cloudstack.utils.security.ParserUtils;
143+
import org.apache.cloudstack.vm.UnmanagedVMsManager;
143144
import org.apache.cloudstack.vm.lease.VMLeaseManager;
144145
import org.apache.cloudstack.vm.schedule.VMScheduleManager;
145-
import org.apache.cloudstack.vm.UnmanagedVMsManager;
146146
import org.apache.commons.collections.CollectionUtils;
147147
import org.apache.commons.collections.MapUtils;
148148
import org.apache.commons.lang.math.NumberUtils;
@@ -211,6 +211,7 @@
211211
import com.cloud.dc.dao.VlanDao;
212212
import com.cloud.deploy.DataCenterDeployment;
213213
import com.cloud.deploy.DeployDestination;
214+
import com.cloud.deploy.DeploymentPlan;
214215
import com.cloud.deploy.DeploymentPlanner;
215216
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
216217
import com.cloud.deploy.DeploymentPlanningManager;
@@ -250,6 +251,7 @@
250251
import com.cloud.host.HostVO;
251252
import com.cloud.host.Status;
252253
import com.cloud.host.dao.HostDao;
254+
import com.cloud.hypervisor.Hypervisor;
253255
import com.cloud.hypervisor.Hypervisor.HypervisorType;
254256
import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
255257
import com.cloud.hypervisor.kvm.dpdk.DpdkHelper;
@@ -261,6 +263,7 @@
261263
import com.cloud.network.Network.Provider;
262264
import com.cloud.network.Network.Service;
263265
import com.cloud.network.NetworkModel;
266+
import com.cloud.network.NetworkService;
264267
import com.cloud.network.Networks.TrafficType;
265268
import com.cloud.network.PhysicalNetwork;
266269
import com.cloud.network.as.AutoScaleManager;
@@ -397,9 +400,6 @@
397400
import com.cloud.vm.snapshot.VMSnapshotVO;
398401
import com.cloud.vm.snapshot.dao.VMSnapshotDao;
399402

400-
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
401-
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
402-
403403

404404
public class UserVmManagerImpl extends ManagerBase implements UserVmManager, VirtualMachineGuru, Configurable {
405405

@@ -967,6 +967,10 @@ public UserVm resetVMUserData(ResetVMUserDataCmd cmd) throws ResourceUnavailable
967967
if (UserVmManager.SHAREDFSVM.equals(userVm.getUserVmType())) {
968968
throw new InvalidParameterValueException("Operation not supported on Shared FileSystem Instance");
969969
}
970+
if (Hypervisor.HypervisorType.External.equals(userVm.getHypervisorType())) {
971+
throw new InvalidParameterValueException(String.format("Operation not supported for %s hypervisor Instance",
972+
Hypervisor.HypervisorType.External.name()));
973+
}
970974
_accountMgr.checkAccess(caller, null, true, userVm);
971975

972976
VMTemplateVO template = _templateDao.findByIdIncludingRemoved(userVm.getTemplateId());
@@ -1014,6 +1018,10 @@ public UserVm resetVMSSHKey(ResetVMSSHKeyCmd cmd) throws ResourceUnavailableExce
10141018
if (UserVmManager.SHAREDFSVM.equals(userVm.getUserVmType())) {
10151019
throw new InvalidParameterValueException("Operation not supported on Shared FileSystem Instance");
10161020
}
1021+
if (Hypervisor.HypervisorType.External.equals(userVm.getHypervisorType())) {
1022+
throw new InvalidParameterValueException(String.format("Operation not supported for %s hypervisor Instance",
1023+
Hypervisor.HypervisorType.External.name()));
1024+
}
10171025

10181026
VMTemplateVO template = _templateDao.findByIdIncludingRemoved(userVm.getTemplateId());
10191027

@@ -1945,6 +1953,10 @@ public UserVm upgradeVirtualMachine(ScaleVMCmd cmd) throws ResourceUnavailableEx
19451953
if (vm == null) {
19461954
throw new InvalidParameterValueException("Unable to find VM's UUID");
19471955
}
1956+
if (Hypervisor.HypervisorType.External.equals(vm.getHypervisorType())) {
1957+
throw new InvalidParameterValueException(String.format("Operation not supported for %s hypervisor Instance",
1958+
Hypervisor.HypervisorType.External.name()));
1959+
}
19481960
CallContext.current().setEventDetails("Vm Id: " + vm.getUuid());
19491961

19501962
Map<String, String> cmdDetails = cmd.getDetails();
@@ -8526,6 +8538,10 @@ public UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException,
85268538
if (UserVmManager.SHAREDFSVM.equals(vm.getUserVmType())) {
85278539
throw new InvalidParameterValueException("Operation not supported on Shared FileSystem Instance");
85288540
}
8541+
if (Hypervisor.HypervisorType.External.equals(vm.getHypervisorType())) {
8542+
throw new InvalidParameterValueException(String.format("Operation not supported for %s hypervisor Instance",
8543+
Hypervisor.HypervisorType.External.name()));
8544+
}
85298545
_accountMgr.checkAccess(caller, null, true, vm);
85308546

85318547
VMTemplateVO template;

server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import org.apache.cloudstack.annotation.AnnotationService;
3131
import org.apache.cloudstack.annotation.dao.AnnotationDao;
3232
import org.apache.cloudstack.api.ApiConstants;
33-
import org.apache.commons.collections.MapUtils;
34-
import org.springframework.stereotype.Component;
3533
import org.apache.cloudstack.api.command.user.vmsnapshot.ListVMSnapshotCmd;
3634
import org.apache.cloudstack.context.CallContext;
3735
import org.apache.cloudstack.engine.subsystem.api.storage.StorageStrategyFactory;
@@ -55,6 +53,8 @@
5553
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
5654
import org.apache.cloudstack.storage.to.VolumeObjectTO;
5755
import org.apache.cloudstack.utils.identity.ManagementServerNode;
56+
import org.apache.commons.collections.MapUtils;
57+
import org.springframework.stereotype.Component;
5858

5959
import com.cloud.agent.api.RestoreVMSnapshotCommand;
6060
import com.cloud.agent.api.VMSnapshotTO;
@@ -69,6 +69,7 @@
6969
import com.cloud.exception.ResourceUnavailableException;
7070
import com.cloud.exception.VirtualMachineMigrationException;
7171
import com.cloud.gpu.GPU;
72+
import com.cloud.hypervisor.Hypervisor;
7273
import com.cloud.hypervisor.Hypervisor.HypervisorType;
7374
import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
7475
import com.cloud.projects.Project.ListProjectResourcesCriteria;
@@ -513,6 +514,10 @@ public VMSnapshot createVMSnapshot(Long vmId, Long vmSnapshotId, Boolean quiesce
513514
if (UserVmManager.SHAREDFSVM.equals(userVm.getUserVmType())) {
514515
throw new InvalidParameterValueException("Operation not supported on Shared FileSystem Instance");
515516
}
517+
if (Hypervisor.HypervisorType.External.equals(userVm.getHypervisorType())) {
518+
throw new InvalidParameterValueException(String.format("Operation not supported for %s hypervisor Instance",
519+
Hypervisor.HypervisorType.External.name()));
520+
}
516521
VMSnapshotVO vmSnapshot = _vmSnapshotDao.findById(vmSnapshotId);
517522
if (vmSnapshot == null) {
518523
throw new CloudRuntimeException("VM snapshot id: " + vmSnapshotId + " can not be found");

server/src/main/java/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.cloud.event.EventTypes;
4444
import com.cloud.exception.InvalidParameterValueException;
4545
import com.cloud.exception.PermissionDeniedException;
46+
import com.cloud.hypervisor.Hypervisor;
4647
import com.cloud.user.Account;
4748
import com.cloud.user.AccountManager;
4849
import com.cloud.user.DomainManager;
@@ -434,6 +435,10 @@ public UserVm updateVMAffinityGroups(Long vmId, List<Long> affinityGroupIds) {
434435
if (UserVmManager.SHAREDFSVM.equals(vmInstance.getUserVmType())) {
435436
throw new InvalidParameterValueException("Operation not supported on Shared FileSystem Instance");
436437
}
438+
if (Hypervisor.HypervisorType.External.equals(vmInstance.getHypervisorType())) {
439+
throw new InvalidParameterValueException(String.format("Operation not supported for %s hypervisor Instance",
440+
Hypervisor.HypervisorType.External.name()));
441+
}
437442

438443
// Check that the VM is stopped
439444
if (!vmInstance.getState().equals(State.Stopped)) {

0 commit comments

Comments
 (0)