Skip to content

Commit c756e43

Browse files
authored
List volumes by service offering id (#9211)
* Allow listing of volumes by service offering id * Address comments
1 parent 4de975f commit c756e43

File tree

4 files changed

+84
-5
lines changed

4 files changed

+84
-5
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.cloudstack.api.response.HostResponse;
3232
import org.apache.cloudstack.api.response.ListResponse;
3333
import org.apache.cloudstack.api.response.PodResponse;
34+
import org.apache.cloudstack.api.response.ServiceOfferingResponse;
3435
import org.apache.cloudstack.api.response.StoragePoolResponse;
3536
import org.apache.cloudstack.api.response.UserVmResponse;
3637
import org.apache.cloudstack.api.response.VolumeResponse;
@@ -82,6 +83,12 @@ public class ListVolumesCmd extends BaseListRetrieveOnlyResourceCountCmd impleme
8283
RoleType.Admin})
8384
private String storageId;
8485

86+
@Parameter(name = ApiConstants.SERVICE_OFFERING_ID, type = CommandType.UUID,
87+
entityType = ServiceOfferingResponse.class,
88+
description = "list volumes by disk offering of a service offering. If both service offering and " +
89+
"disk offering are passed, service offering is ignored", since = "4.19.1")
90+
private Long serviceOfferingId;
91+
8592
@Parameter(name = ApiConstants.DISK_OFFERING_ID, type = CommandType.UUID, entityType = DiskOfferingResponse.class, description = "list volumes by disk offering", since = "4.4")
8693
private Long diskOfferingId;
8794

@@ -123,6 +130,10 @@ public Long getPodId() {
123130
return podId;
124131
}
125132

133+
public Long getServiceOfferingId() {
134+
return serviceOfferingId;
135+
}
136+
126137
public Long getDiskOfferingId() {
127138
return diskOfferingId;
128139
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,7 +2406,8 @@ private Pair<List<Long>, Integer> searchForVolumeIdsAndCount(ListVolumesCmd cmd)
24062406
Map<String, String> tags = cmd.getTags();
24072407
String storageId = cmd.getStorageId();
24082408
Long clusterId = cmd.getClusterId();
2409-
Long diskOffId = cmd.getDiskOfferingId();
2409+
Long serviceOfferingId = cmd.getServiceOfferingId();
2410+
Long diskOfferingId = cmd.getDiskOfferingId();
24102411
Boolean display = cmd.getDisplay();
24112412
String state = cmd.getState();
24122413
boolean shouldListSystemVms = shouldListSystemVms(cmd, caller.getId());
@@ -2416,6 +2417,13 @@ private Pair<List<Long>, Integer> searchForVolumeIdsAndCount(ListVolumesCmd cmd)
24162417

24172418
List<Long> ids = getIdsListFromCmd(cmd.getId(), cmd.getIds());
24182419

2420+
if (diskOfferingId == null && serviceOfferingId != null) {
2421+
ServiceOfferingVO serviceOffering = _srvOfferingDao.findById(serviceOfferingId);
2422+
if (serviceOffering != null) {
2423+
diskOfferingId = serviceOffering.getDiskOfferingId();
2424+
}
2425+
}
2426+
24192427
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null);
24202428
accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
24212429
Long domainId = domainIdRecursiveListProject.first();
@@ -2546,8 +2554,8 @@ private Pair<List<Long>, Integer> searchForVolumeIdsAndCount(ListVolumesCmd cmd)
25462554
}
25472555
}
25482556

