api,server,engine/schema: admin listvm api clusterid (#5659)

* api,server,engine/schema: admin listvm api clusterid

Add clusterid parameter in listVirtualMachines API for admin

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>

* import order

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>

* set clusterid only for ListVMsCmdByAdmin

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
Abhishek Kumar 2021-11-04 08:47:42 +05:30 committed by GitHub
parent fe1ddfb1eb
commit 0ad742405c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 6 deletions

View File

@ -16,18 +16,18 @@
// under the License.
package org.apache.cloudstack.api.command.admin.vm;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ResponseObject.ResponseView;
import org.apache.cloudstack.api.command.admin.AdminCmd;
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.api.response.PodResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.log4j.Logger;
import com.cloud.vm.VirtualMachine;
@ -52,6 +52,10 @@ public class ListVMsCmdByAdmin extends ListVMsCmd implements AdminCmd {
description="the storage ID where vm's volumes belong to")
private Long storageId;
@Parameter(name = ApiConstants.CLUSTER_ID, type = CommandType.UUID, entityType = ClusterResponse.class,
description = "the cluster ID", since = "4.16.0")
private Long clusterId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -69,4 +73,7 @@ public class ListVMsCmdByAdmin extends ListVMsCmd implements AdminCmd {
return storageId;
}
public Long getClusterId() {
return clusterId;
}
}

View File

@ -456,6 +456,7 @@ SELECT
`host`.`id` AS `host_id`,
`host`.`uuid` AS `host_uuid`,
`host`.`name` AS `host_name`,
`host`.`cluster_id` AS `cluster_id`,
`vm_template`.`id` AS `template_id`,
`vm_template`.`uuid` AS `template_uuid`,
`vm_template`.`name` AS `template_name`,

View File

@ -30,10 +30,6 @@ import java.util.stream.Stream;
import javax.inject.Inject;
import com.cloud.resource.icon.dao.ResourceIconDao;
import com.cloud.server.ResourceManagerUtil;
import com.cloud.storage.dao.VMTemplateDetailsDao;
import com.cloud.vm.VirtualMachineManager;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.affinity.AffinityGroupDomainMapVO;
import org.apache.cloudstack.affinity.AffinityGroupResponse;
@ -62,6 +58,7 @@ import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
import org.apache.cloudstack.api.command.admin.storage.ListStorageTagsCmd;
import org.apache.cloudstack.api.command.admin.template.ListTemplatesCmdByAdmin;
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
import org.apache.cloudstack.api.command.admin.vm.ListVMsCmdByAdmin;
import org.apache.cloudstack.api.command.admin.zone.ListZonesCmdByAdmin;
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
@ -206,6 +203,8 @@ import com.cloud.projects.dao.ProjectAccountDao;
import com.cloud.projects.dao.ProjectDao;
import com.cloud.projects.dao.ProjectInvitationDao;
import com.cloud.resource.ResourceManager;
import com.cloud.resource.icon.dao.ResourceIconDao;
import com.cloud.server.ResourceManagerUtil;
import com.cloud.server.ResourceMetaDataService;
import com.cloud.server.ResourceTag;
import com.cloud.server.ResourceTag.ResourceObjectType;
@ -224,6 +223,7 @@ import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.Volume;
import com.cloud.storage.dao.StoragePoolTagsDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VMTemplateDetailsDao;
import com.cloud.tags.ResourceTagVO;
import com.cloud.tags.dao.ResourceTagDao;
import com.cloud.template.VirtualMachineTemplate.State;
@ -251,6 +251,7 @@ import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.VmDetailConstants;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.UserVmDao;
@ -986,10 +987,14 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
Object securityGroupId = cmd.getSecurityGroupId();
Object isHaEnabled = cmd.getHaEnabled();
Object pod = null;
Long clusterId = null;
Object hostId = null;
Object storageId = null;
if (_accountMgr.isRootAdmin(caller.getId())) {
pod = cmd.getPodId();
if (cmd instanceof ListVMsCmdByAdmin) {
clusterId = ((ListVMsCmdByAdmin)cmd).getClusterId();
}
hostId = cmd.getHostId();
storageId = cmd.getStorageId();
}
@ -1002,6 +1007,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
sb.and("stateNIN", sb.entity().getState(), SearchCriteria.Op.NIN);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
sb.and("hostIdEQ", sb.entity().getHostId(), SearchCriteria.Op.EQ);
sb.and("templateId", sb.entity().getTemplateId(), SearchCriteria.Op.EQ);
@ -1175,6 +1181,10 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
}
}
if (clusterId != null) {
sc.setParameters("clusterId", clusterId);
}
if (hostId != null) {
sc.setParameters("hostIdEQ", hostId);
}

View File

@ -142,6 +142,9 @@ public class UserVmJoinVO extends BaseViewWithTagInformationVO implements Contro
@Column(name = "private_mac_address", updatable = true, nullable = true)
private String privateMacAddress;
@Column(name = "cluster_id", updatable = true, nullable = false)
private Long clusterId;
@Column(name = "pod_id", updatable = true, nullable = false)
private Long podId;
@ -530,6 +533,10 @@ public class UserVmJoinVO extends BaseViewWithTagInformationVO implements Contro
return lastHostId;
}
public Long getClusterId() {
return clusterId;
}
public Long getPodId() {
return podId;
}