DaanHoogland commented on a change in pull request #5216:
URL: https://github.com/apache/cloudstack/pull/5216#discussion_r692791800
##########
File path: server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
##########
@@ -4509,6 +4518,245 @@ protected String validateUserData(String userData,
HTTPMethod httpmethod) {
return null;
}
+ @Override
+ public void validateCloneCondition(CloneVMCmd cmd) throws
InvalidParameterValueException, ResourceUnavailableException,
CloudRuntimeException, ResourceAllocationException {
+
+ if (cmd.getAccountName() != null && cmd.getDomainId() == null) {
+ throw new InvalidParameterValueException("You must input the
domainId together with the account name");
+ }
+
+ final DomainVO domain = cmd.getDomainId() == null ? null :
_domainDao.findById(cmd.getDomainId());
+ final Account account = cmd.getAccountName() == null ? null :
_accountService.getActiveAccountByName(cmd.getAccountName(), cmd.getDomainId());
+ if (domain != null && account != null) {
+ if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
+ throw new InvalidParameterValueException("Invalid user type:
project to clone the VM");
+ }
+ if (account.getState() != Account.State.enabled) {
+ throw new InvalidParameterValueException("User is not enabled
to clone this VM");
+ }
+ }
+ UserVm curVm = cmd.getTargetVM();
+ if (curVm == null) {
+ throw new CloudRuntimeException("the VM doesn't exist or not
registered in management server!");
+ }
+ UserVmVO vmStatus = _vmDao.findById(cmd.getId());
+// if (vmStatus.state != State.Shutdown && vmStatus.state !=
State.Stopped) {
+// throw new CloudRuntimeException("You should clone an instance
that's shutdown!");
+// }
Review comment:
please remove
##########
File path: server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
##########
@@ -4509,6 +4518,245 @@ protected String validateUserData(String userData,
HTTPMethod httpmethod) {
return null;
}
+ @Override
+ public void validateCloneCondition(CloneVMCmd cmd) throws
InvalidParameterValueException, ResourceUnavailableException,
CloudRuntimeException, ResourceAllocationException {
+
+ if (cmd.getAccountName() != null && cmd.getDomainId() == null) {
+ throw new InvalidParameterValueException("You must input the
domainId together with the account name");
+ }
+
+ final DomainVO domain = cmd.getDomainId() == null ? null :
_domainDao.findById(cmd.getDomainId());
+ final Account account = cmd.getAccountName() == null ? null :
_accountService.getActiveAccountByName(cmd.getAccountName(), cmd.getDomainId());
+ if (domain != null && account != null) {
+ if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
+ throw new InvalidParameterValueException("Invalid user type:
project to clone the VM");
+ }
+ if (account.getState() != Account.State.enabled) {
+ throw new InvalidParameterValueException("User is not enabled
to clone this VM");
+ }
+ }
+ UserVm curVm = cmd.getTargetVM();
+ if (curVm == null) {
+ throw new CloudRuntimeException("the VM doesn't exist or not
registered in management server!");
+ }
+ UserVmVO vmStatus = _vmDao.findById(cmd.getId());
+// if (vmStatus.state != State.Shutdown && vmStatus.state !=
State.Stopped) {
+// throw new CloudRuntimeException("You should clone an instance
that's shutdown!");
+// }
+ if (vmStatus.getHypervisorType() != HypervisorType.KVM &&
vmStatus.getHypervisorType() != HypervisorType.Simulator) {
+ throw new CloudRuntimeException("The clone operation is only
supported on KVM and Simulator!");
+ }
+ String kvmEnabled = _configDao.getValue("kvm.snapshot.enabled");
+ if (kvmEnabled == null || !kvmEnabled.equalsIgnoreCase("true")) {
+ throw new CloudRuntimeException("Clone VM is not supported, as
snapshots are disabled");
+ }
+ Long accountId = curVm.getAccountId();
+ Account vmOwner = _accountDao.findById(accountId);
+ if (vmOwner == null) {
+ throw new CloudRuntimeException("This VM doesn't have an owner
account, please assign one to it");
+ }
+ List<VolumeVO> volumes = _volsDao.findByInstanceAndType(cmd.getId(),
Volume.Type.ROOT);
+ if (CollectionUtils.isEmpty(volumes)) {
+ throw new CloudRuntimeException("The VM to copy does not have a
Volume attached!");
+ }
+ // verify that the VM doesn't expire
+ Map<String, String> details = curVm.getDetails();
+ verifyDetails(details);
+// Account activeOwner = _accountDao.findById(cmd.getEntityOwnerId());
Review comment:
please remove
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]