Skip to content

Commit f489439

Browse files
authored
api: add zone, vm name params in listVmSnapshot response (#4604)
* api: add zone, vm name params in listVmSnaphots response Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 06b5bd2 commit f489439

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import java.util.LinkedHashSet;
2222
import java.util.Set;
2323

24-
import com.cloud.hypervisor.Hypervisor;
2524
import org.apache.cloudstack.api.ApiConstants;
2625
import org.apache.cloudstack.api.BaseResponseWithTagInformation;
2726
import org.apache.cloudstack.api.EntityReference;
2827

28+
import com.cloud.hypervisor.Hypervisor;
2929
import com.cloud.serializer.Param;
3030
import com.cloud.vm.snapshot.VMSnapshot;
3131
import com.google.gson.annotations.SerializedName;
@@ -57,9 +57,17 @@ public class VMSnapshotResponse extends BaseResponseWithTagInformation implement
5757
@Param(description = "the Zone ID of the vm snapshot")
5858
private String zoneId;
5959

60+
@SerializedName(ApiConstants.ZONE_NAME)
61+
@Param(description = "the Zone name of the vm snapshot", since = "4.15.1")
62+
private String zoneName;
63+
6064
@SerializedName(ApiConstants.VIRTUAL_MACHINE_ID)
6165
@Param(description = "the vm ID of the vm snapshot")
62-
private String virtualMachineid;
66+
private String virtualMachineId;
67+
68+
@SerializedName(ApiConstants.VIRTUAL_MACHINE_NAME)
69+
@Param(description = "the vm name of the vm snapshot", since = "4.15.1")
70+
private String virtualMachineName;
6371

6472
@SerializedName("parent")
6573
@Param(description = "the parent ID of the vm snapshot")
@@ -154,12 +162,28 @@ public void setZoneId(String zoneId) {
154162
this.zoneId = zoneId;
155163
}
156164

157-
public String getVirtualMachineid() {
158-
return virtualMachineid;
165+
public String getZoneName() {
166+
return zoneName;
167+
}
168+
169+
public void setZoneName(String zoneName) {
170+
this.zoneName = zoneName;
171+
}
172+
173+
public String getVirtualMachineId() {
174+
return virtualMachineId;
175+
}
176+
177+
public void setVirtualMachineId(String virtualMachineId) {
178+
this.virtualMachineId = virtualMachineId;
179+
}
180+
181+
public String getVirtualMachineName() {
182+
return virtualMachineName;
159183
}
160184

161-
public void setVirtualMachineid(String virtualMachineid) {
162-
this.virtualMachineid = virtualMachineid;
185+
public void setVirtualMachineName(String virtualMachineName) {
186+
this.virtualMachineName = virtualMachineName;
163187
}
164188

165189
public void setName(String name) {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// under the License.
1717
package com.cloud.api;
1818

19+
import static com.cloud.utils.NumbersUtil.toHumanReadableSize;
20+
1921
import java.text.DecimalFormat;
2022
import java.util.ArrayList;
2123
import java.util.Calendar;
@@ -349,8 +351,7 @@
349351
import com.cloud.vm.snapshot.VMSnapshot;
350352
import com.cloud.vm.snapshot.VMSnapshotVO;
351353
import com.cloud.vm.snapshot.dao.VMSnapshotDao;
352-
353-
import static com.cloud.utils.NumbersUtil.toHumanReadableSize;
354+
import com.google.common.base.Strings;
354355

355356
public class ApiResponseHelper implements ResponseGenerator {
356357

@@ -621,11 +622,13 @@ public VMSnapshotResponse createVMSnapshotResponse(VMSnapshot vmSnapshot) {
621622
vmSnapshotResponse.setDisplayName(vmSnapshot.getDisplayName());
622623
UserVm vm = ApiDBUtils.findUserVmById(vmSnapshot.getVmId());
623624
if (vm != null) {
624-
vmSnapshotResponse.setVirtualMachineid(vm.getUuid());
625+
vmSnapshotResponse.setVirtualMachineId(vm.getUuid());
626+
vmSnapshotResponse.setVirtualMachineName(Strings.isNullOrEmpty(vm.getDisplayName()) ? vm.getHostName() : vm.getDisplayName());
625627
vmSnapshotResponse.setHypervisor(vm.getHypervisorType());
626628
DataCenterVO datacenter = ApiDBUtils.findZoneById(vm.getDataCenterId());
627629
if (datacenter != null) {
628630
vmSnapshotResponse.setZoneId(datacenter.getUuid());
631+
vmSnapshotResponse.setZoneName(datacenter.getName());
629632
}
630633
}
631634
if (vmSnapshot.getParent() != null) {

0 commit comments

Comments
 (0)