2549-
if (diskOffId != null) {
2550-
sc.setParameters("diskOfferingId", diskOffId);
2557+
if (diskOfferingId != null) {
2558+
sc.setParameters("diskOfferingId", diskOfferingId);
25512559
}
25522560

25532561
if (id != null) {

ui/src/components/view/SearchView.vue

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export default {
285285
}
286286
if (['zoneid', 'domainid', 'imagestoreid', 'storageid', 'state', 'account', 'hypervisor', 'level',
287287
'clusterid', 'podid', 'groupid', 'entitytype', 'accounttype', 'systemvmtype', 'scope', 'provider',
288-
'type'].includes(item)
288+
'type', 'serviceofferingid', 'diskofferingid'].includes(item)
289289
) {
290290
type = 'list'
291291
} else if (item === 'tags') {
@@ -397,6 +397,8 @@ export default {
397397
let podIndex = -1
398398
let clusterIndex = -1
399399
let groupIndex = -1
400+
let serviceOfferingIndex = -1
401+
let diskOfferingIndex = -1
400402
401403
if (arrayField.includes('type')) {
402404
if (this.$route.path === '/alert') {
@@ -464,6 +466,18 @@ export default {
464466
promises.push(await this.fetchInstanceGroups(searchKeyword))
465467
}
466468
469+
if (arrayField.includes('serviceofferingid')) {
470+
serviceOfferingIndex = this.fields.findIndex(item => item.name === 'serviceofferingid')
471+
this.fields[serviceOfferingIndex].loading = true
472+
promises.push(await this.fetchServiceOfferings(searchKeyword))
473+
}
474+
475+
if (arrayField.includes('diskofferingid')) {
476+
diskOfferingIndex = this.fields.findIndex(item => item.name === 'diskofferingid')
477+
this.fields[diskOfferingIndex].loading = true
478+
promises.push(await this.fetchDiskOfferings(searchKeyword))
479+
}
480+
467481
Promise.all(promises).then(response => {
468482
if (typeIndex > -1) {
469483
const types = response.filter(item => item.type === 'type')
@@ -525,6 +539,20 @@ export default {
525539
this.fields[groupIndex].opts = this.sortArray(groups[0].data)
526540
}
527541
}
542+
543+
if (serviceOfferingIndex > -1) {
544+
const serviceOfferings = response.filter(item => item.type === 'serviceofferingid')
545+
if (serviceOfferings && serviceOfferings.length > 0) {
546+
this.fields[serviceOfferingIndex].opts = this.sortArray(serviceOfferings[0].data)
547+
}
548+
}
549+
550+
if (diskOfferingIndex > -1) {
551+
const diskOfferings = response.filter(item => item.type === 'diskofferingid')
552+
if (diskOfferings && diskOfferings.length > 0) {
553+
this.fields[diskOfferingIndex].opts = this.sortArray(diskOfferings[0].data)
554+
}
555+
}
528556
}).finally(() => {
529557
if (typeIndex > -1) {
530558
this.fields[typeIndex].loading = false
@@ -550,6 +578,12 @@ export default {
550578
if (groupIndex > -1) {
551579
this.fields[groupIndex].loading = false
552580
}
581+
if (serviceOfferingIndex > -1) {
582+
this.fields[serviceOfferingIndex].loading = false
583+
}
584+
if (diskOfferingIndex > -1) {
585+
this.fields[diskOfferingIndex].loading = false
586+
}
553587
this.fillFormFieldValues()
554588
})
555589
},
@@ -699,6 +733,32 @@ export default {
699733
})
700734
})
701735
},
736+
fetchServiceOfferings (searchKeyword) {
737+
return new Promise((resolve, reject) => {
738+
api('listServiceOfferings', { listAll: true, keyword: searchKeyword }).then(json => {
739+
const serviceOfferings = json.listserviceofferingsresponse.serviceoffering
740+
resolve({
741+
type: 'serviceofferingid',
742+
data: serviceOfferings
743+
})
744+
}).catch(error => {
745+
reject(error.response.headers['x-description'])
746+
})
747+
})
748+
},
749+
fetchDiskOfferings (searchKeyword) {
750+
return new Promise((resolve, reject) => {
751+
api('listDiskOfferings', { listAll: true, keyword: searchKeyword }).then(json => {
752+
const diskOfferings = json.listdiskofferingsresponse.diskoffering
753+
resolve({
754+
type: 'diskofferingid',
755+
data: diskOfferings
756+
})
757+
}).catch(error => {
758+
reject(error.response.headers['x-description'])
759+
})
760+
})
761+
},
702762
fetchAlertTypes () {
703763
if (this.alertTypes.length > 0) {
704764
return new Promise((resolve, reject) => {

ui/src/config/section/storage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default {
9191
}
9292
],
9393
searchFilters: () => {
94-
var filters = ['name', 'zoneid', 'domainid', 'account', 'state', 'tags']
94+
var filters = ['name', 'zoneid', 'domainid', 'account', 'state', 'tags', 'serviceofferingid', 'diskofferingid']
9595
if (['Admin', 'DomainAdmin'].includes(store.getters.userInfo.roletype)) {
9696
filters.push('storageid')
9797
}

0 commit comments

Comments
 (0)