mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Build responses in ApiResponseHelper for the deploy/start/stop/reboot/recover/listVm create/list snapshot/snapshotPolicies
This commit is contained in:
parent
410d423a5e
commit
694a8231ef
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.cloud.api;
|
package com.cloud.api;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -26,20 +27,34 @@ import com.cloud.api.response.DiskOfferingResponse;
|
|||||||
import com.cloud.api.response.DomainResponse;
|
import com.cloud.api.response.DomainResponse;
|
||||||
import com.cloud.api.response.ResourceLimitResponse;
|
import com.cloud.api.response.ResourceLimitResponse;
|
||||||
import com.cloud.api.response.ServiceOfferingResponse;
|
import com.cloud.api.response.ServiceOfferingResponse;
|
||||||
|
import com.cloud.api.response.SnapshotPolicyResponse;
|
||||||
|
import com.cloud.api.response.SnapshotResponse;
|
||||||
import com.cloud.api.response.UserResponse;
|
import com.cloud.api.response.UserResponse;
|
||||||
|
import com.cloud.api.response.UserVmResponse;
|
||||||
|
import com.cloud.async.AsyncJobVO;
|
||||||
import com.cloud.configuration.ConfigurationVO;
|
import com.cloud.configuration.ConfigurationVO;
|
||||||
import com.cloud.configuration.ResourceCount.ResourceType;
|
import com.cloud.configuration.ResourceCount.ResourceType;
|
||||||
import com.cloud.configuration.ResourceLimitVO;
|
import com.cloud.configuration.ResourceLimitVO;
|
||||||
import com.cloud.domain.DomainVO;
|
import com.cloud.domain.DomainVO;
|
||||||
import com.cloud.offering.NetworkOffering.GuestIpType;
|
import com.cloud.offering.NetworkOffering.GuestIpType;
|
||||||
|
import com.cloud.offering.ServiceOffering;
|
||||||
import com.cloud.server.Criteria;
|
import com.cloud.server.Criteria;
|
||||||
import com.cloud.service.ServiceOfferingVO;
|
import com.cloud.service.ServiceOfferingVO;
|
||||||
import com.cloud.storage.DiskOfferingVO;
|
import com.cloud.storage.DiskOfferingVO;
|
||||||
|
import com.cloud.storage.Snapshot;
|
||||||
|
import com.cloud.storage.Snapshot.SnapshotType;
|
||||||
|
import com.cloud.storage.SnapshotPolicyVO;
|
||||||
|
import com.cloud.storage.StoragePoolVO;
|
||||||
|
import com.cloud.storage.VMTemplateVO;
|
||||||
|
import com.cloud.storage.VolumeVO;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.user.UserAccount;
|
import com.cloud.user.UserAccount;
|
||||||
|
import com.cloud.user.UserContext;
|
||||||
import com.cloud.user.UserStatisticsVO;
|
import com.cloud.user.UserStatisticsVO;
|
||||||
import com.cloud.uservm.UserVm;
|
import com.cloud.uservm.UserVm;
|
||||||
|
import com.cloud.vm.InstanceGroupVO;
|
||||||
import com.cloud.vm.State;
|
import com.cloud.vm.State;
|
||||||
|
import com.cloud.vm.VmStats;
|
||||||
|
|
||||||
public class ApiResponseHelper {
|
public class ApiResponseHelper {
|
||||||
|
|
||||||
@ -239,5 +254,160 @@ public class ApiResponseHelper {
|
|||||||
return cfgResponse;
|
return cfgResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SnapshotResponse createSnapshotResponse (Snapshot snapshot) {
|
||||||
|
SnapshotResponse snapshotResponse = new SnapshotResponse();
|
||||||
|
snapshotResponse.setId(snapshot.getId());
|
||||||
|
|
||||||
|
Account acct = ApiDBUtils.findAccountById(Long.valueOf(snapshot.getAccountId()));
|
||||||
|
if (acct != null) {
|
||||||
|
snapshotResponse.setAccountName(acct.getAccountName());
|
||||||
|
snapshotResponse.setDomainId(acct.getDomainId());
|
||||||
|
snapshotResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
VolumeVO volume = ApiDBUtils.findVolumeById(snapshot.getVolumeId());
|
||||||
|
String snapshotTypeStr = SnapshotType.values()[snapshot.getSnapshotType()].name();
|
||||||
|
snapshotResponse.setSnapshotType(snapshotTypeStr);
|
||||||
|
snapshotResponse.setVolumeId(snapshot.getVolumeId());
|
||||||
|
snapshotResponse.setVolumeName(volume.getName());
|
||||||
|
snapshotResponse.setVolumeType(volume.getVolumeType().name());
|
||||||
|
snapshotResponse.setCreated(snapshot.getCreated());
|
||||||
|
snapshotResponse.setName(snapshot.getName());
|
||||||
|
snapshotResponse.setIntervalType(ApiDBUtils.getSnapshotIntervalTypes(snapshot.getId()));
|
||||||
|
AsyncJobVO asyncJob = ApiDBUtils.findInstancePendingAsyncJob("snapshot", snapshot.getId());
|
||||||
|
if (asyncJob != null) {
|
||||||
|
snapshotResponse.setJobId(asyncJob.getId());
|
||||||
|
snapshotResponse.setJobStatus(asyncJob.getStatus());
|
||||||
|
}
|
||||||
|
return snapshotResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static SnapshotPolicyResponse createSnapshotPolicyResponse (SnapshotPolicyVO policy) {
|
||||||
|
SnapshotPolicyResponse policyResponse = new SnapshotPolicyResponse();
|
||||||
|
policyResponse.setId(policy.getId());
|
||||||
|
policyResponse.setVolumeId(policy.getVolumeId());
|
||||||
|
policyResponse.setSchedule(policy.getSchedule());
|
||||||
|
policyResponse.setIntervalType(policy.getInterval());
|
||||||
|
policyResponse.setMaxSnaps(policy.getMaxSnaps());
|
||||||
|
policyResponse.setTimezone(policy.getTimezone());
|
||||||
|
|
||||||
|
return policyResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UserVmResponse createUserVmResponse (UserVm userVm) {
|
||||||
|
UserVmResponse userVmResponse = new UserVmResponse();
|
||||||
|
|
||||||
|
Account acct = ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId()));
|
||||||
|
//FIXME - this check should be done in searchForUserVm method in ManagementServerImpl;
|
||||||
|
//otherwise the number of vms returned is not going to match pageSize request parameter
|
||||||
|
if ((acct != null) && (acct.getRemoved() == null)) {
|
||||||
|
userVmResponse.setAccountName(acct.getAccountName());
|
||||||
|
userVmResponse.setDomainId(acct.getDomainId());
|
||||||
|
userVmResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
|
||||||
|
} else {
|
||||||
|
return null; // the account has been deleted, skip this VM in the response
|
||||||
|
}
|
||||||
|
|
||||||
|
userVmResponse.setId(userVm.getId());
|
||||||
|
AsyncJobVO asyncJob = ApiDBUtils.findInstancePendingAsyncJob("vm_instance", userVm.getId());
|
||||||
|
if (asyncJob != null) {
|
||||||
|
userVmResponse.setJobId(asyncJob.getId());
|
||||||
|
userVmResponse.setJobStatus(asyncJob.getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
userVmResponse.setName(userVm.getName());
|
||||||
|
userVmResponse.setCreated(userVm.getCreated());
|
||||||
|
userVmResponse.setIpAddress(userVm.getPrivateIpAddress());
|
||||||
|
if (userVm.getState() != null) {
|
||||||
|
userVmResponse.setState(userVm.getState().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
userVmResponse.setHaEnable(userVm.isHaEnabled());
|
||||||
|
|
||||||
|
if (userVm.getDisplayName() != null) {
|
||||||
|
userVmResponse.setDisplayName(userVm.getDisplayName());
|
||||||
|
} else {
|
||||||
|
userVmResponse.setDisplayName(userVm.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(userVm.getId());
|
||||||
|
if (group != null) {
|
||||||
|
userVmResponse.setGroup(group.getName());
|
||||||
|
userVmResponse.setGroupId(group.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Data Center Info
|
||||||
|
userVmResponse.setZoneId(userVm.getDataCenterId());
|
||||||
|
userVmResponse.setZoneName(ApiDBUtils.findZoneById(userVm.getDataCenterId()).getName());
|
||||||
|
|
||||||
|
Account account = (Account)UserContext.current().getAccount();
|
||||||
|
//if user is an admin, display host id
|
||||||
|
if (((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) && (userVm.getHostId() != null)) {
|
||||||
|
userVmResponse.setHostId(userVm.getHostId());
|
||||||
|
userVmResponse.setHostName(ApiDBUtils.findHostById(userVm.getHostId()).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Template Info
|
||||||
|
VMTemplateVO template = ApiDBUtils.findTemplateById(userVm.getTemplateId());
|
||||||
|
if (template != null) {
|
||||||
|
userVmResponse.setTemplateId(userVm.getTemplateId());
|
||||||
|
userVmResponse.setTemplateName(template.getName());
|
||||||
|
userVmResponse.setTemplateDisplayText(template.getDisplayText());
|
||||||
|
userVmResponse.setPasswordEnabled(template.getEnablePassword());
|
||||||
|
} else {
|
||||||
|
userVmResponse.setTemplateId(-1L);
|
||||||
|
userVmResponse.setTemplateName("ISO Boot");
|
||||||
|
userVmResponse.setTemplateDisplayText("ISO Boot");
|
||||||
|
userVmResponse.setPasswordEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ISO Info
|
||||||
|
if (userVm.getIsoId() != null) {
|
||||||
|
VMTemplateVO iso = ApiDBUtils.findTemplateById(userVm.getIsoId().longValue());
|
||||||
|
if (iso != null) {
|
||||||
|
userVmResponse.setIsoId(userVm.getIsoId());
|
||||||
|
userVmResponse.setIsoName(iso.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Service Offering Info
|
||||||
|
ServiceOffering offering = ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId());
|
||||||
|
userVmResponse.setServiceOfferingId(userVm.getServiceOfferingId());
|
||||||
|
userVmResponse.setServiceOfferingName(offering.getName());
|
||||||
|
userVmResponse.setCpuNumber(offering.getCpu());
|
||||||
|
userVmResponse.setCpuSpeed(offering.getSpeed());
|
||||||
|
userVmResponse.setMemory(offering.getRamSize());
|
||||||
|
|
||||||
|
VolumeVO rootVolume = ApiDBUtils.findRootVolume(userVm.getId());
|
||||||
|
if (rootVolume != null) {
|
||||||
|
userVmResponse.setRootDeviceId(rootVolume.getDeviceId());
|
||||||
|
StoragePoolVO storagePool = ApiDBUtils.findStoragePoolById(rootVolume.getPoolId());
|
||||||
|
userVmResponse.setRootDeviceType(storagePool.getPoolType().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
//stats calculation
|
||||||
|
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||||
|
String cpuUsed = null;
|
||||||
|
VmStats vmStats = ApiDBUtils.getVmStatistics(userVm.getId());
|
||||||
|
if (vmStats != null) {
|
||||||
|
float cpuUtil = (float) vmStats.getCPUUtilization();
|
||||||
|
cpuUsed = decimalFormat.format(cpuUtil) + "%";
|
||||||
|
userVmResponse.setCpuUsed(cpuUsed);
|
||||||
|
|
||||||
|
long networkKbRead = (long)vmStats.getNetworkReadKBs();
|
||||||
|
userVmResponse.setNetworkKbsRead(networkKbRead);
|
||||||
|
|
||||||
|
long networkKbWrite = (long)vmStats.getNetworkWriteKBs();
|
||||||
|
userVmResponse.setNetworkKbsWrite(networkKbWrite);
|
||||||
|
}
|
||||||
|
|
||||||
|
userVmResponse.setGuestOsId(userVm.getGuestOSId());
|
||||||
|
//network groups
|
||||||
|
userVmResponse.setNetworkGroupList(ApiDBUtils.getNetworkGroupsNamesForVm(userVm.getId()));
|
||||||
|
|
||||||
|
return userVmResponse;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import org.apache.log4j.Logger;
|
|||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
import com.cloud.api.ApiDBUtils;
|
import com.cloud.api.ApiDBUtils;
|
||||||
|
import com.cloud.api.ApiResponseHelper;
|
||||||
import com.cloud.api.BaseAsyncCreateCmd;
|
import com.cloud.api.BaseAsyncCreateCmd;
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
@ -29,7 +30,6 @@ import com.cloud.api.Parameter;
|
|||||||
import com.cloud.api.ServerApiException;
|
import com.cloud.api.ServerApiException;
|
||||||
import com.cloud.api.response.SnapshotResponse;
|
import com.cloud.api.response.SnapshotResponse;
|
||||||
import com.cloud.event.EventTypes;
|
import com.cloud.event.EventTypes;
|
||||||
import com.cloud.storage.Snapshot.SnapshotType;
|
|
||||||
import com.cloud.storage.SnapshotVO;
|
import com.cloud.storage.SnapshotVO;
|
||||||
import com.cloud.storage.VolumeVO;
|
import com.cloud.storage.VolumeVO;
|
||||||
import com.cloud.storage.snapshot.SnapshotManager;
|
import com.cloud.storage.snapshot.SnapshotManager;
|
||||||
@ -108,25 +108,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
|
|||||||
SnapshotVO snapshot = (SnapshotVO)getResponseObject();
|
SnapshotVO snapshot = (SnapshotVO)getResponseObject();
|
||||||
|
|
||||||
if (snapshot != null) {
|
if (snapshot != null) {
|
||||||
SnapshotResponse response = new SnapshotResponse();
|
SnapshotResponse response = ApiResponseHelper.createSnapshotResponse(snapshot);
|
||||||
response.setId(snapshot.getId());
|
|
||||||
|
|
||||||
Account account = ApiDBUtils.findAccountById(snapshot.getAccountId());
|
|
||||||
if (account != null) {
|
|
||||||
response.setAccountName(account.getAccountName());
|
|
||||||
response.setDomainId(account.getDomainId());
|
|
||||||
response.setDomainName(ApiDBUtils.findDomainById(account.getDomainId()).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
VolumeVO volume = ApiDBUtils.findVolumeById(snapshot.getVolumeId());
|
|
||||||
String snapshotTypeStr = SnapshotType.values()[snapshot.getSnapshotType()].name();
|
|
||||||
response.setSnapshotType(snapshotTypeStr);
|
|
||||||
response.setVolumeId(snapshot.getVolumeId());
|
|
||||||
response.setVolumeName(volume.getName());
|
|
||||||
response.setVolumeType(volume.getVolumeType().toString());
|
|
||||||
response.setCreated(snapshot.getCreated());
|
|
||||||
response.setName(snapshot.getName());
|
|
||||||
|
|
||||||
response.setResponseName(getName());
|
response.setResponseName(getName());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@ package com.cloud.api.commands;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
|
import com.cloud.api.ApiResponseHelper;
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
@ -110,14 +111,7 @@ public class CreateSnapshotPolicyCmd extends BaseCmd {
|
|||||||
@Override @SuppressWarnings("unchecked")
|
@Override @SuppressWarnings("unchecked")
|
||||||
public SnapshotPolicyResponse getResponse() {
|
public SnapshotPolicyResponse getResponse() {
|
||||||
SnapshotPolicyVO snapshotPolicy = (SnapshotPolicyVO)getResponseObject();
|
SnapshotPolicyVO snapshotPolicy = (SnapshotPolicyVO)getResponseObject();
|
||||||
|
SnapshotPolicyResponse response = ApiResponseHelper.createSnapshotPolicyResponse(snapshotPolicy);
|
||||||
SnapshotPolicyResponse response = new SnapshotPolicyResponse();
|
|
||||||
response.setId(snapshotPolicy.getId());
|
|
||||||
response.setIntervalType(snapshotPolicy.getInterval());
|
|
||||||
response.setMaxSnaps(snapshotPolicy.getMaxSnaps());
|
|
||||||
response.setSchedule(snapshotPolicy.getSchedule());
|
|
||||||
response.setVolumeId(snapshotPolicy.getVolumeId());
|
|
||||||
|
|
||||||
response.setResponseName(getName());
|
response.setResponseName(getName());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,21 +24,15 @@ import org.apache.log4j.Logger;
|
|||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
import com.cloud.api.ApiDBUtils;
|
import com.cloud.api.ApiDBUtils;
|
||||||
|
import com.cloud.api.ApiResponseHelper;
|
||||||
import com.cloud.api.BaseAsyncCmd;
|
import com.cloud.api.BaseAsyncCmd;
|
||||||
import com.cloud.api.BaseCmd;
|
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.response.UserVmResponse;
|
import com.cloud.api.response.UserVmResponse;
|
||||||
import com.cloud.event.EventTypes;
|
import com.cloud.event.EventTypes;
|
||||||
import com.cloud.offering.ServiceOffering;
|
|
||||||
import com.cloud.storage.StoragePoolVO;
|
|
||||||
import com.cloud.storage.VMTemplateVO;
|
|
||||||
import com.cloud.storage.VolumeVO;
|
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.user.User;
|
|
||||||
import com.cloud.user.UserContext;
|
import com.cloud.user.UserContext;
|
||||||
import com.cloud.uservm.UserVm;
|
import com.cloud.uservm.UserVm;
|
||||||
import com.cloud.vm.InstanceGroupVO;
|
|
||||||
|
|
||||||
@Implementation(method="deployVirtualMachine", description="Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.")
|
@Implementation(method="deployVirtualMachine", description="Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.")
|
||||||
public class DeployVMCmd extends BaseAsyncCmd {
|
public class DeployVMCmd extends BaseAsyncCmd {
|
||||||
@ -196,114 +190,12 @@ public class DeployVMCmd extends BaseAsyncCmd {
|
|||||||
@Override @SuppressWarnings("unchecked")
|
@Override @SuppressWarnings("unchecked")
|
||||||
public UserVmResponse getResponse() {
|
public UserVmResponse getResponse() {
|
||||||
UserVm userVm = (UserVm)getResponseObject();
|
UserVm userVm = (UserVm)getResponseObject();
|
||||||
|
UserVmResponse response = ApiResponseHelper.createUserVmResponse(userVm);
|
||||||
UserVmResponse response = new UserVmResponse();
|
|
||||||
response.setId(userVm.getId());
|
|
||||||
response.setName(userVm.getName());
|
|
||||||
response.setCreated(userVm.getCreated());
|
|
||||||
response.setZoneId(userVm.getDataCenterId());
|
|
||||||
response.setZoneName(ApiDBUtils.findZoneById(userVm.getDataCenterId()).getName());
|
|
||||||
response.setIpAddress(userVm.getPrivateIpAddress());
|
|
||||||
response.setServiceOfferingId(userVm.getServiceOfferingId());
|
|
||||||
response.setHaEnable(userVm.isHaEnabled());
|
|
||||||
|
|
||||||
InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(userVm.getId());
|
|
||||||
if (group != null) {
|
|
||||||
response.setGroup(group.getName());
|
|
||||||
response.setGroupId(group.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userVm.getDisplayName() == null || userVm.getDisplayName().length() == 0) {
|
|
||||||
response.setDisplayName(userVm.getName());
|
|
||||||
} else {
|
|
||||||
response.setDisplayName(userVm.getDisplayName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userVm.getState() != null) {
|
// FIXME: where will the password come from in this case?
|
||||||
response.setState(userVm.getState().toString());
|
// if (templatePasswordEnabled) {
|
||||||
}
|
// response.setPassword(getPassword());
|
||||||
|
// }
|
||||||
VMTemplateVO template = ApiDBUtils.findTemplateById(userVm.getTemplateId());
|
|
||||||
|
|
||||||
Account acct = ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId()));
|
|
||||||
if (acct != null) {
|
|
||||||
response.setAccountName(acct.getAccountName());
|
|
||||||
response.setDomainId(acct.getDomainId());
|
|
||||||
response.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
Long userId = UserContext.current().getUserId();
|
|
||||||
if (userId == null) {
|
|
||||||
userId = User.UID_SYSTEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
//this is for the case where the admin deploys a vm for a normal user
|
|
||||||
User userExecutingCmd = ApiDBUtils.findUserById(userId);
|
|
||||||
Account acctForUserExecutingCmd = ApiDBUtils.findAccountById(Long.valueOf(userExecutingCmd.getAccountId()));
|
|
||||||
if ((BaseCmd.isAdmin(acctForUserExecutingCmd.getType()) && (userVm.getHostId() != null)) || (BaseCmd.isAdmin(acct.getType()) && (userVm.getHostId() != null))) {
|
|
||||||
response.setHostName(ApiDBUtils.findHostById(userVm.getHostId()).getName());
|
|
||||||
response.setHostId(userVm.getHostId());
|
|
||||||
}
|
|
||||||
|
|
||||||
String templateName = "none";
|
|
||||||
boolean templatePasswordEnabled = false;
|
|
||||||
String templateDisplayText = null;
|
|
||||||
|
|
||||||
if (template != null) {
|
|
||||||
templateName = template.getName();
|
|
||||||
templatePasswordEnabled = template.getEnablePassword();
|
|
||||||
templateDisplayText = template.getDisplayText();
|
|
||||||
if (templateDisplayText == null) {
|
|
||||||
templateDisplayText = templateName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (templatePasswordEnabled) { // FIXME: where will the password come from in this case?
|
|
||||||
response.setPassword(getPassword());
|
|
||||||
}
|
|
||||||
|
|
||||||
// ISO Info
|
|
||||||
Long isoId = userVm.getIsoId();
|
|
||||||
if (isoId != null) {
|
|
||||||
VMTemplateVO iso = ApiDBUtils.findTemplateById(isoId.longValue());
|
|
||||||
if (iso != null) {
|
|
||||||
response.setIsoId(isoId.longValue());
|
|
||||||
response.setIsoName(iso.getName());
|
|
||||||
response.setTemplateId(isoId.longValue());
|
|
||||||
response.setTemplateName(iso.getName());
|
|
||||||
|
|
||||||
templateDisplayText = iso.getDisplayText();
|
|
||||||
if(templateDisplayText == null)
|
|
||||||
templateDisplayText = iso.getName();
|
|
||||||
response.setIsoDisplayText(templateDisplayText);
|
|
||||||
response.setTemplateDisplayText(templateDisplayText);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
response.setTemplateId(userVm.getTemplateId());
|
|
||||||
response.setTemplateName(templateName);
|
|
||||||
response.setTemplateDisplayText(templateDisplayText);
|
|
||||||
response.setPasswordEnabled(templatePasswordEnabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
ServiceOffering offering = ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId());
|
|
||||||
response.setServiceOfferingId(userVm.getServiceOfferingId());
|
|
||||||
response.setServiceOfferingName(offering.getName());
|
|
||||||
|
|
||||||
response.setCpuNumber(offering.getCpu());
|
|
||||||
response.setCpuSpeed(offering.getSpeed());
|
|
||||||
response.setMemory(offering.getRamSize());
|
|
||||||
|
|
||||||
VolumeVO rootVolume = ApiDBUtils.findRootVolume(userVm.getId());
|
|
||||||
if (rootVolume != null) {
|
|
||||||
response.setRootDeviceId(rootVolume.getDeviceId());
|
|
||||||
StoragePoolVO storagePool = ApiDBUtils.findStoragePoolById(rootVolume.getPoolId());
|
|
||||||
response.setRootDeviceType(storagePool.getPoolType().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setGuestOsId(userVm.getGuestOSId());
|
|
||||||
|
|
||||||
response.setNetworkGroupList(ApiDBUtils.getNetworkGroupsNamesForVm(userVm.getId()));
|
|
||||||
|
|
||||||
response.setResponseName(getName());
|
response.setResponseName(getName());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,17 +21,14 @@ import org.apache.log4j.Logger;
|
|||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
import com.cloud.api.ApiDBUtils;
|
import com.cloud.api.ApiDBUtils;
|
||||||
|
import com.cloud.api.ApiResponseHelper;
|
||||||
import com.cloud.api.BaseAsyncCmd;
|
import com.cloud.api.BaseAsyncCmd;
|
||||||
import com.cloud.api.BaseCmd;
|
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.response.UserVmResponse;
|
import com.cloud.api.response.UserVmResponse;
|
||||||
import com.cloud.event.EventTypes;
|
import com.cloud.event.EventTypes;
|
||||||
import com.cloud.offering.ServiceOffering;
|
|
||||||
import com.cloud.storage.VMTemplateVO;
|
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.uservm.UserVm;
|
import com.cloud.uservm.UserVm;
|
||||||
import com.cloud.vm.InstanceGroupVO;
|
|
||||||
import com.cloud.vm.UserVmManager;
|
import com.cloud.vm.UserVmManager;
|
||||||
|
|
||||||
@Implementation(method="destroyVm", manager=UserVmManager.class, description="Destroys a virtual machine. Once destroyed, only the administrator can recover it.")
|
@Implementation(method="destroyVm", manager=UserVmManager.class, description="Destroys a virtual machine. Once destroyed, only the administrator can recover it.")
|
||||||
@ -86,94 +83,8 @@ public class DestroyVMCmd extends BaseAsyncCmd {
|
|||||||
|
|
||||||
@Override @SuppressWarnings("unchecked")
|
@Override @SuppressWarnings("unchecked")
|
||||||
public UserVmResponse getResponse() {
|
public UserVmResponse getResponse() {
|
||||||
Boolean success = (Boolean)getResponseObject();
|
UserVm userVm = (UserVm)getResponseObject();
|
||||||
UserVmResponse recoverVmResponse = new UserVmResponse();
|
UserVmResponse recoverVmResponse = ApiResponseHelper.createUserVmResponse(userVm);
|
||||||
UserVm vm = ApiDBUtils.findUserVmById(id);
|
|
||||||
recoverVmResponse.setSuccess(success);
|
|
||||||
recoverVmResponse.setResponseName(getName());
|
|
||||||
recoverVmResponse.setId(vm.getId());
|
|
||||||
recoverVmResponse.setName(vm.getName());
|
|
||||||
recoverVmResponse.setCreated(vm.getCreated());
|
|
||||||
recoverVmResponse.setZoneId(vm.getDataCenterId());
|
|
||||||
recoverVmResponse.setZoneName(ApiDBUtils.findZoneById(vm.getDataCenterId()).getName());
|
|
||||||
recoverVmResponse.setIpAddress(vm.getPrivateIpAddress());
|
|
||||||
recoverVmResponse.setServiceOfferingId(vm.getServiceOfferingId());
|
|
||||||
recoverVmResponse.setHaEnable(vm.isHaEnabled());
|
|
||||||
if (vm.getDisplayName() == null || vm.getDisplayName().length() == 0) {
|
|
||||||
recoverVmResponse.setDisplayName(vm.getName());
|
|
||||||
} else {
|
|
||||||
recoverVmResponse.setDisplayName(vm.getDisplayName());
|
|
||||||
}
|
|
||||||
|
|
||||||
InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(vm.getId());
|
|
||||||
if (group != null) {
|
|
||||||
recoverVmResponse.setGroup(group.getName());
|
|
||||||
recoverVmResponse.setGroupId(group.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vm.getState() != null) {
|
|
||||||
recoverVmResponse.setState(vm.getState().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
Account acct = ApiDBUtils.findAccountById(vm.getAccountId());
|
|
||||||
if (acct != null) {
|
|
||||||
recoverVmResponse.setAccountName(acct.getAccountName());
|
|
||||||
recoverVmResponse.setDomainId(acct.getDomainId());
|
|
||||||
recoverVmResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BaseCmd.isAdmin(acct.getType()) && (vm.getHostId() != null)) {
|
|
||||||
recoverVmResponse.setHostName(ApiDBUtils.findHostById(vm.getHostId()).getName());
|
|
||||||
recoverVmResponse.setHostId(vm.getHostId());
|
|
||||||
}
|
|
||||||
|
|
||||||
String templateName = "ISO Boot";
|
|
||||||
boolean templatePasswordEnabled = false;
|
|
||||||
String templateDisplayText = "ISO Boot";
|
|
||||||
|
|
||||||
VMTemplateVO template = ApiDBUtils.findTemplateById(vm.getTemplateId());
|
|
||||||
if (template != null) {
|
|
||||||
templateName = template.getName();
|
|
||||||
templatePasswordEnabled = template.getEnablePassword();
|
|
||||||
templateDisplayText = template.getDisplayText();
|
|
||||||
if (templateDisplayText == null) {
|
|
||||||
templateDisplayText = templateName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
recoverVmResponse.setTemplateId(vm.getTemplateId());
|
|
||||||
recoverVmResponse.setTemplateName(templateName);
|
|
||||||
recoverVmResponse.setTemplateDisplayText(templateDisplayText);
|
|
||||||
recoverVmResponse.setPasswordEnabled(templatePasswordEnabled);
|
|
||||||
if (templatePasswordEnabled) {
|
|
||||||
recoverVmResponse.setPassword(null); // FIXME: Where should password come from? In the old framework, password was always passed
|
|
||||||
// in to composeResultObject() as null, so that behavior is preserved...
|
|
||||||
} else {
|
|
||||||
recoverVmResponse.setPassword("");
|
|
||||||
}
|
|
||||||
|
|
||||||
String isoName = null;
|
|
||||||
if (vm.getIsoId() != null) {
|
|
||||||
VMTemplateVO iso = ApiDBUtils.findTemplateById(vm.getIsoId().longValue());
|
|
||||||
if (iso != null) {
|
|
||||||
isoName = iso.getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
recoverVmResponse.setIsoId(vm.getIsoId());
|
|
||||||
recoverVmResponse.setIsoName(isoName);
|
|
||||||
|
|
||||||
ServiceOffering offering = ApiDBUtils.findServiceOfferingById(vm.getServiceOfferingId());
|
|
||||||
recoverVmResponse.setServiceOfferingId(vm.getServiceOfferingId());
|
|
||||||
recoverVmResponse.setServiceOfferingName(offering.getName());
|
|
||||||
|
|
||||||
recoverVmResponse.setCpuNumber(offering.getCpu());
|
|
||||||
recoverVmResponse.setCpuSpeed(offering.getSpeed());
|
|
||||||
recoverVmResponse.setMemory(offering.getRamSize());
|
|
||||||
|
|
||||||
//Network groups
|
|
||||||
recoverVmResponse.setNetworkGroupList(ApiDBUtils.getNetworkGroupsNamesForVm(vm.getId()));
|
|
||||||
|
|
||||||
recoverVmResponse.setResponseName(getName());
|
recoverVmResponse.setResponseName(getName());
|
||||||
return recoverVmResponse;
|
return recoverVmResponse;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import java.util.List;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
|
import com.cloud.api.ApiResponseHelper;
|
||||||
import com.cloud.api.BaseListCmd;
|
import com.cloud.api.BaseListCmd;
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
@ -83,14 +84,7 @@ public class ListSnapshotPoliciesCmd extends BaseListCmd {
|
|||||||
ListResponse<SnapshotPolicyResponse> response = new ListResponse<SnapshotPolicyResponse>();
|
ListResponse<SnapshotPolicyResponse> response = new ListResponse<SnapshotPolicyResponse>();
|
||||||
List<SnapshotPolicyResponse> policyResponses = new ArrayList<SnapshotPolicyResponse>();
|
List<SnapshotPolicyResponse> policyResponses = new ArrayList<SnapshotPolicyResponse>();
|
||||||
for (SnapshotPolicyVO policy : policies) {
|
for (SnapshotPolicyVO policy : policies) {
|
||||||
SnapshotPolicyResponse policyResponse = new SnapshotPolicyResponse();
|
SnapshotPolicyResponse policyResponse = ApiResponseHelper.createSnapshotPolicyResponse(policy);
|
||||||
policyResponse.setId(policy.getId());
|
|
||||||
policyResponse.setVolumeId(policy.getVolumeId());
|
|
||||||
policyResponse.setSchedule(policy.getSchedule());
|
|
||||||
policyResponse.setIntervalType(policy.getInterval());
|
|
||||||
policyResponse.setMaxSnaps(policy.getMaxSnaps());
|
|
||||||
policyResponse.setTimezone(policy.getTimezone());
|
|
||||||
|
|
||||||
policyResponse.setResponseName("snapshotpolicy");
|
policyResponse.setResponseName("snapshotpolicy");
|
||||||
policyResponses.add(policyResponse);
|
policyResponses.add(policyResponse);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,18 +23,14 @@ import java.util.List;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
import com.cloud.api.ApiDBUtils;
|
import com.cloud.api.ApiResponseHelper;
|
||||||
import com.cloud.api.BaseListCmd;
|
import com.cloud.api.BaseListCmd;
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.response.ListResponse;
|
import com.cloud.api.response.ListResponse;
|
||||||
import com.cloud.api.response.SnapshotResponse;
|
import com.cloud.api.response.SnapshotResponse;
|
||||||
import com.cloud.async.AsyncJobVO;
|
|
||||||
import com.cloud.storage.Snapshot;
|
import com.cloud.storage.Snapshot;
|
||||||
import com.cloud.storage.Snapshot.SnapshotType;
|
|
||||||
import com.cloud.storage.SnapshotVO;
|
import com.cloud.storage.SnapshotVO;
|
||||||
import com.cloud.storage.VolumeVO;
|
|
||||||
import com.cloud.user.Account;
|
|
||||||
|
|
||||||
@Implementation(method="listSnapshots", description="Lists all available snapshots for the account.")
|
@Implementation(method="listSnapshots", description="Lists all available snapshots for the account.")
|
||||||
public class ListSnapshotsCmd extends BaseListCmd {
|
public class ListSnapshotsCmd extends BaseListCmd {
|
||||||
@ -115,32 +111,7 @@ public class ListSnapshotsCmd extends BaseListCmd {
|
|||||||
ListResponse<SnapshotResponse> response = new ListResponse<SnapshotResponse>();
|
ListResponse<SnapshotResponse> response = new ListResponse<SnapshotResponse>();
|
||||||
List<SnapshotResponse> snapshotResponses = new ArrayList<SnapshotResponse>();
|
List<SnapshotResponse> snapshotResponses = new ArrayList<SnapshotResponse>();
|
||||||
for (Snapshot snapshot : snapshots) {
|
for (Snapshot snapshot : snapshots) {
|
||||||
SnapshotResponse snapshotResponse = new SnapshotResponse();
|
SnapshotResponse snapshotResponse = ApiResponseHelper.createSnapshotResponse(snapshot);
|
||||||
snapshotResponse.setId(snapshot.getId());
|
|
||||||
|
|
||||||
Account acct = ApiDBUtils.findAccountById(Long.valueOf(snapshot.getAccountId()));
|
|
||||||
if (acct != null) {
|
|
||||||
snapshotResponse.setAccountName(acct.getAccountName());
|
|
||||||
snapshotResponse.setDomainId(acct.getDomainId());
|
|
||||||
snapshotResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
VolumeVO volume = ApiDBUtils.findVolumeById(snapshot.getVolumeId());
|
|
||||||
String snapshotTypeStr = SnapshotType.values()[snapshot.getSnapshotType()].name();
|
|
||||||
snapshotResponse.setSnapshotType(snapshotTypeStr);
|
|
||||||
snapshotResponse.setVolumeId(snapshot.getVolumeId());
|
|
||||||
snapshotResponse.setVolumeName(volume.getName());
|
|
||||||
snapshotResponse.setVolumeType(volume.getVolumeType().name());
|
|
||||||
snapshotResponse.setCreated(snapshot.getCreated());
|
|
||||||
snapshotResponse.setName(snapshot.getName());
|
|
||||||
|
|
||||||
AsyncJobVO asyncJob = ApiDBUtils.findInstancePendingAsyncJob("snapshot", snapshot.getId());
|
|
||||||
if (asyncJob != null) {
|
|
||||||
snapshotResponse.setJobId(asyncJob.getId());
|
|
||||||
snapshotResponse.setJobStatus(asyncJob.getStatus());
|
|
||||||
}
|
|
||||||
snapshotResponse.setIntervalType(ApiDBUtils.getSnapshotIntervalTypes(snapshot.getId()));
|
|
||||||
|
|
||||||
snapshotResponse.setResponseName("snapshot");
|
snapshotResponse.setResponseName("snapshot");
|
||||||
snapshotResponses.add(snapshotResponse);
|
snapshotResponses.add(snapshotResponse);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,29 +17,19 @@
|
|||||||
*/
|
*/
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
import com.cloud.api.ApiDBUtils;
|
import com.cloud.api.ApiResponseHelper;
|
||||||
import com.cloud.api.BaseListCmd;
|
import com.cloud.api.BaseListCmd;
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.response.ListResponse;
|
import com.cloud.api.response.ListResponse;
|
||||||
import com.cloud.api.response.UserVmResponse;
|
import com.cloud.api.response.UserVmResponse;
|
||||||
import com.cloud.async.AsyncJobVO;
|
import com.cloud.uservm.UserVm;
|
||||||
import com.cloud.offering.ServiceOffering;
|
|
||||||
import com.cloud.storage.StoragePoolVO;
|
|
||||||
import com.cloud.storage.VMTemplateVO;
|
|
||||||
import com.cloud.storage.VolumeVO;
|
|
||||||
import com.cloud.user.Account;
|
|
||||||
import com.cloud.user.UserContext;
|
|
||||||
import com.cloud.vm.InstanceGroupVO;
|
|
||||||
import com.cloud.vm.UserVmVO;
|
|
||||||
import com.cloud.vm.VmStats;
|
|
||||||
|
|
||||||
@Implementation(method="searchForUserVMs", description="List the virtual machines owned by the account.")
|
@Implementation(method="searchForUserVMs", description="List the virtual machines owned by the account.")
|
||||||
public class ListVMsCmd extends BaseListCmd {
|
public class ListVMsCmd extends BaseListCmd {
|
||||||
@ -129,125 +119,17 @@ public class ListVMsCmd extends BaseListCmd {
|
|||||||
|
|
||||||
@Override @SuppressWarnings("unchecked")
|
@Override @SuppressWarnings("unchecked")
|
||||||
public ListResponse<UserVmResponse> getResponse() {
|
public ListResponse<UserVmResponse> getResponse() {
|
||||||
List<UserVmVO> userVms = (List<UserVmVO>)getResponseObject();
|
List<UserVm> userVms = (List<UserVm>)getResponseObject();
|
||||||
|
|
||||||
ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
|
ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
|
||||||
List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
|
List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
|
||||||
for (UserVmVO userVm : userVms) {
|
for (UserVm userVm : userVms) {
|
||||||
UserVmResponse userVmResponse = new UserVmResponse();
|
UserVmResponse userVmResponse = ApiResponseHelper.createUserVmResponse(userVm);
|
||||||
|
if (userVmResponse != null) {
|
||||||
Account acct = ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId()));
|
userVmResponse.setResponseName("virtualmachine");
|
||||||
if ((acct != null) && (acct.getRemoved() == null)) {
|
vmResponses.add(userVmResponse);
|
||||||
userVmResponse.setAccountName(acct.getAccountName());
|
|
||||||
userVmResponse.setDomainId(acct.getDomainId());
|
|
||||||
userVmResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
|
|
||||||
} else {
|
|
||||||
continue; // the account has been deleted, skip this VM in the response
|
|
||||||
}
|
}
|
||||||
|
|
||||||
userVmResponse.setId(userVm.getId());
|
|
||||||
AsyncJobVO asyncJob = ApiDBUtils.findInstancePendingAsyncJob("vm_instance", userVm.getId());
|
|
||||||
if (asyncJob != null) {
|
|
||||||
userVmResponse.setJobId(asyncJob.getId());
|
|
||||||
userVmResponse.setJobStatus(asyncJob.getStatus());
|
|
||||||
}
|
|
||||||
|
|
||||||
userVmResponse.setName(userVm.getName());
|
|
||||||
userVmResponse.setCreated(userVm.getCreated());
|
|
||||||
userVmResponse.setIpAddress(userVm.getPrivateIpAddress());
|
|
||||||
if (userVm.getState() != null) {
|
|
||||||
userVmResponse.setState(userVm.getState().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
userVmResponse.setHaEnable(userVm.isHaEnabled());
|
|
||||||
|
|
||||||
if (userVm.getDisplayName() != null) {
|
|
||||||
userVmResponse.setDisplayName(userVm.getDisplayName());
|
|
||||||
} else {
|
|
||||||
userVmResponse.setDisplayName(userVm.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(userVm.getId());
|
|
||||||
if (group != null) {
|
|
||||||
userVmResponse.setGroup(group.getName());
|
|
||||||
userVmResponse.setGroupId(group.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Data Center Info
|
|
||||||
userVmResponse.setZoneId(userVm.getDataCenterId());
|
|
||||||
userVmResponse.setZoneName(ApiDBUtils.findZoneById(userVm.getDataCenterId()).getName());
|
|
||||||
|
|
||||||
Account account = (Account)UserContext.current().getAccount();
|
|
||||||
//if user is an admin, display host id
|
|
||||||
if (((account == null) || isAdmin(account.getType())) && (userVm.getHostId() != null)) {
|
|
||||||
userVmResponse.setHostId(userVm.getHostId());
|
|
||||||
userVmResponse.setHostName(ApiDBUtils.findHostById(userVm.getHostId()).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Template Info
|
|
||||||
VMTemplateVO template = ApiDBUtils.findTemplateById(userVm.getTemplateId());
|
|
||||||
if (template != null) {
|
|
||||||
userVmResponse.setTemplateId(userVm.getTemplateId());
|
|
||||||
userVmResponse.setTemplateName(template.getName());
|
|
||||||
userVmResponse.setTemplateDisplayText(template.getDisplayText());
|
|
||||||
userVmResponse.setPasswordEnabled(template.getEnablePassword());
|
|
||||||
} else {
|
|
||||||
userVmResponse.setTemplateId(-1L);
|
|
||||||
userVmResponse.setTemplateName("ISO Boot");
|
|
||||||
userVmResponse.setTemplateDisplayText("ISO Boot");
|
|
||||||
userVmResponse.setPasswordEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ISO Info
|
|
||||||
if (userVm.getIsoId() != null) {
|
|
||||||
VMTemplateVO iso = ApiDBUtils.findTemplateById(userVm.getIsoId().longValue());
|
|
||||||
if (iso != null) {
|
|
||||||
userVmResponse.setIsoId(userVm.getIsoId());
|
|
||||||
userVmResponse.setIsoName(iso.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Service Offering Info
|
|
||||||
ServiceOffering offering = ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId());
|
|
||||||
userVmResponse.setServiceOfferingId(userVm.getServiceOfferingId());
|
|
||||||
userVmResponse.setServiceOfferingName(offering.getName());
|
|
||||||
userVmResponse.setCpuNumber(offering.getCpu());
|
|
||||||
userVmResponse.setCpuSpeed(offering.getSpeed());
|
|
||||||
userVmResponse.setMemory(offering.getRamSize());
|
|
||||||
|
|
||||||
VolumeVO rootVolume = ApiDBUtils.findRootVolume(userVm.getId());
|
|
||||||
if (rootVolume != null) {
|
|
||||||
userVmResponse.setRootDeviceId(rootVolume.getDeviceId());
|
|
||||||
StoragePoolVO storagePool = ApiDBUtils.findStoragePoolById(rootVolume.getPoolId());
|
|
||||||
userVmResponse.setRootDeviceType(storagePool.getPoolType().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
//stats calculation
|
|
||||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
|
||||||
String cpuUsed = null;
|
|
||||||
VmStats vmStats = ApiDBUtils.getVmStatistics(userVm.getId());
|
|
||||||
if (vmStats != null) {
|
|
||||||
float cpuUtil = (float) vmStats.getCPUUtilization();
|
|
||||||
cpuUsed = decimalFormat.format(cpuUtil) + "%";
|
|
||||||
userVmResponse.setCpuUsed(cpuUsed);
|
|
||||||
|
|
||||||
long networkKbRead = (long)vmStats.getNetworkReadKBs();
|
|
||||||
userVmResponse.setNetworkKbsRead(networkKbRead);
|
|
||||||
|
|
||||||
long networkKbWrite = (long)vmStats.getNetworkWriteKBs();
|
|
||||||
userVmResponse.setNetworkKbsWrite(networkKbWrite);
|
|
||||||
}
|
|
||||||
|
|
||||||
userVmResponse.setGuestOsId(userVm.getGuestOSId());
|
|
||||||
|
|
||||||
//network groups
|
|
||||||
userVmResponse.setNetworkGroupList(ApiDBUtils.getNetworkGroupsNamesForVm(userVm.getId()));
|
|
||||||
|
|
||||||
userVmResponse.setResponseName("virtualmachine");
|
|
||||||
vmResponses.add(userVmResponse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response.setResponses(vmResponses);
|
response.setResponses(vmResponses);
|
||||||
response.setResponseName(getName());
|
response.setResponseName(getName());
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
@ -21,19 +21,14 @@ import org.apache.log4j.Logger;
|
|||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
import com.cloud.api.ApiDBUtils;
|
import com.cloud.api.ApiDBUtils;
|
||||||
|
import com.cloud.api.ApiResponseHelper;
|
||||||
import com.cloud.api.BaseAsyncCmd;
|
import com.cloud.api.BaseAsyncCmd;
|
||||||
import com.cloud.api.BaseCmd;
|
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.response.UserVmResponse;
|
import com.cloud.api.response.UserVmResponse;
|
||||||
import com.cloud.event.EventTypes;
|
import com.cloud.event.EventTypes;
|
||||||
import com.cloud.offering.ServiceOffering;
|
|
||||||
import com.cloud.storage.StoragePoolVO;
|
|
||||||
import com.cloud.storage.VMTemplateVO;
|
|
||||||
import com.cloud.storage.VolumeVO;
|
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.uservm.UserVm;
|
import com.cloud.uservm.UserVm;
|
||||||
import com.cloud.vm.InstanceGroupVO;
|
|
||||||
import com.cloud.vm.UserVmManager;
|
import com.cloud.vm.UserVmManager;
|
||||||
|
|
||||||
@Implementation(method="rebootVirtualMachine", manager=UserVmManager.class, description="Reboots a virtual machine.")
|
@Implementation(method="rebootVirtualMachine", manager=UserVmManager.class, description="Reboots a virtual machine.")
|
||||||
@ -85,104 +80,11 @@ public class RebootVMCmd extends BaseAsyncCmd {
|
|||||||
return "rebooting user vm: " + getId();
|
return "rebooting user vm: " + getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @SuppressWarnings("unchecked")
|
@Override @SuppressWarnings("unchecked")
|
||||||
public UserVmResponse getResponse() {
|
public UserVmResponse getResponse() {
|
||||||
UserVm vm = (UserVm)getResponseObject();
|
UserVm userVm = (UserVm)getResponseObject();
|
||||||
|
UserVmResponse recoverVmResponse = ApiResponseHelper.createUserVmResponse(userVm);
|
||||||
UserVmResponse response = new UserVmResponse();
|
recoverVmResponse.setResponseName(getName());
|
||||||
response.setId(vm.getId());
|
return recoverVmResponse;
|
||||||
response.setName(vm.getName());
|
}
|
||||||
response.setCreated(vm.getCreated());
|
|
||||||
response.setZoneId(vm.getDataCenterId());
|
|
||||||
response.setZoneName(ApiDBUtils.findZoneById(vm.getDataCenterId()).getName());
|
|
||||||
response.setIpAddress(vm.getPrivateIpAddress());
|
|
||||||
response.setServiceOfferingId(vm.getServiceOfferingId());
|
|
||||||
response.setHaEnable(vm.isHaEnabled());
|
|
||||||
if (vm.getDisplayName() == null || vm.getDisplayName().length() == 0) {
|
|
||||||
response.setDisplayName(vm.getName());
|
|
||||||
} else {
|
|
||||||
response.setDisplayName(vm.getDisplayName());
|
|
||||||
}
|
|
||||||
|
|
||||||
InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(vm.getId());
|
|
||||||
if (group != null) {
|
|
||||||
response.setGroup(group.getName());
|
|
||||||
response.setGroupId(group.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vm.getState() != null) {
|
|
||||||
response.setState(vm.getState().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
Account acct = ApiDBUtils.findAccountById(vm.getAccountId());
|
|
||||||
if (acct != null) {
|
|
||||||
response.setAccountName(acct.getAccountName());
|
|
||||||
response.setDomainId(acct.getDomainId());
|
|
||||||
response.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BaseCmd.isAdmin(acct.getType()) && (vm.getHostId() != null)) {
|
|
||||||
response.setHostName(ApiDBUtils.findHostById(vm.getHostId()).getName());
|
|
||||||
response.setHostId(vm.getHostId());
|
|
||||||
}
|
|
||||||
|
|
||||||
String templateName = "ISO Boot";
|
|
||||||
boolean templatePasswordEnabled = false;
|
|
||||||
String templateDisplayText = "ISO Boot";
|
|
||||||
|
|
||||||
VMTemplateVO template = ApiDBUtils.findTemplateById(vm.getTemplateId());
|
|
||||||
if (template != null) {
|
|
||||||
templateName = template.getName();
|
|
||||||
templatePasswordEnabled = template.getEnablePassword();
|
|
||||||
templateDisplayText = template.getDisplayText();
|
|
||||||
if (templateDisplayText == null) {
|
|
||||||
templateDisplayText = templateName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setTemplateId(vm.getTemplateId());
|
|
||||||
response.setTemplateName(templateName);
|
|
||||||
response.setTemplateDisplayText(templateDisplayText);
|
|
||||||
response.setPasswordEnabled(templatePasswordEnabled);
|
|
||||||
if (templatePasswordEnabled) {
|
|
||||||
response.setPassword(null); // FIXME: Where should password come from? In the old framework, password was always passed
|
|
||||||
// in to composeResultObject() as null, so that behavior is preserved...
|
|
||||||
} else {
|
|
||||||
response.setPassword("");
|
|
||||||
}
|
|
||||||
|
|
||||||
String isoName = null;
|
|
||||||
if (vm.getIsoId() != null) {
|
|
||||||
VMTemplateVO iso = ApiDBUtils.findTemplateById(vm.getIsoId().longValue());
|
|
||||||
if (iso != null) {
|
|
||||||
isoName = iso.getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setIsoId(vm.getIsoId());
|
|
||||||
response.setIsoName(isoName);
|
|
||||||
|
|
||||||
ServiceOffering offering = ApiDBUtils.findServiceOfferingById(vm.getServiceOfferingId());
|
|
||||||
response.setServiceOfferingId(vm.getServiceOfferingId());
|
|
||||||
response.setServiceOfferingName(offering.getName());
|
|
||||||
|
|
||||||
response.setCpuNumber(offering.getCpu());
|
|
||||||
response.setCpuSpeed(offering.getSpeed());
|
|
||||||
response.setMemory(offering.getRamSize());
|
|
||||||
|
|
||||||
VolumeVO rootVolume = ApiDBUtils.findRootVolume(vm.getId());
|
|
||||||
if (rootVolume != null) {
|
|
||||||
response.setRootDeviceId(rootVolume.getDeviceId());
|
|
||||||
StoragePoolVO storagePool = ApiDBUtils.findStoragePoolById(rootVolume.getPoolId());
|
|
||||||
response.setRootDeviceType(storagePool.getPoolType().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setGuestOsId(vm.getGuestOSId());
|
|
||||||
|
|
||||||
//Network groups
|
|
||||||
response.setNetworkGroupList(ApiDBUtils.getNetworkGroupsNamesForVm(vm.getId()));
|
|
||||||
|
|
||||||
response.setResponseName(getName());
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,16 +21,12 @@ package com.cloud.api.commands;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
import com.cloud.api.ApiDBUtils;
|
import com.cloud.api.ApiResponseHelper;
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.response.UserVmResponse;
|
import com.cloud.api.response.UserVmResponse;
|
||||||
import com.cloud.offering.ServiceOffering;
|
|
||||||
import com.cloud.storage.VMTemplateVO;
|
|
||||||
import com.cloud.user.Account;
|
|
||||||
import com.cloud.uservm.UserVm;
|
import com.cloud.uservm.UserVm;
|
||||||
import com.cloud.vm.InstanceGroupVO;
|
|
||||||
import com.cloud.vm.UserVmManager;
|
import com.cloud.vm.UserVmManager;
|
||||||
|
|
||||||
@Implementation(method="recoverVirtualMachine", manager=UserVmManager.class, description="Recovers a virtual machine.")
|
@Implementation(method="recoverVirtualMachine", manager=UserVmManager.class, description="Recovers a virtual machine.")
|
||||||
@ -63,97 +59,11 @@ public class RecoverVMCmd extends BaseCmd {
|
|||||||
return s_name;
|
return s_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @SuppressWarnings("unchecked")
|
@Override @SuppressWarnings("unchecked")
|
||||||
public UserVmResponse getResponse() {
|
public UserVmResponse getResponse() {
|
||||||
Boolean success = (Boolean)getResponseObject();
|
UserVm userVm = (UserVm)getResponseObject();
|
||||||
UserVmResponse recoverVmResponse = new UserVmResponse();
|
UserVmResponse recoverVmResponse = ApiResponseHelper.createUserVmResponse(userVm);
|
||||||
UserVm vm = ApiDBUtils.findUserVmById(id);
|
|
||||||
recoverVmResponse.setSuccess(success);
|
|
||||||
recoverVmResponse.setResponseName(getName());
|
|
||||||
recoverVmResponse.setId(vm.getId());
|
|
||||||
recoverVmResponse.setName(vm.getName());
|
|
||||||
recoverVmResponse.setCreated(vm.getCreated());
|
|
||||||
recoverVmResponse.setZoneId(vm.getDataCenterId());
|
|
||||||
recoverVmResponse.setZoneName(ApiDBUtils.findZoneById(vm.getDataCenterId()).getName());
|
|
||||||
recoverVmResponse.setIpAddress(vm.getPrivateIpAddress());
|
|
||||||
recoverVmResponse.setServiceOfferingId(vm.getServiceOfferingId());
|
|
||||||
recoverVmResponse.setHaEnable(vm.isHaEnabled());
|
|
||||||
if (vm.getDisplayName() == null || vm.getDisplayName().length() == 0) {
|
|
||||||
recoverVmResponse.setDisplayName(vm.getName());
|
|
||||||
} else {
|
|
||||||
recoverVmResponse.setDisplayName(vm.getDisplayName());
|
|
||||||
}
|
|
||||||
|
|
||||||
InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(vm.getId());
|
|
||||||
if (group != null) {
|
|
||||||
recoverVmResponse.setGroup(group.getName());
|
|
||||||
recoverVmResponse.setGroupId(group.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vm.getState() != null) {
|
|
||||||
recoverVmResponse.setState(vm.getState().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
Account acct = ApiDBUtils.findAccountById(vm.getAccountId());
|
|
||||||
if (acct != null) {
|
|
||||||
recoverVmResponse.setAccountName(acct.getAccountName());
|
|
||||||
recoverVmResponse.setDomainId(acct.getDomainId());
|
|
||||||
recoverVmResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BaseCmd.isAdmin(acct.getType()) && (vm.getHostId() != null)) {
|
|
||||||
recoverVmResponse.setHostName(ApiDBUtils.findHostById(vm.getHostId()).getName());
|
|
||||||
recoverVmResponse.setHostId(vm.getHostId());
|
|
||||||
}
|
|
||||||
|
|
||||||
String templateName = "ISO Boot";
|
|
||||||
boolean templatePasswordEnabled = false;
|
|
||||||
String templateDisplayText = "ISO Boot";
|
|
||||||
|
|
||||||
VMTemplateVO template = ApiDBUtils.findTemplateById(vm.getTemplateId());
|
|
||||||
if (template != null) {
|
|
||||||
templateName = template.getName();
|
|
||||||
templatePasswordEnabled = template.getEnablePassword();
|
|
||||||
templateDisplayText = template.getDisplayText();
|
|
||||||
if (templateDisplayText == null) {
|
|
||||||
templateDisplayText = templateName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
recoverVmResponse.setTemplateId(vm.getTemplateId());
|
|
||||||
recoverVmResponse.setTemplateName(templateName);
|
|
||||||
recoverVmResponse.setTemplateDisplayText(templateDisplayText);
|
|
||||||
recoverVmResponse.setPasswordEnabled(templatePasswordEnabled);
|
|
||||||
if (templatePasswordEnabled) {
|
|
||||||
recoverVmResponse.setPassword(null); // FIXME: Where should password come from? In the old framework, password was always passed
|
|
||||||
// in to composeResultObject() as null, so that behavior is preserved...
|
|
||||||
} else {
|
|
||||||
recoverVmResponse.setPassword("");
|
|
||||||
}
|
|
||||||
|
|
||||||
String isoName = null;
|
|
||||||
if (vm.getIsoId() != null) {
|
|
||||||
VMTemplateVO iso = ApiDBUtils.findTemplateById(vm.getIsoId().longValue());
|
|
||||||
if (iso != null) {
|
|
||||||
isoName = iso.getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
recoverVmResponse.setIsoId(vm.getIsoId());
|
|
||||||
recoverVmResponse.setIsoName(isoName);
|
|
||||||
|
|
||||||
ServiceOffering offering = ApiDBUtils.findServiceOfferingById(vm.getServiceOfferingId());
|
|
||||||
recoverVmResponse.setServiceOfferingId(vm.getServiceOfferingId());
|
|
||||||
recoverVmResponse.setServiceOfferingName(offering.getName());
|
|
||||||
|
|
||||||
recoverVmResponse.setCpuNumber(offering.getCpu());
|
|
||||||
recoverVmResponse.setCpuSpeed(offering.getSpeed());
|
|
||||||
recoverVmResponse.setMemory(offering.getRamSize());
|
|
||||||
|
|
||||||
//Network groups
|
|
||||||
recoverVmResponse.setNetworkGroupList(ApiDBUtils.getNetworkGroupsNamesForVm(vm.getId()));
|
|
||||||
|
|
||||||
recoverVmResponse.setResponseName(getName());
|
recoverVmResponse.setResponseName(getName());
|
||||||
return recoverVmResponse;
|
return recoverVmResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,19 +21,14 @@ import org.apache.log4j.Logger;
|
|||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
import com.cloud.api.ApiDBUtils;
|
import com.cloud.api.ApiDBUtils;
|
||||||
|
import com.cloud.api.ApiResponseHelper;
|
||||||
import com.cloud.api.BaseAsyncCmd;
|
import com.cloud.api.BaseAsyncCmd;
|
||||||
import com.cloud.api.BaseCmd;
|
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.response.UserVmResponse;
|
import com.cloud.api.response.UserVmResponse;
|
||||||
import com.cloud.event.EventTypes;
|
import com.cloud.event.EventTypes;
|
||||||
import com.cloud.offering.ServiceOffering;
|
|
||||||
import com.cloud.storage.VMTemplateVO;
|
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.user.User;
|
|
||||||
import com.cloud.user.UserContext;
|
|
||||||
import com.cloud.uservm.UserVm;
|
import com.cloud.uservm.UserVm;
|
||||||
import com.cloud.vm.InstanceGroupVO;
|
|
||||||
import com.cloud.vm.UserVmManager;
|
import com.cloud.vm.UserVmManager;
|
||||||
|
|
||||||
@Implementation(method="resetVMPassword", manager=UserVmManager.class, description="Resets the password for virtual machine. " +
|
@Implementation(method="resetVMPassword", manager=UserVmManager.class, description="Resets the password for virtual machine. " +
|
||||||
@ -103,105 +98,12 @@ public class ResetVMPasswordCmd extends BaseAsyncCmd {
|
|||||||
@Override @SuppressWarnings("unchecked")
|
@Override @SuppressWarnings("unchecked")
|
||||||
public UserVmResponse getResponse() {
|
public UserVmResponse getResponse() {
|
||||||
UserVm userVm = (UserVm)getResponseObject();
|
UserVm userVm = (UserVm)getResponseObject();
|
||||||
|
UserVmResponse response = ApiResponseHelper.createUserVmResponse(userVm);
|
||||||
UserVmResponse response = new UserVmResponse();
|
|
||||||
response.setId(userVm.getId());
|
|
||||||
response.setName(userVm.getName());
|
|
||||||
response.setCreated(userVm.getCreated());
|
|
||||||
response.setZoneId(userVm.getDataCenterId());
|
|
||||||
response.setZoneName(ApiDBUtils.findZoneById(userVm.getDataCenterId()).getName());
|
|
||||||
response.setIpAddress(userVm.getPrivateIpAddress());
|
|
||||||
response.setServiceOfferingId(userVm.getServiceOfferingId());
|
|
||||||
response.setHaEnable(userVm.isHaEnabled());
|
|
||||||
|
|
||||||
InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(userVm.getId());
|
|
||||||
if (group != null) {
|
|
||||||
response.setGroup(group.getName());
|
|
||||||
response.setGroupId(group.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userVm.getDisplayName() == null || userVm.getDisplayName().length() == 0) {
|
|
||||||
response.setDisplayName(userVm.getName());
|
|
||||||
} else {
|
|
||||||
response.setDisplayName(userVm.getDisplayName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userVm.getState() != null) {
|
// FIXME: where will the password come from in this case?
|
||||||
response.setState(userVm.getState().toString());
|
// if (templatePasswordEnabled) {
|
||||||
}
|
// response.setPassword(getPassword());
|
||||||
|
// }
|
||||||
VMTemplateVO template = ApiDBUtils.findTemplateById(userVm.getTemplateId());
|
|
||||||
|
|
||||||
Account acct = ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId()));
|
|
||||||
if (acct != null) {
|
|
||||||
response.setAccountName(acct.getAccountName());
|
|
||||||
response.setDomainId(acct.getDomainId());
|
|
||||||
response.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
Long userId = UserContext.current().getUserId();
|
|
||||||
if (userId == null) {
|
|
||||||
userId = User.UID_SYSTEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
//this is for the case where the admin deploys a vm for a normal user
|
|
||||||
User userExecutingCmd = ApiDBUtils.findUserById(userId);
|
|
||||||
Account acctForUserExecutingCmd = ApiDBUtils.findAccountById(Long.valueOf(userExecutingCmd.getAccountId()));
|
|
||||||
if ((BaseCmd.isAdmin(acctForUserExecutingCmd.getType()) && (userVm.getHostId() != null)) || (BaseCmd.isAdmin(acct.getType()) && (userVm.getHostId() != null))) {
|
|
||||||
response.setHostName(ApiDBUtils.findHostById(userVm.getHostId()).getName());
|
|
||||||
response.setHostId(userVm.getHostId());
|
|
||||||
}
|
|
||||||
|
|
||||||
String templateName = "none";
|
|
||||||
boolean templatePasswordEnabled = false;
|
|
||||||
String templateDisplayText = null;
|
|
||||||
|
|
||||||
if (template != null) {
|
|
||||||
templateName = template.getName();
|
|
||||||
templatePasswordEnabled = template.getEnablePassword();
|
|
||||||
templateDisplayText = template.getDisplayText();
|
|
||||||
if (templateDisplayText == null) {
|
|
||||||
templateDisplayText = templateName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (templatePasswordEnabled) { // FIXME: where will the password come from in this case?
|
|
||||||
response.setPassword(getPassword());
|
|
||||||
}
|
|
||||||
|
|
||||||
// ISO Info
|
|
||||||
Long isoId = userVm.getIsoId();
|
|
||||||
if (isoId != null) {
|
|
||||||
VMTemplateVO iso = ApiDBUtils.findTemplateById(isoId.longValue());
|
|
||||||
if (iso != null) {
|
|
||||||
response.setIsoId(isoId.longValue());
|
|
||||||
response.setIsoName(iso.getName());
|
|
||||||
response.setTemplateId(isoId.longValue());
|
|
||||||
response.setTemplateName(iso.getName());
|
|
||||||
|
|
||||||
templateDisplayText = iso.getDisplayText();
|
|
||||||
if(templateDisplayText == null)
|
|
||||||
templateDisplayText = iso.getName();
|
|
||||||
response.setIsoDisplayText(templateDisplayText);
|
|
||||||
response.setTemplateDisplayText(templateDisplayText);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
response.setTemplateId(userVm.getTemplateId());
|
|
||||||
response.setTemplateName(templateName);
|
|
||||||
response.setTemplateDisplayText(templateDisplayText);
|
|
||||||
response.setPasswordEnabled(templatePasswordEnabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
ServiceOffering offering = ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId());
|
|
||||||
response.setServiceOfferingId(userVm.getServiceOfferingId());
|
|
||||||
response.setServiceOfferingName(offering.getName());
|
|
||||||
|
|
||||||
response.setCpuNumber(offering.getCpu());
|
|
||||||
response.setCpuSpeed(offering.getSpeed());
|
|
||||||
response.setMemory(offering.getRamSize());
|
|
||||||
|
|
||||||
response.setNetworkGroupList(ApiDBUtils.getNetworkGroupsNamesForVm(userVm.getId()));
|
|
||||||
|
|
||||||
response.setResponseName(getName());
|
response.setResponseName(getName());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,19 +21,14 @@ import org.apache.log4j.Logger;
|
|||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
import com.cloud.api.ApiDBUtils;
|
import com.cloud.api.ApiDBUtils;
|
||||||
|
import com.cloud.api.ApiResponseHelper;
|
||||||
import com.cloud.api.BaseAsyncCmd;
|
import com.cloud.api.BaseAsyncCmd;
|
||||||
import com.cloud.api.BaseCmd;
|
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.response.UserVmResponse;
|
import com.cloud.api.response.UserVmResponse;
|
||||||
import com.cloud.event.EventTypes;
|
import com.cloud.event.EventTypes;
|
||||||
import com.cloud.offering.ServiceOffering;
|
|
||||||
import com.cloud.storage.StoragePoolVO;
|
|
||||||
import com.cloud.storage.VMTemplateVO;
|
|
||||||
import com.cloud.storage.VolumeVO;
|
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.uservm.UserVm;
|
import com.cloud.uservm.UserVm;
|
||||||
import com.cloud.vm.InstanceGroupVO;
|
|
||||||
import com.cloud.vm.UserVmManager;
|
import com.cloud.vm.UserVmManager;
|
||||||
|
|
||||||
@Implementation(method="startVirtualMachine", manager=UserVmManager.class, description="Starts a virtual machine.")
|
@Implementation(method="startVirtualMachine", manager=UserVmManager.class, description="Starts a virtual machine.")
|
||||||
@ -90,105 +85,11 @@ public class StartVMCmd extends BaseAsyncCmd {
|
|||||||
return "starting user vm: " + getId();
|
return "starting user vm: " + getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @SuppressWarnings("unchecked")
|
@Override @SuppressWarnings("unchecked")
|
||||||
public UserVmResponse getResponse() {
|
public UserVmResponse getResponse() {
|
||||||
UserVm vm = (UserVm)getResponseObject();
|
UserVm userVm = (UserVm)getResponseObject();
|
||||||
|
UserVmResponse recoverVmResponse = ApiResponseHelper.createUserVmResponse(userVm);
|
||||||
UserVmResponse response = new UserVmResponse();
|
recoverVmResponse.setResponseName(getName());
|
||||||
response.setId(vm.getId());
|
return recoverVmResponse;
|
||||||
response.setName(vm.getName());
|
|
||||||
response.setCreated(vm.getCreated());
|
|
||||||
response.setZoneId(vm.getDataCenterId());
|
|
||||||
response.setZoneName(ApiDBUtils.findZoneById(vm.getDataCenterId()).getName());
|
|
||||||
response.setIpAddress(vm.getPrivateIpAddress());
|
|
||||||
response.setServiceOfferingId(vm.getServiceOfferingId());
|
|
||||||
response.setHaEnable(vm.isHaEnabled());
|
|
||||||
if (vm.getDisplayName() == null || vm.getDisplayName().length() == 0) {
|
|
||||||
response.setDisplayName(vm.getName());
|
|
||||||
} else {
|
|
||||||
response.setDisplayName(vm.getDisplayName());
|
|
||||||
}
|
|
||||||
|
|
||||||
InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(vm.getId());
|
|
||||||
if (group != null) {
|
|
||||||
response.setGroup(group.getName());
|
|
||||||
response.setGroupId(group.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vm.getState() != null) {
|
|
||||||
response.setState(vm.getState().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
Account acct = ApiDBUtils.findAccountById(vm.getAccountId());
|
|
||||||
if (acct != null) {
|
|
||||||
response.setAccountName(acct.getAccountName());
|
|
||||||
response.setDomainId(acct.getDomainId());
|
|
||||||
response.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BaseCmd.isAdmin(acct.getType()) && (vm.getHostId() != null)) {
|
|
||||||
response.setHostName(ApiDBUtils.findHostById(vm.getHostId()).getName());
|
|
||||||
response.setHostId(vm.getHostId());
|
|
||||||
}
|
|
||||||
|
|
||||||
String templateName = "ISO Boot";
|
|
||||||
boolean templatePasswordEnabled = false;
|
|
||||||
String templateDisplayText = "ISO Boot";
|
|
||||||
|
|
||||||
VMTemplateVO template = ApiDBUtils.findTemplateById(vm.getTemplateId());
|
|
||||||
if (template != null) {
|
|
||||||
templateName = template.getName();
|
|
||||||
templatePasswordEnabled = template.getEnablePassword();
|
|
||||||
templateDisplayText = template.getDisplayText();
|
|
||||||
if (templateDisplayText == null) {
|
|
||||||
templateDisplayText = templateName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setTemplateId(vm.getTemplateId());
|
|
||||||
response.setTemplateName(templateName);
|
|
||||||
response.setTemplateDisplayText(templateDisplayText);
|
|
||||||
response.setPasswordEnabled(templatePasswordEnabled);
|
|
||||||
if (templatePasswordEnabled) {
|
|
||||||
response.setPassword(null); // FIXME: Where should password come from? In the old framework, password was always passed
|
|
||||||
// in to composeResultObject() as null, so that behavior is preserved...
|
|
||||||
} else {
|
|
||||||
response.setPassword("");
|
|
||||||
}
|
|
||||||
|
|
||||||
String isoName = null;
|
|
||||||
if (vm.getIsoId() != null) {
|
|
||||||
VMTemplateVO iso = ApiDBUtils.findTemplateById(vm.getIsoId().longValue());
|
|
||||||
if (iso != null) {
|
|
||||||
isoName = iso.getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setIsoId(vm.getIsoId());
|
|
||||||
response.setIsoName(isoName);
|
|
||||||
|
|
||||||
ServiceOffering offering = ApiDBUtils.findServiceOfferingById(vm.getServiceOfferingId());
|
|
||||||
response.setServiceOfferingId(vm.getServiceOfferingId());
|
|
||||||
response.setServiceOfferingName(offering.getName());
|
|
||||||
|
|
||||||
response.setCpuNumber(offering.getCpu());
|
|
||||||
response.setCpuSpeed(offering.getSpeed());
|
|
||||||
response.setMemory(offering.getRamSize());
|
|
||||||
|
|
||||||
VolumeVO rootVolume = ApiDBUtils.findRootVolume(vm.getId());
|
|
||||||
if (rootVolume != null) {
|
|
||||||
response.setRootDeviceId(rootVolume.getDeviceId());
|
|
||||||
StoragePoolVO storagePool = ApiDBUtils.findStoragePoolById(rootVolume.getPoolId());
|
|
||||||
response.setRootDeviceType(storagePool.getPoolType().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setGuestOsId(vm.getGuestOSId());
|
|
||||||
|
|
||||||
//Network groups
|
|
||||||
response.setNetworkGroupList(ApiDBUtils.getNetworkGroupsNamesForVm(vm.getId()));
|
|
||||||
|
|
||||||
response.setResponseName(getName());
|
|
||||||
//response.setResponseName(getResultObjectName());
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,19 +21,14 @@ import org.apache.log4j.Logger;
|
|||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
import com.cloud.api.ApiDBUtils;
|
import com.cloud.api.ApiDBUtils;
|
||||||
|
import com.cloud.api.ApiResponseHelper;
|
||||||
import com.cloud.api.BaseAsyncCmd;
|
import com.cloud.api.BaseAsyncCmd;
|
||||||
import com.cloud.api.BaseCmd;
|
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.response.UserVmResponse;
|
import com.cloud.api.response.UserVmResponse;
|
||||||
import com.cloud.event.EventTypes;
|
import com.cloud.event.EventTypes;
|
||||||
import com.cloud.offering.ServiceOffering;
|
|
||||||
import com.cloud.storage.StoragePoolVO;
|
|
||||||
import com.cloud.storage.VMTemplateVO;
|
|
||||||
import com.cloud.storage.VolumeVO;
|
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.uservm.UserVm;
|
import com.cloud.uservm.UserVm;
|
||||||
import com.cloud.vm.InstanceGroupVO;
|
|
||||||
import com.cloud.vm.UserVmManager;
|
import com.cloud.vm.UserVmManager;
|
||||||
|
|
||||||
@Implementation(method="stopVirtualMachine", manager=UserVmManager.class, description="Stops a virtual machine.")
|
@Implementation(method="stopVirtualMachine", manager=UserVmManager.class, description="Stops a virtual machine.")
|
||||||
@ -90,100 +85,11 @@ public class StopVMCmd extends BaseAsyncCmd {
|
|||||||
return "stopping user vm: " + getId();
|
return "stopping user vm: " + getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @SuppressWarnings("unchecked")
|
@Override @SuppressWarnings("unchecked")
|
||||||
public UserVmResponse getResponse() {
|
public UserVmResponse getResponse() {
|
||||||
UserVm vm = (UserVm)getResponseObject();
|
UserVm userVm = (UserVm)getResponseObject();
|
||||||
|
UserVmResponse recoverVmResponse = ApiResponseHelper.createUserVmResponse(userVm);
|
||||||
UserVmResponse response = new UserVmResponse();
|
recoverVmResponse.setResponseName(getName());
|
||||||
response.setId(vm.getId());
|
return recoverVmResponse;
|
||||||
response.setName(vm.getName());
|
}
|
||||||
response.setCreated(vm.getCreated());
|
|
||||||
response.setZoneId(vm.getDataCenterId());
|
|
||||||
response.setZoneName(ApiDBUtils.findZoneById(vm.getDataCenterId()).getName());
|
|
||||||
response.setIpAddress(vm.getPrivateIpAddress());
|
|
||||||
response.setServiceOfferingId(vm.getServiceOfferingId());
|
|
||||||
response.setHaEnable(vm.isHaEnabled());
|
|
||||||
if (vm.getDisplayName() == null || vm.getDisplayName().length() == 0) {
|
|
||||||
response.setDisplayName(vm.getName());
|
|
||||||
} else {
|
|
||||||
response.setDisplayName(vm.getDisplayName());
|
|
||||||
}
|
|
||||||
|
|
||||||
InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(vm.getId());
|
|
||||||
if (group != null) {
|
|
||||||
response.setGroup(group.getName());
|
|
||||||
response.setGroupId(group.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vm.getState() != null) {
|
|
||||||
response.setState(vm.getState().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
Account acct = ApiDBUtils.findAccountById(vm.getAccountId());
|
|
||||||
if (acct != null) {
|
|
||||||
response.setAccountName(acct.getAccountName());
|
|
||||||
response.setDomainId(acct.getDomainId());
|
|
||||||
response.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
String templateName = "ISO Boot";
|
|
||||||
boolean templatePasswordEnabled = false;
|
|
||||||
String templateDisplayText = "ISO Boot";
|
|
||||||
|
|
||||||
VMTemplateVO template = ApiDBUtils.findTemplateById(vm.getTemplateId());
|
|
||||||
if (template != null) {
|
|
||||||
templateName = template.getName();
|
|
||||||
templatePasswordEnabled = template.getEnablePassword();
|
|
||||||
templateDisplayText = template.getDisplayText();
|
|
||||||
if (templateDisplayText == null) {
|
|
||||||
templateDisplayText = templateName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setTemplateId(vm.getTemplateId());
|
|
||||||
response.setTemplateName(templateName);
|
|
||||||
response.setTemplateDisplayText(templateDisplayText);
|
|
||||||
response.setPasswordEnabled(templatePasswordEnabled);
|
|
||||||
if (templatePasswordEnabled) {
|
|
||||||
response.setPassword(null); // FIXME: Where should password come from? In the old framework, password was always passed
|
|
||||||
// in to composeResultObject() as null, so that behavior is preserved...
|
|
||||||
} else {
|
|
||||||
response.setPassword("");
|
|
||||||
}
|
|
||||||
|
|
||||||
String isoName = null;
|
|
||||||
if (vm.getIsoId() != null) {
|
|
||||||
VMTemplateVO iso = ApiDBUtils.findTemplateById(vm.getIsoId().longValue());
|
|
||||||
if (iso != null) {
|
|
||||||
isoName = iso.getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setIsoId(vm.getIsoId());
|
|
||||||
response.setIsoName(isoName);
|
|
||||||
|
|
||||||
ServiceOffering offering = ApiDBUtils.findServiceOfferingById(vm.getServiceOfferingId());
|
|
||||||
response.setServiceOfferingId(vm.getServiceOfferingId());
|
|
||||||
response.setServiceOfferingName(offering.getName());
|
|
||||||
|
|
||||||
response.setCpuNumber(offering.getCpu());
|
|
||||||
response.setCpuSpeed(offering.getSpeed());
|
|
||||||
response.setMemory(offering.getRamSize());
|
|
||||||
|
|
||||||
VolumeVO rootVolume = ApiDBUtils.findRootVolume(vm.getId());
|
|
||||||
if (rootVolume != null) {
|
|
||||||
response.setRootDeviceId(rootVolume.getDeviceId());
|
|
||||||
StoragePoolVO storagePool = ApiDBUtils.findStoragePoolById(rootVolume.getPoolId());
|
|
||||||
response.setRootDeviceType(storagePool.getPoolType().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setGuestOsId(vm.getGuestOSId());
|
|
||||||
|
|
||||||
//Network groups
|
|
||||||
response.setNetworkGroupList(ApiDBUtils.getNetworkGroupsNamesForVm(vm.getId()));
|
|
||||||
|
|
||||||
response.setResponseName(getName());
|
|
||||||
//response.setResponseName(getResultObjectName());
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,10 +20,12 @@ package com.cloud.api.commands;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
|
import com.cloud.api.ApiResponseHelper;
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.response.SuccessResponse;
|
import com.cloud.api.response.UserVmResponse;
|
||||||
|
import com.cloud.uservm.UserVm;
|
||||||
import com.cloud.vm.UserVmManager;
|
import com.cloud.vm.UserVmManager;
|
||||||
|
|
||||||
@Implementation(method="updateVirtualMachine", manager=UserVmManager.class, description="Updates parameters of a virtual machine.")
|
@Implementation(method="updateVirtualMachine", manager=UserVmManager.class, description="Updates parameters of a virtual machine.")
|
||||||
@ -81,10 +83,10 @@ public class UpdateVMCmd extends BaseCmd{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override @SuppressWarnings("unchecked")
|
@Override @SuppressWarnings("unchecked")
|
||||||
public SuccessResponse getResponse() {
|
public UserVmResponse getResponse() {
|
||||||
SuccessResponse response = new SuccessResponse();
|
UserVm userVm = (UserVm)getResponseObject();
|
||||||
response.setSuccess(Boolean.TRUE);
|
UserVmResponse recoverVmResponse = ApiResponseHelper.createUserVmResponse(userVm);
|
||||||
response.setResponseName(getName());
|
recoverVmResponse.setResponseName(getName());
|
||||||
return response;
|
return recoverVmResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,24 +17,16 @@
|
|||||||
*/
|
*/
|
||||||
package com.cloud.api.commands;
|
package com.cloud.api.commands;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.api.ApiConstants;
|
import com.cloud.api.ApiConstants;
|
||||||
import com.cloud.api.ApiDBUtils;
|
import com.cloud.api.ApiResponseHelper;
|
||||||
import com.cloud.api.BaseCmd;
|
import com.cloud.api.BaseCmd;
|
||||||
import com.cloud.api.Implementation;
|
import com.cloud.api.Implementation;
|
||||||
import com.cloud.api.Parameter;
|
import com.cloud.api.Parameter;
|
||||||
import com.cloud.api.ServerApiException;
|
|
||||||
import com.cloud.api.response.UserVmResponse;
|
import com.cloud.api.response.UserVmResponse;
|
||||||
import com.cloud.offering.ServiceOffering;
|
import com.cloud.uservm.UserVm;
|
||||||
import com.cloud.service.ServiceOfferingVO;
|
|
||||||
import com.cloud.storage.VMTemplateVO;
|
|
||||||
import com.cloud.user.Account;
|
|
||||||
import com.cloud.vm.UserVmManager;
|
import com.cloud.vm.UserVmManager;
|
||||||
import com.cloud.vm.UserVmVO;
|
|
||||||
import com.cloud.vm.VmStats;
|
|
||||||
|
|
||||||
@Implementation(method="upgradeVirtualMachine", manager=UserVmManager.class, description="Changes the service offering for a virtual machine. " +
|
@Implementation(method="upgradeVirtualMachine", manager=UserVmManager.class, description="Changes the service offering for a virtual machine. " +
|
||||||
"The virtual machine must be in a \"Stopped\" state for " +
|
"The virtual machine must be in a \"Stopped\" state for " +
|
||||||
@ -80,67 +72,9 @@ public class UpgradeVMCmd extends BaseCmd {
|
|||||||
|
|
||||||
@Override @SuppressWarnings("unchecked")
|
@Override @SuppressWarnings("unchecked")
|
||||||
public UserVmResponse getResponse() {
|
public UserVmResponse getResponse() {
|
||||||
UserVmVO userVm = (UserVmVO)getResponseObject();
|
UserVm userVm = (UserVm)getResponseObject();
|
||||||
|
UserVmResponse recoverVmResponse = ApiResponseHelper.createUserVmResponse(userVm);
|
||||||
UserVmResponse response = new UserVmResponse();
|
recoverVmResponse.setResponseName(getName());
|
||||||
if (userVm != null) {
|
return recoverVmResponse;
|
||||||
Account acct = ApiDBUtils.findAccountById(userVm.getAccountId());
|
|
||||||
response.setId(userVm.getId());
|
|
||||||
response.setAccountName(acct.getAccountName());
|
|
||||||
|
|
||||||
ServiceOffering offering = ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId());
|
|
||||||
response.setCpuSpeed(offering.getSpeed());
|
|
||||||
response.setMemory(offering.getRamSize());
|
|
||||||
if (((ServiceOfferingVO)offering).getDisplayText() != null) {
|
|
||||||
response.setServiceOfferingName(((ServiceOfferingVO)offering).getDisplayText());
|
|
||||||
} else {
|
|
||||||
response.setServiceOfferingName(offering.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setServiceOfferingId(userVm.getServiceOfferingId());
|
|
||||||
|
|
||||||
//stats calculation
|
|
||||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
|
||||||
String cpuUsed = null;
|
|
||||||
VmStats vmStats = ApiDBUtils.getVmStatistics(userVm.getId());
|
|
||||||
if (vmStats != null) {
|
|
||||||
float cpuUtil = (float) vmStats.getCPUUtilization();
|
|
||||||
cpuUsed = decimalFormat.format(cpuUtil) + "%";
|
|
||||||
response.setCpuUsed(cpuUsed);
|
|
||||||
|
|
||||||
long networkKbRead = (long)vmStats.getNetworkReadKBs();
|
|
||||||
response.setNetworkKbsRead(networkKbRead);
|
|
||||||
|
|
||||||
long networkKbWrite = (long)vmStats.getNetworkWriteKBs();
|
|
||||||
response.setNetworkKbsWrite(networkKbWrite);
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setCreated(userVm.getCreated());
|
|
||||||
response.setDisplayName(userVm.getDisplayName());
|
|
||||||
response.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
|
|
||||||
response.setDomainId(acct.getDomainId());
|
|
||||||
response.setHaEnable(userVm.isHaEnabled());
|
|
||||||
|
|
||||||
if (userVm.getHostId() != null) {
|
|
||||||
response.setHostId(userVm.getHostId());
|
|
||||||
response.setHostName(ApiDBUtils.findHostById(userVm.getHostId()).getName());
|
|
||||||
}
|
|
||||||
response.setIpAddress(userVm.getPrivateIpAddress());
|
|
||||||
response.setName(userVm.getName());
|
|
||||||
response.setState(userVm.getState().toString());
|
|
||||||
response.setZoneId(userVm.getDataCenterId());
|
|
||||||
response.setZoneName(ApiDBUtils.findZoneById(userVm.getDataCenterId()).getName());
|
|
||||||
|
|
||||||
VMTemplateVO template = ApiDBUtils.findTemplateById(userVm.getTemplateId());
|
|
||||||
response.setPasswordEnabled(template.getEnablePassword());
|
|
||||||
response.setTemplateDisplayText(template.getDisplayText());
|
|
||||||
response.setTemplateId(template.getId());
|
|
||||||
response.setTemplateName(template.getName());
|
|
||||||
} else {
|
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update zone; internal error.");
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setResponseName(getName());
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -138,17 +138,6 @@ public class UserVmResponse extends BaseResponse {
|
|||||||
@SerializedName("jobstatus") @Param(description="shows the current pending asynchronous job status")
|
@SerializedName("jobstatus") @Param(description="shows the current pending asynchronous job status")
|
||||||
private Integer jobStatus;
|
private Integer jobStatus;
|
||||||
|
|
||||||
@SerializedName("success") @Param(description="shows the status of the return call for the invoked uservmmanager command")
|
|
||||||
private Boolean success;
|
|
||||||
|
|
||||||
public void setSuccess(Boolean success){
|
|
||||||
this.success = success;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getSuccess(){
|
|
||||||
return this.success;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1885,7 +1885,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
@Override @DB
|
@Override @DB
|
||||||
public boolean recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException, CloudRuntimeException {
|
public UserVm recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException, CloudRuntimeException {
|
||||||
|
|
||||||
Long vmId = cmd.getId();
|
Long vmId = cmd.getId();
|
||||||
Account accountHandle = UserContext.current().getAccount();
|
Account accountHandle = UserContext.current().getAccount();
|
||||||
@ -1910,14 +1910,14 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
|||||||
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);
|
||||||
}
|
}
|
||||||
return false;
|
throw new InvalidParameterValueException("Unable to find vm by id " + vmId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm.getState() != State.Destroyed) {
|
if (vm.getState() != State.Destroyed) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("vm is not in the right state: " + vmId);
|
s_logger.debug("vm is not in the right state: " + vmId);
|
||||||
}
|
}
|
||||||
return true;
|
throw new InvalidParameterValueException("Vm with id " + vmId + " is not in the right state");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
@ -1960,7 +1960,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
|||||||
|
|
||||||
if (!_vmDao.updateIf(vm, Event.RecoveryRequested, null)) {
|
if (!_vmDao.updateIf(vm, Event.RecoveryRequested, null)) {
|
||||||
s_logger.debug("Unable to recover the vm because it is not in the correct state: " + vmId);
|
s_logger.debug("Unable to recover the vm because it is not in the correct state: " + vmId);
|
||||||
return false;
|
throw new InvalidParameterValueException("Unable to recover the vm because it is not in the correct state: " + vmId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recover the VM's disks
|
// Recover the VM's disks
|
||||||
@ -1997,7 +1997,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
|||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
|
||||||
return true;
|
return _vmDao.findById(vmId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -3208,7 +3208,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateVirtualMachine(UpdateVMCmd cmd) {
|
public UserVm updateVirtualMachine(UpdateVMCmd cmd) {
|
||||||
String displayName = cmd.getDisplayName();
|
String displayName = cmd.getDisplayName();
|
||||||
String group = cmd.getGroup();
|
String group = cmd.getGroup();
|
||||||
Boolean ha = cmd.getHaEnable();
|
Boolean ha = cmd.getHaEnable();
|
||||||
@ -3265,10 +3265,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
|||||||
// create a event for the change in HA Enabled flag
|
// create a event for the change in HA Enabled flag
|
||||||
EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_INFO, type, description, null);
|
EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_INFO, type, description, null);
|
||||||
}
|
}
|
||||||
|
return _vmDao.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserVmVO stopVirtualMachine(StopVMCmd cmd) throws ServerApiException{
|
public UserVm stopVirtualMachine(StopVMCmd cmd) throws ServerApiException{
|
||||||
|
|
||||||
//Input validation
|
//Input validation
|
||||||
Account account = UserContext.current().getAccount();
|
Account account = UserContext.current().getAccount();
|
||||||
@ -3290,14 +3291,13 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
|||||||
|
|
||||||
boolean success = stopVirtualMachine(userId, id, eventId);
|
boolean success = stopVirtualMachine(userId, id, eventId);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Unable to stop virtual machine with id " + id + ", internal error.");
|
throw new CloudRuntimeException("Unable to stop virtual machine with id " + id + ", internal error.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return _vmDao.findById(id);
|
return _vmDao.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserVmVO startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, ExecutionException, ConcurrentOperationException {
|
public UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, ExecutionException, ConcurrentOperationException {
|
||||||
//Input validation
|
//Input validation
|
||||||
Account account = UserContext.current().getAccount();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
@ -3348,7 +3348,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean destroyVm(DestroyVMCmd cmd) {
|
public UserVm destroyVm(DestroyVMCmd cmd) {
|
||||||
|
|
||||||
Account account = UserContext.current().getAccount();
|
Account account = UserContext.current().getAccount();
|
||||||
Long userId = UserContext.current().getUserId();
|
Long userId = UserContext.current().getUserId();
|
||||||
@ -3369,12 +3369,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
|||||||
if(status)
|
if(status)
|
||||||
{
|
{
|
||||||
EventUtils.saveEvent(userId, vmInstance.getAccountId(), EventTypes.EVENT_VM_DESTROY, "Successfully destroyed vm with id:"+vmId);
|
EventUtils.saveEvent(userId, vmInstance.getAccountId(), EventTypes.EVENT_VM_DESTROY, "Successfully destroyed vm with id:"+vmId);
|
||||||
return status;
|
return _vmDao.findById(vmId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EventUtils.saveEvent(userId, vmInstance.getAccountId(), EventTypes.EVENT_VM_DESTROY, "Failed to destroy vm with id:"+vmId);
|
EventUtils.saveEvent(userId, vmInstance.getAccountId(), EventTypes.EVENT_VM_DESTROY, "Failed to destroy vm with id:"+vmId);
|
||||||
return status;
|
throw new CloudRuntimeException("Failed to destroy vm with id " + vmId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -53,7 +53,7 @@ public interface UserVmService extends Manager {
|
|||||||
* @param userId the id of the user performing the action
|
* @param userId the id of the user performing the action
|
||||||
* @param vmId the id of the virtual machine.
|
* @param vmId the id of the virtual machine.
|
||||||
*/
|
*/
|
||||||
boolean destroyVm(DestroyVMCmd cmd);
|
UserVm destroyVm(DestroyVMCmd cmd);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the password of a virtual machine.
|
* Resets the password of a virtual machine.
|
||||||
@ -77,15 +77,15 @@ public interface UserVmService extends Manager {
|
|||||||
*/
|
*/
|
||||||
VolumeResponse detachVolumeFromVM(DetachVolumeCmd cmmd);
|
VolumeResponse detachVolumeFromVM(DetachVolumeCmd cmmd);
|
||||||
|
|
||||||
UserVmVO startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, ExecutionException, ConcurrentOperationException;
|
UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, ExecutionException, ConcurrentOperationException;
|
||||||
UserVmVO stopVirtualMachine(StopVMCmd cmd);
|
UserVm stopVirtualMachine(StopVMCmd cmd);
|
||||||
UserVm rebootVirtualMachine(RebootVMCmd cmd);
|
UserVm rebootVirtualMachine(RebootVMCmd cmd);
|
||||||
|
UserVm updateVirtualMachine(UpdateVMCmd cmd);
|
||||||
|
UserVm recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
OperationResponse executeRebootVM(RebootVMExecutor executor, VMOperationParam param);
|
OperationResponse executeRebootVM(RebootVMExecutor executor, VMOperationParam param);
|
||||||
|
|
||||||
boolean recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a template database record in preparation for creating a private template.
|
* Create a template database record in preparation for creating a private template.
|
||||||
* @param cmd the command object that defines the name, display text, snapshot/volume, bits, public/private, etc.
|
* @param cmd the command object that defines the name, display text, snapshot/volume, bits, public/private, etc.
|
||||||
@ -102,8 +102,6 @@ public interface UserVmService extends Manager {
|
|||||||
* @throws InvalidParameterValueException
|
* @throws InvalidParameterValueException
|
||||||
*/
|
*/
|
||||||
VMTemplateVO createPrivateTemplate(CreateTemplateCmd cmd);
|
VMTemplateVO createPrivateTemplate(CreateTemplateCmd cmd);
|
||||||
|
|
||||||
void updateVirtualMachine(UpdateVMCmd cmd);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a User VM in the database and returns the VM to the caller.
|
* Creates a User VM in the database and returns the VM to the caller.
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
as the only address, specify as <ipAddressRange>192.168.1.1<ipAddressRange>. To specify 192.168.1.1
|
as the only address, specify as <ipAddressRange>192.168.1.1<ipAddressRange>. To specify 192.168.1.1
|
||||||
to 192.168.1.150 specify as <ipAddressRange>192.168.1.1-192.168.1.150</ipAddressRange>
|
to 192.168.1.150 specify as <ipAddressRange>192.168.1.1-192.168.1.150</ipAddressRange>
|
||||||
-->
|
-->
|
||||||
<zones>
|
<!-- <zones>
|
||||||
<zone>
|
<zone>
|
||||||
<id>1</id>
|
<id>1</id>
|
||||||
<name>NM</name>
|
<name>NM</name>
|
||||||
@ -22,7 +22,7 @@
|
|||||||
<vnet>560-579</vnet>
|
<vnet>560-579</vnet>
|
||||||
<guestNetworkCidr>10.1.1.0/24</guestNetworkCidr>
|
<guestNetworkCidr>10.1.1.0/24</guestNetworkCidr>
|
||||||
</zone>
|
</zone>
|
||||||
</zones>
|
</zones> -->
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
ipAddressRange: It is possible to specify a single IP address. For example, to add 192.168.1.1
|
ipAddressRange: It is possible to specify a single IP address. For example, to add 192.168.1.1
|
||||||
@ -32,7 +32,7 @@
|
|||||||
At the moment there is no way to specify a different netmask for each pod. The netmask
|
At the moment there is no way to specify a different netmask for each pod. The netmask
|
||||||
is controlled by the private.net.mask parameter further down this file.
|
is controlled by the private.net.mask parameter further down this file.
|
||||||
-->
|
-->
|
||||||
<pods>
|
<!-- <pods>
|
||||||
<pod>
|
<pod>
|
||||||
<id>1</id>
|
<id>1</id>
|
||||||
<name>NM</name>
|
<name>NM</name>
|
||||||
@ -41,7 +41,7 @@
|
|||||||
<cidr>10.91.28.0/24</cidr>
|
<cidr>10.91.28.0/24</cidr>
|
||||||
<ipAddressRange>10.91.28.160-10.91.28.179</ipAddressRange>
|
<ipAddressRange>10.91.28.160-10.91.28.179</ipAddressRange>
|
||||||
</pod>
|
</pod>
|
||||||
</pods>
|
</pods> -->
|
||||||
<!--
|
<!--
|
||||||
<storagePools>
|
<storagePools>
|
||||||
<storagePool>
|
<storagePool>
|
||||||
@ -64,7 +64,7 @@
|
|||||||
</secondaryStorages>
|
</secondaryStorages>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<vlans>
|
<!-- <vlans>
|
||||||
<vlan>
|
<vlan>
|
||||||
<zoneId>1</zoneId>
|
<zoneId>1</zoneId>
|
||||||
<vlanId>30</vlanId>
|
<vlanId>30</vlanId>
|
||||||
@ -73,7 +73,7 @@
|
|||||||
<netmask>255.255.255.0</netmask>
|
<netmask>255.255.255.0</netmask>
|
||||||
<ipAddressRange>10.91.30.160-10.91.30.179</ipAddressRange>
|
<ipAddressRange>10.91.30.160-10.91.30.179</ipAddressRange>
|
||||||
</vlan>
|
</vlan>
|
||||||
</vlans>
|
</vlans>-->
|
||||||
<!--
|
<!--
|
||||||
<vlan>
|
<vlan>
|
||||||
<zoneId>1</zoneId>
|
<zoneId>1</zoneId>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user