From 3bc06ba4211eaede841426b0f221f35711763cac Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Wed, 20 Jan 2021 17:19:12 +0530 Subject: [PATCH 1/4] api: add zone, vm name params in listVmSnaphots response Signed-off-by: Abhishek Kumar --- .../api/response/VMSnapshotResponse.java | 36 +++++++++++++++---- .../java/com/cloud/api/ApiResponseHelper.java | 8 +++-- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/response/VMSnapshotResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/VMSnapshotResponse.java index f5d7dbd76b98..30709c4436fa 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/VMSnapshotResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/VMSnapshotResponse.java @@ -21,11 +21,11 @@ import java.util.LinkedHashSet; import java.util.Set; -import com.cloud.hypervisor.Hypervisor; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseResponseWithTagInformation; import org.apache.cloudstack.api.EntityReference; +import com.cloud.hypervisor.Hypervisor; import com.cloud.serializer.Param; import com.cloud.vm.snapshot.VMSnapshot; import com.google.gson.annotations.SerializedName; @@ -57,9 +57,17 @@ public class VMSnapshotResponse extends BaseResponseWithTagInformation implement @Param(description = "the Zone ID of the vm snapshot") private String zoneId; + @SerializedName(ApiConstants.ZONE_NAME) + @Param(description = "the Zone name of the vm snapshot", since = "4.15.1") + private String zoneName; + @SerializedName(ApiConstants.VIRTUAL_MACHINE_ID) @Param(description = "the vm ID of the vm snapshot") - private String virtualMachineid; + private String virtualMachineId; + + @SerializedName(ApiConstants.VIRTUAL_MACHINE_NAME) + @Param(description = "the vm name of the vm snapshot", since = "4.15.1") + private String virtualMachineName; @SerializedName("parent") @Param(description = "the parent ID of the vm snapshot") @@ -154,12 +162,28 @@ public void setZoneId(String zoneId) { this.zoneId = zoneId; } - public String getVirtualMachineid() { - return virtualMachineid; + public String getZoneName() { + return zoneName; + } + + public void setZoneName(String zoneName) { + this.zoneName = zoneName; + } + + public String getVirtualMachineId() { + return virtualMachineId; + } + + public void setVirtualMachineId(String virtualMachineId) { + this.virtualMachineId = virtualMachineId; + } + + public String getVirtualMachineName() { + return virtualMachineName; } - public void setVirtualMachineid(String virtualMachineid) { - this.virtualMachineid = virtualMachineid; + public void setVirtualMachineName(String virtualMachineName) { + this.virtualMachineName = virtualMachineName; } public void setName(String name) { diff --git a/server/src/main/java/com/cloud/api/ApiResponseHelper.java b/server/src/main/java/com/cloud/api/ApiResponseHelper.java index b03fa7dfd9dd..e1823b95950e 100644 --- a/server/src/main/java/com/cloud/api/ApiResponseHelper.java +++ b/server/src/main/java/com/cloud/api/ApiResponseHelper.java @@ -16,6 +16,8 @@ // under the License. package com.cloud.api; +import static com.cloud.utils.NumbersUtil.toHumanReadableSize; + import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Calendar; @@ -350,8 +352,6 @@ import com.cloud.vm.snapshot.VMSnapshotVO; import com.cloud.vm.snapshot.dao.VMSnapshotDao; -import static com.cloud.utils.NumbersUtil.toHumanReadableSize; - public class ApiResponseHelper implements ResponseGenerator { private static final Logger s_logger = Logger.getLogger(ApiResponseHelper.class); @@ -621,11 +621,13 @@ public VMSnapshotResponse createVMSnapshotResponse(VMSnapshot vmSnapshot) { vmSnapshotResponse.setDisplayName(vmSnapshot.getDisplayName()); UserVm vm = ApiDBUtils.findUserVmById(vmSnapshot.getVmId()); if (vm != null) { - vmSnapshotResponse.setVirtualMachineid(vm.getUuid()); + vmSnapshotResponse.setVirtualMachineId(vm.getUuid()); + vmSnapshotResponse.setVirtualMachineName(vm.getDisplayName()); vmSnapshotResponse.setHypervisor(vm.getHypervisorType()); DataCenterVO datacenter = ApiDBUtils.findZoneById(vm.getDataCenterId()); if (datacenter != null) { vmSnapshotResponse.setZoneId(datacenter.getUuid()); + vmSnapshotResponse.setZoneName(datacenter.getName()); } } if (vmSnapshot.getParent() != null) { From 7ae3b78c63421bb6c49feb842a9d42c2613a3f47 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 21 Jan 2021 10:52:45 +0530 Subject: [PATCH 2/4] display name can be empty Signed-off-by: Abhishek Kumar --- server/src/main/java/com/cloud/api/ApiResponseHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/cloud/api/ApiResponseHelper.java b/server/src/main/java/com/cloud/api/ApiResponseHelper.java index e1823b95950e..7229dc98f8be 100644 --- a/server/src/main/java/com/cloud/api/ApiResponseHelper.java +++ b/server/src/main/java/com/cloud/api/ApiResponseHelper.java @@ -622,7 +622,7 @@ public VMSnapshotResponse createVMSnapshotResponse(VMSnapshot vmSnapshot) { UserVm vm = ApiDBUtils.findUserVmById(vmSnapshot.getVmId()); if (vm != null) { vmSnapshotResponse.setVirtualMachineId(vm.getUuid()); - vmSnapshotResponse.setVirtualMachineName(vm.getDisplayName()); + vmSnapshotResponse.setVirtualMachineName(vm.getHostName()); vmSnapshotResponse.setHypervisor(vm.getHypervisorType()); DataCenterVO datacenter = ApiDBUtils.findZoneById(vm.getDataCenterId()); if (datacenter != null) { From bffd70ab4a2498e983b6c1d1f8cffec5edf3ca98 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 21 Jan 2021 12:38:19 +0530 Subject: [PATCH 3/4] prefer vm display name over hostname Signed-off-by: Abhishek Kumar --- server/src/main/java/com/cloud/api/ApiResponseHelper.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/src/main/java/com/cloud/api/ApiResponseHelper.java b/server/src/main/java/com/cloud/api/ApiResponseHelper.java index 7229dc98f8be..b3039240e650 100644 --- a/server/src/main/java/com/cloud/api/ApiResponseHelper.java +++ b/server/src/main/java/com/cloud/api/ApiResponseHelper.java @@ -351,6 +351,7 @@ import com.cloud.vm.snapshot.VMSnapshot; import com.cloud.vm.snapshot.VMSnapshotVO; import com.cloud.vm.snapshot.dao.VMSnapshotDao; +import com.google.common.base.Strings; public class ApiResponseHelper implements ResponseGenerator { @@ -622,6 +623,7 @@ public VMSnapshotResponse createVMSnapshotResponse(VMSnapshot vmSnapshot) { UserVm vm = ApiDBUtils.findUserVmById(vmSnapshot.getVmId()); if (vm != null) { vmSnapshotResponse.setVirtualMachineId(vm.getUuid()); + vmSnapshotResponse.setVirtualMachineName(Strings.isNullOrEmpty(vm.getDisplayName()) ? vm.getHostName() : vm.getDisplayName()); vmSnapshotResponse.setVirtualMachineName(vm.getHostName()); vmSnapshotResponse.setHypervisor(vm.getHypervisorType()); DataCenterVO datacenter = ApiDBUtils.findZoneById(vm.getDataCenterId()); From 5efc277824199065bde84c898da7e6b0baed5cf5 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 12 Feb 2021 15:38:36 +0530 Subject: [PATCH 4/4] fix Signed-off-by: Abhishek Kumar --- server/src/main/java/com/cloud/api/ApiResponseHelper.java | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/main/java/com/cloud/api/ApiResponseHelper.java b/server/src/main/java/com/cloud/api/ApiResponseHelper.java index b3039240e650..473c501b52f6 100644 --- a/server/src/main/java/com/cloud/api/ApiResponseHelper.java +++ b/server/src/main/java/com/cloud/api/ApiResponseHelper.java @@ -624,7 +624,6 @@ public VMSnapshotResponse createVMSnapshotResponse(VMSnapshot vmSnapshot) { if (vm != null) { vmSnapshotResponse.setVirtualMachineId(vm.getUuid()); vmSnapshotResponse.setVirtualMachineName(Strings.isNullOrEmpty(vm.getDisplayName()) ? vm.getHostName() : vm.getDisplayName()); - vmSnapshotResponse.setVirtualMachineName(vm.getHostName()); vmSnapshotResponse.setHypervisor(vm.getHypervisorType()); DataCenterVO datacenter = ApiDBUtils.findZoneById(vm.getDataCenterId()); if (datacenter != null) {