Skip to content

Commit 7d6af6c

Browse files
committed
api,ui: allow filtering vms by arch
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 5348655 commit 7d6af6c

7 files changed

Lines changed: 39 additions & 3 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ public class ListVMsCmd extends BaseListRetrieveOnlyResourceCountCmd implements
149149
@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")
150150
private Boolean showUserData;
151151

152+
@Parameter(name = ApiConstants.ARCH, type = CommandType.STRING,
153+
description = "CPU arch of the VM",
154+
since = "4.20.1")
155+
private String arch;
156+
152157
/////////////////////////////////////////////////////
153158
/////////////////// Accessors ///////////////////////
154159
/////////////////////////////////////////////////////
@@ -284,6 +289,10 @@ public Boolean getVnf() {
284289
return isVnf;
285290
}
286291

292+
public String getArch() {
293+
return arch;
294+
}
295+
287296
/////////////////////////////////////////////////////
288297
/////////////// API Implementation///////////////////
289298
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/response/UserVmResponse.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
import org.apache.cloudstack.api.ApiConstants;
3232
import org.apache.cloudstack.api.BaseResponseWithTagInformation;
3333
import org.apache.cloudstack.api.EntityReference;
34+
import org.apache.commons.collections.CollectionUtils;
3435

3536
import com.cloud.network.router.VirtualRouter;
3637
import com.cloud.serializer.Param;
3738
import com.cloud.uservm.UserVm;
3839
import com.cloud.vm.VirtualMachine;
3940
import com.google.gson.annotations.SerializedName;
40-
import org.apache.commons.collections.CollectionUtils;
4141

4242
@SuppressWarnings("unused")
4343
@EntityReference(value = {VirtualMachine.class, UserVm.class, VirtualRouter.class})
@@ -396,6 +396,10 @@ public class UserVmResponse extends BaseResponseWithTagInformation implements Co
396396
@Param(description = "User VM type", since = "4.20.0")
397397
private String vmType;
398398

399+
@SerializedName(ApiConstants.ARCH)
400+
@Param(description = "CPU arch of the VM", since = "4.20.1")
401+
private String arch;
402+
399403
public UserVmResponse() {
400404
securityGroupList = new LinkedHashSet<>();
401405
nics = new TreeSet<>(Comparator.comparingInt(x -> Integer.parseInt(x.getDeviceId())));
@@ -1169,4 +1173,12 @@ public String getVmType() {
11691173
public void setIpAddress(String ipAddress) {
11701174
this.ipAddress = ipAddress;
11711175
}
1176+
1177+
public String getArch() {
1178+
return arch;
1179+
}
1180+
1181+
public void setArch(String arch) {
1182+
this.arch = arch;
1183+
}
11721184
}

engine/schema/src/main/resources/META-INF/db/views/cloud.user_vm_view.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ SELECT
8383
`iso`.`uuid` AS `iso_uuid`,
8484
`iso`.`name` AS `iso_name`,
8585
`iso`.`display_text` AS `iso_display_text`,
86+
`vm_template`.`arch` AS `arch`,
8687
`service_offering`.`id` AS `service_offering_id`,
8788
`service_offering`.`uuid` AS `service_offering_uuid`,
8889
`disk_offering`.`uuid` AS `disk_offering_uuid`,

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,7 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
12981298
StoragePoolVO pool = null;
12991299
Long userId = cmd.getUserId();
13001300
Map<String, String> tags = cmd.getTags();
1301+
final String arch = cmd.getArch();
13011302

13021303
boolean isAdmin = false;
13031304
boolean isRootAdmin = false;
@@ -1521,8 +1522,10 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
15211522
}
15221523

15231524
Boolean isVnf = cmd.getVnf();
1524-
if (isVnf != null) {
1525+
boolean templateJoinNeeded = isVnf != null || StringUtils.isNoneBlank(arch);
1526+
if (templateJoinNeeded) {
15251527
SearchBuilder<VMTemplateVO> templateSearch = _templateDao.createSearchBuilder();
1528+
templateSearch.and("templateArch", templateSearch.entity().getArch(), Op.EQ);
15261529
templateSearch.and("templateTypeEQ", templateSearch.entity().getTemplateType(), Op.EQ);
15271530
templateSearch.and("templateTypeNEQ", templateSearch.entity().getTemplateType(), Op.NEQ);
15281531

@@ -1647,6 +1650,9 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
16471650
userVmSearchCriteria.setJoinParameters("vmTemplate", "templateTypeNEQ", TemplateType.VNF);
16481651
}
16491652
}
1653+
if (StringUtils.isNotBlank(arch)) {
1654+
userVmSearchCriteria.setJoinParameters("vmTemplate", "templateArch", arch);
1655+
}
16501656

16511657
if (isRootAdmin) {
16521658
if (podId != null) {

server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
188188
userVmResponse.setInstanceName(userVm.getInstanceName());
189189
userVmResponse.setHostId(userVm.getHostUuid());
190190
userVmResponse.setHostName(userVm.getHostName());
191+
userVmResponse.setArch(userVm.getArch());
191192
}
192193
if (userVm.getHostStatus() != null) {
193194
userVmResponse.setHostControlState(ControlState.getControlState(userVm.getHostStatus(), userVm.getHostResourceState()).toString());

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ public class UserVmJoinVO extends BaseViewWithTagInformationVO implements Contro
439439
@Column(name = "delete_protection")
440440
protected Boolean deleteProtection;
441441

442+
@Column(name = "arch")
443+
protected String arch;
444+
442445

443446
public UserVmJoinVO() {
444447
// Empty constructor
@@ -977,4 +980,8 @@ public String getUserDataPolicy() {
977980
public String getUserDataDetails() {
978981
return userDataDetails;
979982
}
983+
984+
public String getArch() {
985+
return arch;
986+
}
980987
}

ui/src/config/section/compute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default {
7777
fields.push('zonename')
7878
return fields
7979
},
80-
searchFilters: ['name', 'zoneid', 'domainid', 'account', 'groupid', 'tags'],
80+
searchFilters: ['name', 'zoneid', 'domainid', 'account', 'groupid', 'arch', 'tags'],
8181
details: () => {
8282
var fields = ['name', 'displayname', 'id', 'state', 'ipaddress', 'ip6address', 'templatename', 'ostypename',
8383
'serviceofferingname', 'isdynamicallyscalable', 'haenable', 'hypervisor', 'boottype', 'bootmode', 'account',

0 commit comments

Comments
 (0)