diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java index fbcedaaeac0..5b3e607416b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java @@ -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; + } } diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41520to41600.sql b/engine/schema/src/main/resources/META-INF/db/schema-41520to41600.sql index ca4700ed09f..16a0dd7bfdf 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-41520to41600.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-41520to41600.sql @@ -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`, diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java index 1a4446b807e..971d409c5d2 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -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); } diff --git a/server/src/main/java/com/cloud/api/query/vo/UserVmJoinVO.java b/server/src/main/java/com/cloud/api/query/vo/UserVmJoinVO.java index 0ef33a919ab..2ce7e6c8572 100644 --- a/server/src/main/java/com/cloud/api/query/vo/UserVmJoinVO.java +++ b/server/src/main/java/com/cloud/api/query/vo/UserVmJoinVO.java @@ -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; }