Skip to content

Commit 0ad7424

Browse files
authored
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 <[email protected]> * import order Signed-off-by: Abhishek Kumar <[email protected]> * set clusterid only for ListVMsCmdByAdmin Signed-off-by: Abhishek Kumar <[email protected]>
1 parent fe1ddfb commit 0ad7424

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

Diff for: api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.vm;
1818

19-
import org.apache.log4j.Logger;
20-
2119
import org.apache.cloudstack.api.APICommand;
2220
import org.apache.cloudstack.api.ApiConstants;
2321
import org.apache.cloudstack.api.Parameter;
2422
import org.apache.cloudstack.api.ResponseObject.ResponseView;
2523
import org.apache.cloudstack.api.command.admin.AdminCmd;
2624
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
25+
import org.apache.cloudstack.api.response.ClusterResponse;
2726
import org.apache.cloudstack.api.response.HostResponse;
2827
import org.apache.cloudstack.api.response.PodResponse;
2928
import org.apache.cloudstack.api.response.StoragePoolResponse;
3029
import org.apache.cloudstack.api.response.UserVmResponse;
30+
import org.apache.log4j.Logger;
3131

3232
import com.cloud.vm.VirtualMachine;
3333

@@ -52,6 +52,10 @@ public class ListVMsCmdByAdmin extends ListVMsCmd implements AdminCmd {
5252
description="the storage ID where vm's volumes belong to")
5353
private Long storageId;
5454

55+
@Parameter(name = ApiConstants.CLUSTER_ID, type = CommandType.UUID, entityType = ClusterResponse.class,
56+
description = "the cluster ID", since = "4.16.0")
57+
private Long clusterId;
58+
5559

5660
/////////////////////////////////////////////////////
5761
/////////////////// Accessors ///////////////////////
@@ -69,4 +73,7 @@ public Long getStorageId() {
6973
return storageId;
7074
}
7175

76+
public Long getClusterId() {
77+
return clusterId;
78+
}
7279
}

Diff for: engine/schema/src/main/resources/META-INF/db/schema-41520to41600.sql

+1
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ SELECT
456456
`host`.`id` AS `host_id`,
457457
`host`.`uuid` AS `host_uuid`,
458458
`host`.`name` AS `host_name`,
459+
`host`.`cluster_id` AS `cluster_id`,
459460
`vm_template`.`id` AS `template_id`,
460461
`vm_template`.`uuid` AS `template_uuid`,
461462
`vm_template`.`name` AS `template_name`,

Diff for: server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030

3131
import javax.inject.Inject;
3232

33-
import com.cloud.resource.icon.dao.ResourceIconDao;
34-
import com.cloud.server.ResourceManagerUtil;
35-
import com.cloud.storage.dao.VMTemplateDetailsDao;
36-
import com.cloud.vm.VirtualMachineManager;
3733
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
3834
import org.apache.cloudstack.affinity.AffinityGroupDomainMapVO;
3935
import org.apache.cloudstack.affinity.AffinityGroupResponse;
@@ -62,6 +58,7 @@
6258
import org.apache.cloudstack.api.command.admin.storage.ListStorageTagsCmd;
6359
import org.apache.cloudstack.api.command.admin.template.ListTemplatesCmdByAdmin;
6460
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
61+
import org.apache.cloudstack.api.command.admin.vm.ListVMsCmdByAdmin;
6562
import org.apache.cloudstack.api.command.admin.zone.ListZonesCmdByAdmin;
6663
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
6764
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
@@ -206,6 +203,8 @@
206203
import com.cloud.projects.dao.ProjectDao;
207204
import com.cloud.projects.dao.ProjectInvitationDao;
208205
import com.cloud.resource.ResourceManager;
206+
import com.cloud.resource.icon.dao.ResourceIconDao;
207+
import com.cloud.server.ResourceManagerUtil;
209208
import com.cloud.server.ResourceMetaDataService;
210209
import com.cloud.server.ResourceTag;
211210
import com.cloud.server.ResourceTag.ResourceObjectType;
@@ -224,6 +223,7 @@
224223
import com.cloud.storage.Volume;
225224
import com.cloud.storage.dao.StoragePoolTagsDao;
226225
import com.cloud.storage.dao.VMTemplateDao;
226+
import com.cloud.storage.dao.VMTemplateDetailsDao;
227227
import com.cloud.tags.ResourceTagVO;
228228
import com.cloud.tags.dao.ResourceTagDao;
229229
import com.cloud.template.VirtualMachineTemplate.State;
@@ -251,6 +251,7 @@
251251
import com.cloud.vm.UserVmVO;
252252
import com.cloud.vm.VMInstanceVO;
253253
import com.cloud.vm.VirtualMachine;
254+
import com.cloud.vm.VirtualMachineManager;
254255
import com.cloud.vm.VmDetailConstants;
255256
import com.cloud.vm.dao.DomainRouterDao;
256257
import com.cloud.vm.dao.UserVmDao;
@@ -986,10 +987,14 @@ private Pair<List<UserVmJoinVO>, Integer> searchForUserVMsInternal(ListVMsCmd cm
986987
Object securityGroupId = cmd.getSecurityGroupId();
987988
Object isHaEnabled = cmd.getHaEnabled();
988989
Object pod = null;
990+
Long clusterId = null;
989991
Object hostId = null;
990992
Object storageId = null;
991993
if (_accountMgr.isRootAdmin(caller.getId())) {
992994
pod = cmd.getPodId();
995+
if (cmd instanceof ListVMsCmdByAdmin) {
996+
clusterId = ((ListVMsCmdByAdmin)cmd).getClusterId();
997+
}
993998
hostId = cmd.getHostId();
994999
storageId = cmd.getStorageId();
9951000
}
@@ -1002,6 +1007,7 @@ private Pair<List<UserVmJoinVO>, Integer> searchForUserVMsInternal(ListVMsCmd cm
10021007
sb.and("stateNIN", sb.entity().getState(), SearchCriteria.Op.NIN);
10031008
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
10041009
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
1010+
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
10051011
sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
10061012
sb.and("hostIdEQ", sb.entity().getHostId(), SearchCriteria.Op.EQ);
10071013
sb.and("templateId", sb.entity().getTemplateId(), SearchCriteria.Op.EQ);
@@ -1175,6 +1181,10 @@ private Pair<List<UserVmJoinVO>, Integer> searchForUserVMsInternal(ListVMsCmd cm
11751181
}
11761182
}
11771183

1184+
if (clusterId != null) {
1185+
sc.setParameters("clusterId", clusterId);
1186+
}
1187+
11781188
if (hostId != null) {
11791189
sc.setParameters("hostIdEQ", hostId);
11801190
}

Diff for: server/src/main/java/com/cloud/api/query/vo/UserVmJoinVO.java

+7
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ public class UserVmJoinVO extends BaseViewWithTagInformationVO implements Contro
142142
@Column(name = "private_mac_address", updatable = true, nullable = true)
143143
private String privateMacAddress;
144144

145+
@Column(name = "cluster_id", updatable = true, nullable = false)
146+
private Long clusterId;
147+
145148
@Column(name = "pod_id", updatable = true, nullable = false)
146149
private Long podId;
147150

@@ -530,6 +533,10 @@ public Long getLastHostId() {
530533
return lastHostId;
531534
}
532535

536+
public Long getClusterId() {
537+
return clusterId;
538+
}
539+
533540
public Long getPodId() {
534541
return podId;
535542
}

0 commit comments

Comments
 (0)