Skip to content

Commit 02d0dca

Browse files
authored
List only VMs associated to a userdata (#10569)
* List only VMs associated to a userdata * add since param
1 parent 35e809e commit 02d0dca

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;
@@ -151,6 +152,9 @@ public class ListVMsCmd extends BaseListRetrieveOnlyResourceCountCmd implements
151152
@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")
152153
private Boolean showUserData;
153154

155+
@Parameter(name = ApiConstants.USER_DATA_ID, type = CommandType.UUID, entityType = UserDataResponse.class, required = false, description = "the instances by userdata", since = "4.20.1")
156+
private Long userdataId;
157+
154158
/////////////////////////////////////////////////////
155159
/////////////////// Accessors ///////////////////////
156160
/////////////////////////////////////////////////////
@@ -245,6 +249,10 @@ protected boolean isViewDetailsEmpty() {
245249
return CollectionUtils.isEmpty(viewDetails);
246250
}
247251

252+
public Long getUserdataId() {
253+
return userdataId;
254+
}
255+
248256
public EnumSet<VMDetails> getDetails() throws InvalidParameterValueException {
249257
if (isViewDetailsEmpty()) {
250258
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
@@ -1267,6 +1267,7 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
12671267
Long storageId = null;
12681268
StoragePoolVO pool = null;
12691269
Long userId = cmd.getUserId();
1270+
Long userdataId = cmd.getUserdataId();
12701271
Map<String, String> tags = cmd.getTags();
12711272

12721273
boolean isAdmin = false;
@@ -1339,6 +1340,10 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
13391340
userVmSearchBuilder.and("templateId", userVmSearchBuilder.entity().getTemplateId(), Op.EQ);
13401341
}
13411342

1343+
if (userdataId != null) {
1344+
userVmSearchBuilder.and("userdataId", userVmSearchBuilder.entity().getUserDataId(), Op.EQ);
1345+
}
1346+
13421347
if (hypervisor != null) {
13431348
userVmSearchBuilder.and("hypervisorType", userVmSearchBuilder.entity().getHypervisorType(), Op.EQ);
13441349
}
@@ -1531,6 +1536,10 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
15311536
userVmSearchCriteria.setParameters("templateId", templateId);
15321537
}
15331538

1539+
if (userdataId != null) {
1540+
userVmSearchCriteria.setParameters("userdataId", userdataId);
1541+
}
1542+
15341543
if (display != null) {
15351544
userVmSearchCriteria.setParameters("display", display);
15361545
}

ui/src/config/section/compute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ export default {
919919
related: [{
920920
name: 'vm',
921921
title: 'label.instances',
922-
param: 'userdata'
922+
param: 'userdataid'
923923
}],
924924
tabs: [
925925
{

0 commit comments

Comments
 (0)