mirror of https://github.com/apache/cloudstack.git
Merged in alena's changes
This commit is contained in:
parent
bbdc2b22ff
commit
05ce97f918
|
|
@ -355,6 +355,9 @@ public class ApiResponseHelper {
|
|||
}
|
||||
|
||||
public static UserVmResponse createUserVmResponse (UserVm userVm) {
|
||||
if (userVm.getPrivateIpAddress() == null) {
|
||||
return createUserVm2Response(userVm);
|
||||
}
|
||||
UserVmResponse userVmResponse = new UserVmResponse();
|
||||
Account acct = ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId()));
|
||||
//FIXME - this check should be done in searchForUserVm method in ManagementServerImpl;
|
||||
|
|
@ -476,6 +479,9 @@ public class ApiResponseHelper {
|
|||
}
|
||||
|
||||
public static SystemVmResponse createSystemVmResponse (VMInstanceVO systemVM) {
|
||||
if (systemVM.getPrivateIpAddress() == null) {
|
||||
return createSystemVm2Response(systemVM);
|
||||
}
|
||||
SystemVmResponse vmResponse = new SystemVmResponse();
|
||||
if (systemVM instanceof SystemVm) {
|
||||
SystemVm vm = (SystemVm)systemVM;
|
||||
|
|
@ -531,6 +537,9 @@ public class ApiResponseHelper {
|
|||
|
||||
|
||||
public static DomainRouterResponse createDomainRouterResponse (DomainRouter router) {
|
||||
if (router.getPrivateIpAddress() == null) {
|
||||
return createDomainRouter2Response(router);
|
||||
}
|
||||
DomainRouterResponse routerResponse = new DomainRouterResponse();
|
||||
routerResponse.setId(router.getId());
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.api.ApiResponseHelper;
|
||||
import com.cloud.api.BaseAsyncCreateCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
|
|
@ -36,15 +36,10 @@ import com.cloud.exception.InsufficientAddressCapacityException;
|
|||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.vm.InstanceGroupVO;
|
||||
|
||||
@Implementation(description="Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.")
|
||||
public class DeployVm2Cmd extends BaseAsyncCreateCmd {
|
||||
|
|
@ -161,127 +156,19 @@ public class DeployVm2Cmd extends BaseAsyncCreateCmd {
|
|||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
UserVm userVm = _userVmService.startVirtualMachine(this);
|
||||
|
||||
UserVmResponse response = new UserVmResponse();
|
||||
response.setId(userVm.getId());
|
||||
response.setName(userVm.getHostName());
|
||||
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.getHostName());
|
||||
} else {
|
||||
response.setDisplayName(userVm.getDisplayName());
|
||||
}
|
||||
|
||||
if (userVm.getState() != null) {
|
||||
response.setState(userVm.getState().toString());
|
||||
}
|
||||
|
||||
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()));
|
||||
|
||||
public void execute() throws ServerApiException, InvalidParameterValueException, PermissionDeniedException, InsufficientAddressCapacityException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException{
|
||||
UserVm result;
|
||||
result = _userVmService.startVirtualMachine(this);
|
||||
UserVmResponse response = ApiResponseHelper.createUserVm2Response(result);
|
||||
response.setPassword(password);
|
||||
response.setResponseName(getName());
|
||||
response.setObjectName("virtualmachine");
|
||||
this.setResponseObject(response);
|
||||
} catch (Exception ex) {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy virtual machine");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callCreate() throws ServerApiException, InvalidParameterValueException, PermissionDeniedException, InsufficientAddressCapacityException, InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException{
|
||||
try {
|
||||
UserVm vm = _userVmService.createVirtualMachine(this);
|
||||
if (vm != null) {
|
||||
this.setId(vm.getId());
|
||||
}
|
||||
} catch (ResourceUnavailableException ex) {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a vm");
|
||||
}
|
||||
|
||||
public void callCreate() throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
|
||||
UserVm vm = _userVmService.createVirtualMachine(this);
|
||||
this.setId(vm.getId());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue