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>
This commit is contained in:
Abhishek Kumar 2021-02-19 14:52:48 +05:30 committed by GitHub
parent 06b5bd2966
commit f489439a3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 9 deletions

View File

@ -21,11 +21,11 @@ import java.util.Date;
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 class VMSnapshotResponse extends BaseResponseWithTagInformation implement
this.zoneId = zoneId;
}
public String getVirtualMachineid() {
return virtualMachineid;
public String getZoneName() {
return zoneName;
}
public void setVirtualMachineid(String virtualMachineid) {
this.virtualMachineid = virtualMachineid;
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 setVirtualMachineName(String virtualMachineName) {
this.virtualMachineName = virtualMachineName;
}
public void setName(String name) {

View File

@ -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;
@ -349,8 +351,7 @@ import com.cloud.vm.dao.NicSecondaryIpVO;
import com.cloud.vm.snapshot.VMSnapshot;
import com.cloud.vm.snapshot.VMSnapshotVO;
import com.cloud.vm.snapshot.dao.VMSnapshotDao;
import static com.cloud.utils.NumbersUtil.toHumanReadableSize;
import com.google.common.base.Strings;
public class ApiResponseHelper implements ResponseGenerator {
@ -621,11 +622,13 @@ public class ApiResponseHelper implements ResponseGenerator {
vmSnapshotResponse.setDisplayName(vmSnapshot.getDisplayName());
UserVm vm = ApiDBUtils.findUserVmById(vmSnapshot.getVmId());
if (vm != null) {
vmSnapshotResponse.setVirtualMachineid(vm.getUuid());
vmSnapshotResponse.setVirtualMachineId(vm.getUuid());
vmSnapshotResponse.setVirtualMachineName(Strings.isNullOrEmpty(vm.getDisplayName()) ? vm.getHostName() : 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) {