diff --git a/api/src/com/cloud/api/ResponseGenerator.java b/api/src/com/cloud/api/ResponseGenerator.java index 838f030ba97..69f4628b84a 100755 --- a/api/src/com/cloud/api/ResponseGenerator.java +++ b/api/src/com/cloud/api/ResponseGenerator.java @@ -131,8 +131,6 @@ public interface ResponseGenerator { SnapshotPolicyResponse createSnapshotPolicyResponse(SnapshotPolicy policy); List createUserVmResponse(String objectName, UserVm... userVms); - - List createUserVmSummaryResponse(String objectName, UserVm... userVms); SystemVmResponse createSystemVmResponse(VirtualMachine systemVM); diff --git a/api/src/com/cloud/api/commands/VMsSummaryCmd.java b/api/src/com/cloud/api/commands/VMsSummaryCmd.java deleted file mode 100644 index a9ddab0e2af..00000000000 --- a/api/src/com/cloud/api/commands/VMsSummaryCmd.java +++ /dev/null @@ -1,178 +0,0 @@ -/** - * Copyright (C) 2011 Citrix, Inc. All rights reserved. - * - * This software is licensed under the GNU General Public License v3 or later. - * - * It is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -package com.cloud.api.commands; - -import java.util.List; - -import org.apache.log4j.Logger; - -import com.cloud.api.ApiConstants; -import com.cloud.api.BaseListCmd; -import com.cloud.api.Implementation; -import com.cloud.api.Parameter; -import com.cloud.api.response.ListResponse; -import com.cloud.api.response.UserVmResponse; -import com.cloud.async.AsyncJob; -import com.cloud.uservm.UserVm; - -@Implementation(description="List summary of the virtual machines owned by the account.", responseObject=UserVmResponse.class) -public class VMsSummaryCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(VMsSummaryCmd.class.getName()); - - private static final String s_name = "listvirtualmachinessummaryresponse"; - - ///////////////////////////////////////////////////// - //////////////// API parameters ///////////////////// - ///////////////////////////////////////////////////// - - @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account. Must be used with the domainId parameter.") - private String accountName; - - @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID. If used with the account parameter, lists virtual machines for the specified account in this domain.") - private Long domainId; - - @Parameter(name=ApiConstants.IS_RECURSIVE, type=CommandType.BOOLEAN, description="Must be used with domainId parameter. Defaults to false, but if true, lists all vms from the parent specified by the domain id till leaves.") - private Boolean recursive; - - @Parameter(name=ApiConstants.GROUP_ID, type=CommandType.LONG, description="the group ID") - private Long groupId; - - @Parameter(name=ApiConstants.HOST_ID, type=CommandType.LONG, description="the host ID") - private Long hostId; - - @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the ID of the virtual machine") - private Long id; - - @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="name of the virtual machine") - private String instanceName; - - @Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, description="the pod ID") - private Long podId; - - @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="state of the virtual machine") - private String state; - - @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the availability zone ID") - private Long zoneId; - - @Parameter(name=ApiConstants.FOR_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="list by network type; true if need to list vms using Virtual Network, false otherwise") - private Boolean forVirtualNetwork; - - @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, description="list by network id") - private Long networkId; - - @Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, description="the target hypervisor for the template") - private String hypervisor; - - @Parameter(name=ApiConstants.STORAGE_ID, type=CommandType.LONG, description="the storage ID where vm's volumes belong to") - private Long storageId; - - @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="list vms by project") - private Long projectId; - - ///////////////////////////////////////////////////// - /////////////////// Accessors /////////////////////// - ///////////////////////////////////////////////////// - - public String getAccountName() { - return accountName; - } - - public Long getDomainId() { - return domainId; - } - - public Long getGroupId() { - return groupId; - } - - public Long getHostId() { - return hostId; - } - - public Long getId() { - return id; - } - - public String getInstanceName() { - return instanceName; - } - - public Long getPodId() { - return podId; - } - - public String getState() { - return state; - } - - public Long getZoneId() { - return zoneId; - } - - public Boolean getForVirtualNetwork() { - return forVirtualNetwork; - } - - public void setForVirtualNetwork(Boolean forVirtualNetwork) { - this.forVirtualNetwork = forVirtualNetwork; - } - - public Long getNetworkId() { - return networkId; - } - - public Boolean isRecursive() { - return recursive; - } - - public String getHypervisor() { - return hypervisor; - } - - public Long getStorageId() { - return storageId; - } - - public Long getProjectId() { - return projectId; - } - - ///////////////////////////////////////////////////// - /////////////// API Implementation/////////////////// - ///////////////////////////////////////////////////// - @Override - public String getCommandName() { - return s_name; - } - - public AsyncJob.Type getInstanceType() { - return AsyncJob.Type.VirtualMachine; - } - - @Override - public void execute(){ - List result = _userVmService.searchForUserVMs(this); - ListResponse response = new ListResponse(); - List vmResponses = _responseGenerator.createUserVmSummaryResponse("virtualmachine", result.toArray(new UserVm[result.size()])); - response.setResponses(vmResponses); - response.setResponseName(getCommandName()); - this.setResponseObject(response); - } - -} diff --git a/api/src/com/cloud/vm/UserVmService.java b/api/src/com/cloud/vm/UserVmService.java index 38e14a36335..b6b37e681d8 100755 --- a/api/src/com/cloud/vm/UserVmService.java +++ b/api/src/com/cloud/vm/UserVmService.java @@ -38,7 +38,6 @@ import com.cloud.api.commands.RestoreVMCmd; import com.cloud.api.commands.StartVMCmd; import com.cloud.api.commands.UpdateVMCmd; import com.cloud.api.commands.UpgradeVMCmd; -import com.cloud.api.commands.VMsSummaryCmd; import com.cloud.dc.DataCenter; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -350,7 +349,6 @@ public interface UserVmService { * @return List of UserVMs. */ List searchForUserVMs(ListVMsCmd cmd); - List searchForUserVMs(VMsSummaryCmd cmd); HypervisorType getHypervisorTypeOfUserVM(long vmid); diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index aa9fcc0b54b..86d1bd0eda0 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -46,7 +46,6 @@ changeServiceForVirtualMachine=com.cloud.api.commands.UpgradeVMCmd;15 updateVirtualMachine=com.cloud.api.commands.UpdateVMCmd;15 recoverVirtualMachine=com.cloud.api.commands.RecoverVMCmd;7 listVirtualMachines=com.cloud.api.commands.ListVMsCmd;15 -listVMSummary=com.cloud.api.commands.VMsSummaryCmd;15 getVMPassword=com.cloud.api.commands.GetVMPasswordCmd;15 migrateVirtualMachine=com.cloud.api.commands.MigrateVMCmd;1 moveVirtualMachine=com.cloud.api.commands.MoveUserVMCmd;15 diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index e7a2d68a861..365192f3d28 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -1169,44 +1169,6 @@ public class ApiResponseHelper implements ResponseGenerator { } return vmResponses; } - - - @Override - public List createUserVmSummaryResponse(String objectName, UserVm... userVms) { - Account caller = UserContext.current().getCaller(); - boolean caller_is_admin = ((caller == null) || (caller.getType() == Account.ACCOUNT_TYPE_ADMIN)); - //initialize vmresponse from vmdatalist - List vmResponses = new ArrayList(); - for (UserVm userVm : userVms) { - UserVmResponse userVmResponse = new UserVmResponse(); - userVmResponse.setHypervisor(userVm.getHypervisorType().toString()); - userVmResponse.setId(userVm.getId()); - userVmResponse.setName(userVm.getInstanceName()); - userVmResponse.setDisplayName(userVm.getDisplayName()); - userVmResponse.setIpAddress(userVm.getPrivateIpAddress()); - userVmResponse.setHaEnable(userVm.isHaEnabled()); - - populateAccount(userVmResponse, userVm.getAccountId()); - populateDomain(userVmResponse, userVm.getDomainId()); - - userVmResponse.setCreated(userVm.getCreated()); - userVmResponse.setState(userVm.getState().toString()); - userVmResponse.setZoneId(userVm.getDataCenterIdToDeployIn()); - if (caller_is_admin){ - userVmResponse.setHostId(userVm.getHostId()); - //userVmResponse.setHostName(userVm.getHostName()); - } - userVmResponse.setTemplateId(userVm.getTemplateId()); - userVmResponse.setIsoId(userVm.getIsoId()); - userVmResponse.setServiceOfferingId(userVm.getServiceOfferingId()); - userVmResponse.setPassword(userVm.getPassword()); - - userVmResponse.setObjectName(objectName); - vmResponses.add(userVmResponse); - } - return vmResponses; - } - @Override diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index da0e17fc5fc..ecc4cd95d9c 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -71,7 +71,6 @@ import com.cloud.api.commands.RestoreVMCmd; import com.cloud.api.commands.StartVMCmd; import com.cloud.api.commands.UpdateVMCmd; import com.cloud.api.commands.UpgradeVMCmd; -import com.cloud.api.commands.VMsSummaryCmd; import com.cloud.async.AsyncJobExecutor; import com.cloud.async.AsyncJobManager; import com.cloud.async.AsyncJobVO; @@ -2885,119 +2884,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager throw new CloudRuntimeException("Failed to destroy vm with id " + vmId); } } - - @Override - public List searchForUserVMs(VMsSummaryCmd cmd) { - Account caller = UserContext.current().getCaller(); - Long domainId = cmd.getDomainId(); - String accountName = cmd.getAccountName(); - Boolean isRecursive = cmd.isRecursive(); - String hypervisor = cmd.getHypervisor(); - List permittedAccounts = new ArrayList(); - String path = null; - Long projectId = cmd.getProjectId(); - - if (isRecursive != null && isRecursive && domainId == null) { - throw new InvalidParameterValueException("Please enter a parent domain id for listing vms recursively"); - } - - if (domainId != null) { - // Verify if user is authorized to see instances belonging to the domain - DomainVO domain = _domainDao.findById(domainId); - if (domain == null) { - throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist"); - } - _accountMgr.checkAccess(caller, domain); - } - - boolean isAdmin = false; - - if (_accountMgr.isAdmin(caller.getType())) { - isAdmin = true; - if (accountName != null && domainId != null) { - Account account = _accountDao.findActiveAccount(accountName, domainId); - if (account == null) { - throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId); - } - permittedAccounts.add(caller.getId()); - } - - if (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { - if (isRecursive == null) { - DomainVO domain = _domainDao.findById(caller.getDomainId()); - path = domain.getPath(); - } - } - } else { - //regular user can't specify any other domain rather than his own - if (domainId != null && domainId.longValue() != caller.getDomainId()) { - throw new PermissionDeniedException("Caller is not authorised to see domain id=" + domainId + " entries"); - } - permittedAccounts.add(caller.getId()); - } - - if (isRecursive != null && isRecursive && isAdmin) { - if (isRecursive) { - DomainVO domain = _domainDao.findById(domainId); - path = domain.getPath(); - domainId = null; - } - } - - //set project information - if (projectId != null) { - permittedAccounts.clear(); - Project project = _projectMgr.getProject(projectId); - if (project == null) { - throw new InvalidParameterValueException("Unable to find project by id " + projectId); - } - if (!_projectMgr.canAccessProjectAccount(caller, project.getProjectAccountId())) { - throw new InvalidParameterValueException("Account " + caller + " can't access project id=" + projectId); - } - permittedAccounts.add(project.getProjectAccountId()); - } else { - permittedAccounts.addAll(_projectMgr.listPermittedProjectAccounts(caller.getId())); - } - - Criteria c = new Criteria("id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal()); - c.addCriteria(Criteria.KEYWORD, cmd.getKeyword()); - c.addCriteria(Criteria.ID, cmd.getId()); - c.addCriteria(Criteria.NAME, cmd.getInstanceName()); - c.addCriteria(Criteria.STATE, cmd.getState()); - c.addCriteria(Criteria.DATACENTERID, cmd.getZoneId()); - c.addCriteria(Criteria.GROUPID, cmd.getGroupId()); - c.addCriteria(Criteria.FOR_VIRTUAL_NETWORK, cmd.getForVirtualNetwork()); - c.addCriteria(Criteria.NETWORKID, cmd.getNetworkId()); - - if (domainId != null) { - c.addCriteria(Criteria.DOMAINID, domainId); - } - - if (path != null) { - c.addCriteria(Criteria.PATH, path); - } - - if (HypervisorType.getType(hypervisor) != HypervisorType.None) { - c.addCriteria(Criteria.HYPERVISOR, hypervisor); - } else if (hypervisor != null) { - throw new InvalidParameterValueException("Invalid HypervisorType " + hypervisor); - } - - // ignore these search requests if it's not an admin - if (isAdmin) { - c.addCriteria(Criteria.PODID, cmd.getPodId()); - c.addCriteria(Criteria.HOSTID, cmd.getHostId()); - c.addCriteria(Criteria.STORAGE_ID, cmd.getStorageId()); - } - - if (!permittedAccounts.isEmpty()) { - c.addCriteria(Criteria.ACCOUNTID, permittedAccounts.toArray()); - } - c.addCriteria(Criteria.ISADMIN, isAdmin); - - return searchForUserVMs(c); - } - @Override public List searchForUserVMs(ListVMsCmd cmd) { @@ -3593,5 +3479,4 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager s_logger.debug("Restore VM " + vmId + " with template " + root.getTemplateId() + " successfully"); return vm; } - }