Skip to content

Commit bfad334

Browse files
authored
api: include tags in listvmsnapshots response (#3216)
This ensures that tags of a VM snapshot are listed in the UI, available in the list vmsnapshots API response. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent a75292e commit bfad334

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@
1818
package org.apache.cloudstack.api.response;
1919

2020
import java.util.Date;
21-
22-
import com.google.gson.annotations.SerializedName;
21+
import java.util.LinkedHashSet;
22+
import java.util.Set;
2323

2424
import org.apache.cloudstack.api.ApiConstants;
25-
import org.apache.cloudstack.api.BaseResponse;
25+
import org.apache.cloudstack.api.BaseResponseWithTagInformation;
2626
import org.apache.cloudstack.api.EntityReference;
2727

2828
import com.cloud.serializer.Param;
2929
import com.cloud.vm.snapshot.VMSnapshot;
30+
import com.google.gson.annotations.SerializedName;
3031

3132
@EntityReference(value = VMSnapshot.class)
32-
public class VMSnapshotResponse extends BaseResponse implements ControlledEntityResponse {
33+
public class VMSnapshotResponse extends BaseResponseWithTagInformation implements ControlledEntityResponse {
3334

3435
@SerializedName(ApiConstants.ID)
3536
@Param(description = "the ID of the vm snapshot")
@@ -99,6 +100,10 @@ public class VMSnapshotResponse extends BaseResponse implements ControlledEntity
99100
@Param(description = "the domain associated with the disk volume")
100101
private String domainName;
101102

103+
public VMSnapshotResponse() {
104+
tags = new LinkedHashSet<ResourceTagResponse>();
105+
}
106+
102107
@Override
103108
public String getObjectId() {
104109
return getId();
@@ -226,6 +231,9 @@ public void setDomainId(String domainId) {
226231
@Override
227232
public void setDomainName(String domainName) {
228233
this.domainName = domainName;
234+
}
229235

236+
public void setTags(Set<ResourceTagResponse> tags) {
237+
this.tags = tags;
230238
}
231239
}

server/src/main/java/com/cloud/api/ApiResponseHelper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,14 @@ public VMSnapshotResponse createVMSnapshotResponse(VMSnapshot vmSnapshot) {
619619
vmSnapshotResponse.setDomainName(domain.getName());
620620
}
621621

622+
List<? extends ResourceTag> tags = _resourceTagDao.listBy(vmSnapshot.getId(), ResourceObjectType.VMSnapshot);
623+
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
624+
for (ResourceTag tag : tags) {
625+
ResourceTagResponse tagResponse = createResourceTagResponse(tag, false);
626+
CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
627+
}
628+
vmSnapshotResponse.setTags(new HashSet<>(tagResponses));
629+
622630
vmSnapshotResponse.setCurrent(vmSnapshot.getCurrent());
623631
vmSnapshotResponse.setType(vmSnapshot.getType().toString());
624632
vmSnapshotResponse.setObjectName("vmsnapshot");

0 commit comments

Comments
 (0)