Skip to content

Commit 488811f

Browse files
Pearl1594dhslove
authored andcommitted
List only VMs associated to a userdata (apache#10569)
* List only VMs associated to a userdata * add since param
1 parent df5e1f9 commit 488811f

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.apache.cloudstack.api.response.SecurityGroupResponse;
4242
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
4343
import org.apache.cloudstack.api.response.TemplateResponse;
44+
import org.apache.cloudstack.api.response.UserDataResponse;
4445
import org.apache.cloudstack.api.response.UserResponse;
4546
import org.apache.cloudstack.api.response.UserVmResponse;
4647
import org.apache.cloudstack.api.response.VpcResponse;
@@ -149,6 +150,9 @@ public class ListVMsCmd extends BaseListRetrieveOnlyResourceCountCmd implements
149150
@Parameter(name = ApiConstants.USER_DATA, type = CommandType.BOOLEAN, description = "Whether to return the VMs' user data or not. By default, user data will not be returned.", since = "4.18.0.0")
150151
private Boolean showUserData;
151152

153+
@Parameter(name = ApiConstants.USER_DATA_ID, type = CommandType.UUID, entityType = UserDataResponse.class, required = false, description = "the instances by userdata", since = "4.20.1")
154+
private Long userdataId;
155+
152156
/////////////////////////////////////////////////////
153157
/////////////////// Accessors ///////////////////////
154158
/////////////////////////////////////////////////////
@@ -243,6 +247,10 @@ protected boolean isViewDetailsEmpty() {
243247
return CollectionUtils.isEmpty(viewDetails);
244248
}
245249

250+
public Long getUserdataId() {
251+
return userdataId;
252+
}
253+
246254
public EnumSet<VMDetails> getDetails() throws InvalidParameterValueException {
247255
if (isViewDetailsEmpty()) {
248256
if (_queryService.ReturnVmStatsOnVmList.value()) {

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,7 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
13111311
Long storageId = null;
13121312
StoragePoolVO pool = null;
13131313
Long userId = cmd.getUserId();
1314+
Long userdataId = cmd.getUserdataId();
13141315
Map<String, String> tags = cmd.getTags();
13151316

13161317
boolean isAdmin = false;
@@ -1383,6 +1384,10 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
13831384
userVmSearchBuilder.and("templateId", userVmSearchBuilder.entity().getTemplateId(), Op.EQ);
13841385
}
13851386

1387+
if (userdataId != null) {
1388+
userVmSearchBuilder.and("userdataId", userVmSearchBuilder.entity().getUserDataId(), Op.EQ);
1389+
}
1390+
13861391
if (hypervisor != null) {
13871392
userVmSearchBuilder.and("hypervisorType", userVmSearchBuilder.entity().getHypervisorType(), Op.EQ);
13881393
}
@@ -1575,6 +1580,10 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
15751580
userVmSearchCriteria.setParameters("templateId", templateId);
15761581
}
15771582

1583+
if (userdataId != null) {
1584+
userVmSearchCriteria.setParameters("userdataId", userdataId);
1585+
}
1586+
15781587
if (display != null) {
15791588
userVmSearchCriteria.setParameters("display", display);
15801589
}

ui/src/config/section/compute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ export default {
10111011
related: [{
10121012
name: 'vm',
10131013
title: 'label.instances',
1014-
param: 'userdata'
1014+
param: 'userdataid'
10151015
}],
10161016
tabs: [
10171017
{

0 commit comments

Comments
 (0)