mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Refactoring another bunch of commands for vms
This commit is contained in:
parent
b27a5af5fc
commit
49482e947b
@ -18,31 +18,18 @@
|
|||||||
|
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.BaseCmd.Manager;
|
||||||
import com.cloud.exception.InternalErrorException;
|
|
||||||
import com.cloud.exception.ResourceAllocationException;
|
@Implementation(method="recoverVirtualMachine", manager=Manager.UserVmManager)
|
||||||
import com.cloud.user.Account;
|
|
||||||
import com.cloud.utils.Pair;
|
|
||||||
import com.cloud.vm.UserVmVO;
|
|
||||||
|
|
||||||
public class RecoverVMCmd extends BaseCmd {
|
public class RecoverVMCmd extends BaseCmd {
|
||||||
public static final Logger s_logger = Logger.getLogger(RecoverVMCmd.class.getName());
|
public static final Logger s_logger = Logger.getLogger(RecoverVMCmd.class.getName());
|
||||||
|
|
||||||
private static final String s_name = "recovervirtualmachineresponse";
|
private static final String s_name = "recovervirtualmachineresponse";
|
||||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
|
|
||||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////
|
||||||
//////////////// API parameters /////////////////////
|
//////////////// API parameters /////////////////////
|
||||||
@ -65,44 +52,46 @@ public class RecoverVMCmd extends BaseCmd {
|
|||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return s_name;
|
return s_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getResponse() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Pair<Enum, Boolean>> getProperties() {
|
// @Override
|
||||||
return s_properties;
|
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||||
}
|
// Long vmId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||||
|
// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||||
@Override
|
//
|
||||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
// //if account is removed, return error
|
||||||
Long vmId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
// if(account!=null && account.getRemoved() != null)
|
||||||
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
// throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account " + account.getId()+" is removed");
|
||||||
|
//
|
||||||
//if account is removed, return error
|
// // Verify input parameters
|
||||||
if(account!=null && account.getRemoved() != null)
|
// UserVmVO vmInstance = getManagementServer().findUserVMInstanceById(vmId.longValue());
|
||||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account " + account.getId()+" is removed");
|
// if (vmInstance == null) {
|
||||||
|
// throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + vmId);
|
||||||
// Verify input parameters
|
// }
|
||||||
UserVmVO vmInstance = getManagementServer().findUserVMInstanceById(vmId.longValue());
|
//
|
||||||
if (vmInstance == null) {
|
// if ((account != null) && !getManagementServer().isChildDomain(account.getDomainId(), vmInstance.getDomainId())) {
|
||||||
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + vmId);
|
// // the domain in which the VM lives is not in the admin's domain tree
|
||||||
}
|
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to recover virtual machine with id " + vmId + ", invalid id given.");
|
||||||
|
// }
|
||||||
if ((account != null) && !getManagementServer().isChildDomain(account.getDomainId(), vmInstance.getDomainId())) {
|
//
|
||||||
// the domain in which the VM lives is not in the admin's domain tree
|
// try {
|
||||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to recover virtual machine with id " + vmId + ", invalid id given.");
|
// boolean success = getManagementServer().recoverVirtualMachine(vmId.longValue());
|
||||||
}
|
// if (success == false) {
|
||||||
|
// throw new ServerApiException(BaseCmd.VM_RECOVER_ERROR, "unable to recover virtual machine with id " + vmId.toString());
|
||||||
try {
|
// }
|
||||||
boolean success = getManagementServer().recoverVirtualMachine(vmId.longValue());
|
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||||
if (success == false) {
|
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), Boolean.valueOf(success).toString()));
|
||||||
throw new ServerApiException(BaseCmd.VM_RECOVER_ERROR, "unable to recover virtual machine with id " + vmId.toString());
|
// return returnValues;
|
||||||
}
|
// } catch (ResourceAllocationException ex) {
|
||||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
// throw new ServerApiException(BaseCmd.VM_RECOVER_ERROR, "Failed to recover virtual machine with id " + vmId + "; " + ex.getMessage());
|
||||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), Boolean.valueOf(success).toString()));
|
// } catch (InternalErrorException e) {
|
||||||
return returnValues;
|
// throw new ServerApiException(BaseCmd.VM_RECOVER_ERROR, "Failed to recover virtual machine with id " + vmId + "; " + e.getMessage());
|
||||||
} catch (ResourceAllocationException ex) {
|
// }
|
||||||
throw new ServerApiException(BaseCmd.VM_RECOVER_ERROR, "Failed to recover virtual machine with id " + vmId + "; " + ex.getMessage());
|
// }
|
||||||
} catch (InternalErrorException e) {
|
|
||||||
throw new ServerApiException(BaseCmd.VM_RECOVER_ERROR, "Failed to recover virtual machine with id " + vmId + "; " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,12 +18,7 @@
|
|||||||
package com.cloud.server;
|
package com.cloud.server;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.net.Inet6Address;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -88,7 +83,6 @@ import com.cloud.api.commands.StopSystemVmCmd;
|
|||||||
import com.cloud.api.commands.UpdateAccountCmd;
|
import com.cloud.api.commands.UpdateAccountCmd;
|
||||||
import com.cloud.api.commands.UpdateDomainCmd;
|
import com.cloud.api.commands.UpdateDomainCmd;
|
||||||
import com.cloud.api.commands.UpdateIsoPermissionsCmd;
|
import com.cloud.api.commands.UpdateIsoPermissionsCmd;
|
||||||
import com.cloud.api.commands.UpdateTemplateCmd;
|
|
||||||
import com.cloud.api.commands.UpdateTemplateOrIsoCmd;
|
import com.cloud.api.commands.UpdateTemplateOrIsoCmd;
|
||||||
import com.cloud.api.commands.UpdateTemplateOrIsoPermissionsCmd;
|
import com.cloud.api.commands.UpdateTemplateOrIsoPermissionsCmd;
|
||||||
import com.cloud.api.commands.UpdateTemplatePermissionsCmd;
|
import com.cloud.api.commands.UpdateTemplatePermissionsCmd;
|
||||||
@ -112,19 +106,18 @@ import com.cloud.async.executor.DeployVMParam;
|
|||||||
import com.cloud.async.executor.DisassociateIpAddressParam;
|
import com.cloud.async.executor.DisassociateIpAddressParam;
|
||||||
import com.cloud.async.executor.LoadBalancerParam;
|
import com.cloud.async.executor.LoadBalancerParam;
|
||||||
import com.cloud.async.executor.NetworkGroupIngressParam;
|
import com.cloud.async.executor.NetworkGroupIngressParam;
|
||||||
import com.cloud.async.executor.ResetVMPasswordParam;
|
|
||||||
import com.cloud.async.executor.SecurityGroupParam;
|
import com.cloud.async.executor.SecurityGroupParam;
|
||||||
import com.cloud.async.executor.UpdateLoadBalancerParam;
|
import com.cloud.async.executor.UpdateLoadBalancerParam;
|
||||||
import com.cloud.async.executor.VMOperationParam;
|
import com.cloud.async.executor.VMOperationParam;
|
||||||
import com.cloud.async.executor.VMOperationParam.VmOp;
|
|
||||||
import com.cloud.async.executor.VolumeOperationParam;
|
import com.cloud.async.executor.VolumeOperationParam;
|
||||||
|
import com.cloud.async.executor.VMOperationParam.VmOp;
|
||||||
import com.cloud.async.executor.VolumeOperationParam.VolumeOp;
|
import com.cloud.async.executor.VolumeOperationParam.VolumeOp;
|
||||||
import com.cloud.capacity.CapacityVO;
|
import com.cloud.capacity.CapacityVO;
|
||||||
import com.cloud.capacity.dao.CapacityDao;
|
import com.cloud.capacity.dao.CapacityDao;
|
||||||
import com.cloud.configuration.ConfigurationManager;
|
import com.cloud.configuration.ConfigurationManager;
|
||||||
import com.cloud.configuration.ConfigurationVO;
|
import com.cloud.configuration.ConfigurationVO;
|
||||||
import com.cloud.configuration.ResourceCount.ResourceType;
|
|
||||||
import com.cloud.configuration.ResourceLimitVO;
|
import com.cloud.configuration.ResourceLimitVO;
|
||||||
|
import com.cloud.configuration.ResourceCount.ResourceType;
|
||||||
import com.cloud.configuration.dao.ConfigurationDao;
|
import com.cloud.configuration.dao.ConfigurationDao;
|
||||||
import com.cloud.configuration.dao.ResourceLimitDao;
|
import com.cloud.configuration.dao.ResourceLimitDao;
|
||||||
import com.cloud.consoleproxy.ConsoleProxyManager;
|
import com.cloud.consoleproxy.ConsoleProxyManager;
|
||||||
@ -134,8 +127,8 @@ import com.cloud.dc.DataCenterIpAddressVO;
|
|||||||
import com.cloud.dc.DataCenterVO;
|
import com.cloud.dc.DataCenterVO;
|
||||||
import com.cloud.dc.HostPodVO;
|
import com.cloud.dc.HostPodVO;
|
||||||
import com.cloud.dc.PodVlanMapVO;
|
import com.cloud.dc.PodVlanMapVO;
|
||||||
import com.cloud.dc.Vlan.VlanType;
|
|
||||||
import com.cloud.dc.VlanVO;
|
import com.cloud.dc.VlanVO;
|
||||||
|
import com.cloud.dc.Vlan.VlanType;
|
||||||
import com.cloud.dc.dao.AccountVlanMapDao;
|
import com.cloud.dc.dao.AccountVlanMapDao;
|
||||||
import com.cloud.dc.dao.ClusterDao;
|
import com.cloud.dc.dao.ClusterDao;
|
||||||
import com.cloud.dc.dao.DataCenterDao;
|
import com.cloud.dc.dao.DataCenterDao;
|
||||||
@ -151,7 +144,6 @@ import com.cloud.event.EventVO;
|
|||||||
import com.cloud.event.dao.EventDao;
|
import com.cloud.event.dao.EventDao;
|
||||||
import com.cloud.exception.AgentUnavailableException;
|
import com.cloud.exception.AgentUnavailableException;
|
||||||
import com.cloud.exception.ConcurrentOperationException;
|
import com.cloud.exception.ConcurrentOperationException;
|
||||||
import com.cloud.exception.DiscoveryException;
|
|
||||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||||
import com.cloud.exception.InsufficientStorageCapacityException;
|
import com.cloud.exception.InsufficientStorageCapacityException;
|
||||||
import com.cloud.exception.InternalErrorException;
|
import com.cloud.exception.InternalErrorException;
|
||||||
@ -161,7 +153,6 @@ import com.cloud.exception.PermissionDeniedException;
|
|||||||
import com.cloud.exception.ResourceAllocationException;
|
import com.cloud.exception.ResourceAllocationException;
|
||||||
import com.cloud.exception.ResourceInUseException;
|
import com.cloud.exception.ResourceInUseException;
|
||||||
import com.cloud.exception.StorageUnavailableException;
|
import com.cloud.exception.StorageUnavailableException;
|
||||||
import com.cloud.host.Host;
|
|
||||||
import com.cloud.host.HostStats;
|
import com.cloud.host.HostStats;
|
||||||
import com.cloud.host.HostVO;
|
import com.cloud.host.HostVO;
|
||||||
import com.cloud.host.Status;
|
import com.cloud.host.Status;
|
||||||
@ -201,22 +192,21 @@ import com.cloud.storage.GuestOSCategoryVO;
|
|||||||
import com.cloud.storage.GuestOSVO;
|
import com.cloud.storage.GuestOSVO;
|
||||||
import com.cloud.storage.LaunchPermissionVO;
|
import com.cloud.storage.LaunchPermissionVO;
|
||||||
import com.cloud.storage.Snapshot;
|
import com.cloud.storage.Snapshot;
|
||||||
import com.cloud.storage.Snapshot.SnapshotType;
|
|
||||||
import com.cloud.storage.SnapshotPolicyVO;
|
import com.cloud.storage.SnapshotPolicyVO;
|
||||||
import com.cloud.storage.SnapshotScheduleVO;
|
import com.cloud.storage.SnapshotScheduleVO;
|
||||||
import com.cloud.storage.SnapshotVO;
|
import com.cloud.storage.SnapshotVO;
|
||||||
import com.cloud.storage.Storage;
|
import com.cloud.storage.Storage;
|
||||||
import com.cloud.storage.Storage.FileSystem;
|
|
||||||
import com.cloud.storage.Storage.ImageFormat;
|
|
||||||
import com.cloud.storage.StorageManager;
|
import com.cloud.storage.StorageManager;
|
||||||
import com.cloud.storage.StoragePoolVO;
|
import com.cloud.storage.StoragePoolVO;
|
||||||
import com.cloud.storage.StorageStats;
|
import com.cloud.storage.StorageStats;
|
||||||
import com.cloud.storage.VMTemplateHostVO;
|
import com.cloud.storage.VMTemplateHostVO;
|
||||||
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
||||||
import com.cloud.storage.VMTemplateVO;
|
import com.cloud.storage.VMTemplateVO;
|
||||||
import com.cloud.storage.Volume.VolumeType;
|
|
||||||
import com.cloud.storage.VolumeStats;
|
import com.cloud.storage.VolumeStats;
|
||||||
import com.cloud.storage.VolumeVO;
|
import com.cloud.storage.VolumeVO;
|
||||||
|
import com.cloud.storage.Snapshot.SnapshotType;
|
||||||
|
import com.cloud.storage.Storage.ImageFormat;
|
||||||
|
import com.cloud.storage.Volume.VolumeType;
|
||||||
import com.cloud.storage.dao.DiskOfferingDao;
|
import com.cloud.storage.dao.DiskOfferingDao;
|
||||||
import com.cloud.storage.dao.DiskTemplateDao;
|
import com.cloud.storage.dao.DiskTemplateDao;
|
||||||
import com.cloud.storage.dao.GuestOSCategoryDao;
|
import com.cloud.storage.dao.GuestOSCategoryDao;
|
||||||
@ -226,9 +216,9 @@ import com.cloud.storage.dao.SnapshotDao;
|
|||||||
import com.cloud.storage.dao.SnapshotPolicyDao;
|
import com.cloud.storage.dao.SnapshotPolicyDao;
|
||||||
import com.cloud.storage.dao.StoragePoolDao;
|
import com.cloud.storage.dao.StoragePoolDao;
|
||||||
import com.cloud.storage.dao.VMTemplateDao;
|
import com.cloud.storage.dao.VMTemplateDao;
|
||||||
import com.cloud.storage.dao.VMTemplateDao.TemplateFilter;
|
|
||||||
import com.cloud.storage.dao.VMTemplateHostDao;
|
import com.cloud.storage.dao.VMTemplateHostDao;
|
||||||
import com.cloud.storage.dao.VolumeDao;
|
import com.cloud.storage.dao.VolumeDao;
|
||||||
|
import com.cloud.storage.dao.VMTemplateDao.TemplateFilter;
|
||||||
import com.cloud.storage.preallocatedlun.PreallocatedLunVO;
|
import com.cloud.storage.preallocatedlun.PreallocatedLunVO;
|
||||||
import com.cloud.storage.preallocatedlun.dao.PreallocatedLunDao;
|
import com.cloud.storage.preallocatedlun.dao.PreallocatedLunDao;
|
||||||
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
||||||
@ -250,12 +240,12 @@ import com.cloud.user.dao.UserDao;
|
|||||||
import com.cloud.user.dao.UserStatisticsDao;
|
import com.cloud.user.dao.UserStatisticsDao;
|
||||||
import com.cloud.uservm.UserVm;
|
import com.cloud.uservm.UserVm;
|
||||||
import com.cloud.utils.DateUtil;
|
import com.cloud.utils.DateUtil;
|
||||||
import com.cloud.utils.DateUtil.IntervalType;
|
|
||||||
import com.cloud.utils.EnumUtils;
|
import com.cloud.utils.EnumUtils;
|
||||||
import com.cloud.utils.NumbersUtil;
|
import com.cloud.utils.NumbersUtil;
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
import com.cloud.utils.PasswordGenerator;
|
import com.cloud.utils.PasswordGenerator;
|
||||||
import com.cloud.utils.StringUtils;
|
import com.cloud.utils.StringUtils;
|
||||||
|
import com.cloud.utils.DateUtil.IntervalType;
|
||||||
import com.cloud.utils.component.Adapters;
|
import com.cloud.utils.component.Adapters;
|
||||||
import com.cloud.utils.component.ComponentLocator;
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import com.cloud.agent.api.VmStatsEntry;
|
import com.cloud.agent.api.VmStatsEntry;
|
||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.ServerApiException;
|
||||||
|
import com.cloud.api.commands.RecoverVMCmd;
|
||||||
import com.cloud.api.commands.ResetVMPasswordCmd;
|
import com.cloud.api.commands.ResetVMPasswordCmd;
|
||||||
import com.cloud.api.commands.StartVMCmd;
|
import com.cloud.api.commands.StartVMCmd;
|
||||||
import com.cloud.api.commands.StopVMCmd;
|
import com.cloud.api.commands.StopVMCmd;
|
||||||
@ -193,7 +194,7 @@ public interface UserVmManager extends Manager, VirtualMachineManager<UserVmVO>
|
|||||||
boolean rebootVirtualMachine(long userId, long vmId);
|
boolean rebootVirtualMachine(long userId, long vmId);
|
||||||
OperationResponse executeRebootVM(RebootVMExecutor executor, VMOperationParam param);
|
OperationResponse executeRebootVM(RebootVMExecutor executor, VMOperationParam param);
|
||||||
|
|
||||||
boolean recoverVirtualMachine(long vmId) throws ResourceAllocationException, InternalErrorException;
|
boolean recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException, InternalErrorException;
|
||||||
|
|
||||||
VMTemplateVO createPrivateTemplateRecord(Long userId, long vmId, String name, String description, long guestOsId, Boolean requiresHvm, Integer bits, Boolean passwordEnabled, boolean isPublic, boolean featured)
|
VMTemplateVO createPrivateTemplateRecord(Long userId, long vmId, String name, String description, long guestOsId, Boolean requiresHvm, Integer bits, Boolean passwordEnabled, boolean isPublic, boolean featured)
|
||||||
throws InvalidParameterValueException;
|
throws InvalidParameterValueException;
|
||||||
|
|||||||
@ -66,6 +66,7 @@ import com.cloud.agent.manager.AgentManager;
|
|||||||
import com.cloud.alert.AlertManager;
|
import com.cloud.alert.AlertManager;
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.ServerApiException;
|
||||||
|
import com.cloud.api.commands.RecoverVMCmd;
|
||||||
import com.cloud.api.commands.ResetVMPasswordCmd;
|
import com.cloud.api.commands.ResetVMPasswordCmd;
|
||||||
import com.cloud.api.commands.StartVMCmd;
|
import com.cloud.api.commands.StartVMCmd;
|
||||||
import com.cloud.api.commands.StopVMCmd;
|
import com.cloud.api.commands.StopVMCmd;
|
||||||
@ -242,7 +243,6 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
@Inject NetworkGroupManager _networkGroupManager;
|
@Inject NetworkGroupManager _networkGroupManager;
|
||||||
@Inject ServiceOfferingDao _serviceOfferingDao;
|
@Inject ServiceOfferingDao _serviceOfferingDao;
|
||||||
@Inject EventDao _eventDao = null;
|
@Inject EventDao _eventDao = null;
|
||||||
@Inject UserVmDao _userVmDao = null;
|
|
||||||
|
|
||||||
private IpAddrAllocator _IpAllocator;
|
private IpAddrAllocator _IpAllocator;
|
||||||
ScheduledExecutorService _executor = null;
|
ScheduledExecutorService _executor = null;
|
||||||
@ -278,7 +278,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
boolean result = resetVMPasswordInternal(cmd);
|
boolean result = resetVMPasswordInternal(cmd);
|
||||||
|
|
||||||
// Log event
|
// Log event
|
||||||
UserVmVO userVm = _userVmDao.findById(cmd.getId());
|
UserVmVO userVm = _vmDao.findById(cmd.getId());
|
||||||
if (userVm != null) {
|
if (userVm != null) {
|
||||||
if (result) {
|
if (result) {
|
||||||
EventUtils.saveEvent(userId, userVm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_RESETPASSWORD, "successfully reset password for VM : " + userVm.getName(), null);
|
EventUtils.saveEvent(userId, userVm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_RESETPASSWORD, "successfully reset password for VM : " + userVm.getName(), null);
|
||||||
@ -302,7 +302,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
String password = null;
|
String password = null;
|
||||||
|
|
||||||
//Verify input parameters
|
//Verify input parameters
|
||||||
UserVmVO vmInstance = _userVmDao.findById(id.longValue());
|
UserVmVO vmInstance = _vmDao.findById(id.longValue());
|
||||||
if (vmInstance == null) {
|
if (vmInstance == null) {
|
||||||
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + id);
|
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + id);
|
||||||
}
|
}
|
||||||
@ -1169,7 +1169,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
|
|
||||||
// Verify input parameters
|
// Verify input parameters
|
||||||
|
|
||||||
UserVmVO vmInstance = _userVmDao.createForUpdate(virtualMachineId.longValue());
|
UserVmVO vmInstance = _vmDao.createForUpdate(virtualMachineId.longValue());
|
||||||
if (vmInstance == null) {
|
if (vmInstance == null) {
|
||||||
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + virtualMachineId);
|
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + virtualMachineId);
|
||||||
}
|
}
|
||||||
@ -1866,10 +1866,28 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override @DB
|
@Override @DB
|
||||||
public boolean recoverVirtualMachine(long vmId) throws ResourceAllocationException, InternalErrorException {
|
public boolean recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException, InternalErrorException {
|
||||||
UserVmVO vm = _vmDao.findById(vmId);
|
|
||||||
|
Long vmId = cmd.getId();
|
||||||
|
Account accountHandle = (Account)UserContext.current().getAccountObject();
|
||||||
|
|
||||||
|
//if account is removed, return error
|
||||||
|
if(accountHandle!=null && accountHandle.getRemoved() != null)
|
||||||
|
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account " + accountHandle.getId()+" is removed");
|
||||||
|
|
||||||
|
// Verify input parameters
|
||||||
|
UserVmVO vm = _vmDao.findById(vmId.longValue());
|
||||||
|
|
||||||
if (vm == null || vm.getRemoved() != null) {
|
if (vm == null) {
|
||||||
|
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + vmId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((accountHandle != null) && !_domainDao.isChildDomain(accountHandle.getDomainId(), vm.getDomainId())) {
|
||||||
|
// the domain in which the VM lives is not in the admin's domain tree
|
||||||
|
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to recover virtual machine with id " + vmId + ", invalid id given.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vm.getRemoved() != null) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Unable to find vm or vm is removed: " + vmId);
|
s_logger.debug("Unable to find vm or vm is removed: " + vmId);
|
||||||
}
|
}
|
||||||
@ -3132,7 +3150,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
// Verify input parameters
|
// Verify input parameters
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
vmInstance = _userVmDao.findById(id.longValue());
|
vmInstance = _vmDao.findById(id.longValue());
|
||||||
}
|
}
|
||||||
catch (Exception ex1)
|
catch (Exception ex1)
|
||||||
{
|
{
|
||||||
@ -3160,13 +3178,13 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
long accountId = vmInstance.getAccountId();
|
long accountId = vmInstance.getAccountId();
|
||||||
|
|
||||||
|
|
||||||
UserVmVO vm = _userVmDao.findById(id);
|
UserVmVO vm = _vmDao.findById(id);
|
||||||
if (vm == null) {
|
if (vm == null) {
|
||||||
throw new CloudRuntimeException("Unable to find virual machine with id " + id);
|
throw new CloudRuntimeException("Unable to find virual machine with id " + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean haEnabled = vm.isHaEnabled();
|
boolean haEnabled = vm.isHaEnabled();
|
||||||
_userVmDao.updateVM(id, displayName, group, ha);
|
_vmDao.updateVM(id, displayName, group, ha);
|
||||||
if (haEnabled != ha) {
|
if (haEnabled != ha) {
|
||||||
String description = null;
|
String description = null;
|
||||||
String type = null;
|
String type = null;
|
||||||
@ -3197,7 +3215,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
if(account!=null && account.getRemoved() != null)
|
if(account!=null && account.getRemoved() != null)
|
||||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account " + account.getId()+" is removed");
|
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account " + account.getId()+" is removed");
|
||||||
|
|
||||||
UserVmVO vmInstance = _userVmDao.findById(id.longValue());
|
UserVmVO vmInstance = _vmDao.findById(id.longValue());
|
||||||
if (vmInstance == null) {
|
if (vmInstance == null) {
|
||||||
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + id);
|
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + id);
|
||||||
}
|
}
|
||||||
@ -3220,7 +3238,7 @@ public class UserVmManagerImpl implements UserVmManager {
|
|||||||
if(account!=null && account.getRemoved() != null)
|
if(account!=null && account.getRemoved() != null)
|
||||||
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account " + account.getId()+" is removed");
|
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "The account " + account.getId()+" is removed");
|
||||||
|
|
||||||
UserVmVO vmInstance = _userVmDao.findById(id.longValue());
|
UserVmVO vmInstance = _vmDao.findById(id.longValue());
|
||||||
if (vmInstance == null) {
|
if (vmInstance == null) {
|
||||||
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + id);
|
throw new ServerApiException(BaseCmd.VM_INVALID_PARAM_ERROR, "unable to find a virtual machine with id " + id);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user