mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	CLOUDSTACK-9535: [API] listVMSnapshots improvement
This commit is contained in:
		
							parent
							
								
									9a8841d0d9
								
							
						
					
					
						commit
						f4a42ab0d7
					
				| @ -27,11 +27,12 @@ import com.cloud.exception.InsufficientServerCapacityException; | ||||
| import com.cloud.exception.ResourceAllocationException; | ||||
| import com.cloud.exception.ResourceUnavailableException; | ||||
| import com.cloud.uservm.UserVm; | ||||
| import com.cloud.utils.Pair; | ||||
| import com.cloud.vm.VirtualMachine; | ||||
| 
 | ||||
| public interface VMSnapshotService { | ||||
| 
 | ||||
|     List<? extends VMSnapshot> listVMSnapshots(ListVMSnapshotCmd cmd); | ||||
|     Pair<List<? extends VMSnapshot>, Integer> listVMSnapshots(ListVMSnapshotCmd cmd); | ||||
| 
 | ||||
|     VMSnapshot getVMSnapshotById(Long id); | ||||
| 
 | ||||
|  | ||||
| @ -28,6 +28,7 @@ import org.apache.cloudstack.api.response.ListResponse; | ||||
| import org.apache.cloudstack.api.response.UserVmResponse; | ||||
| import org.apache.cloudstack.api.response.VMSnapshotResponse; | ||||
| 
 | ||||
| import com.cloud.utils.Pair; | ||||
| import com.cloud.vm.snapshot.VMSnapshot; | ||||
| 
 | ||||
| @APICommand(name = "listVMSnapshot", description = "List virtual machine snapshot by conditions", responseObject = VMSnapshotResponse.class, since = "4.2.0", entityType = {VMSnapshot.class}, | ||||
| @ -69,15 +70,15 @@ public class ListVMSnapshotCmd extends BaseListTaggedResourcesCmd { | ||||
| 
 | ||||
|     @Override | ||||
|     public void execute() { | ||||
|         List<? extends VMSnapshot> result = _vmSnapshotService.listVMSnapshots(this); | ||||
|         Pair<List<? extends VMSnapshot>,Integer> result = _vmSnapshotService.listVMSnapshots(this); | ||||
|         ListResponse<VMSnapshotResponse> response = new ListResponse<VMSnapshotResponse>(); | ||||
|         List<VMSnapshotResponse> snapshotResponses = new ArrayList<VMSnapshotResponse>(); | ||||
|         for (VMSnapshot r : result) { | ||||
|         for (VMSnapshot r : result.first()) { | ||||
|             VMSnapshotResponse vmSnapshotResponse = _responseGenerator.createVMSnapshotResponse(r); | ||||
|             vmSnapshotResponse.setObjectName("vmSnapshot"); | ||||
|             snapshotResponses.add(vmSnapshotResponse); | ||||
|         } | ||||
|         response.setResponses(snapshotResponses); | ||||
|         response.setResponses(snapshotResponses, result.second()); | ||||
|         response.setResponseName(getCommandName()); | ||||
|         setResponseObject(response); | ||||
|     } | ||||
|  | ||||
| @ -194,6 +194,7 @@ import com.cloud.configuration.ResourceLimit; | ||||
| import com.cloud.dc.ClusterDetailsDao; | ||||
| import com.cloud.dc.ClusterVO; | ||||
| import com.cloud.dc.DataCenter; | ||||
| import com.cloud.dc.DataCenterVO; | ||||
| import com.cloud.dc.HostPodVO; | ||||
| import com.cloud.dc.Pod; | ||||
| import com.cloud.dc.StorageNetworkIpRange; | ||||
| @ -201,6 +202,7 @@ import com.cloud.dc.Vlan; | ||||
| import com.cloud.dc.Vlan.VlanType; | ||||
| import com.cloud.dc.VlanVO; | ||||
| import com.cloud.domain.Domain; | ||||
| import com.cloud.domain.DomainVO; | ||||
| import com.cloud.event.Event; | ||||
| import com.cloud.exception.InvalidParameterValueException; | ||||
| import com.cloud.exception.PermissionDeniedException; | ||||
| @ -552,6 +554,10 @@ public class ApiResponseHelper implements ResponseGenerator { | ||||
|         UserVm vm = ApiDBUtils.findUserVmById(vmSnapshot.getVmId()); | ||||
|         if (vm != null) { | ||||
|             vmSnapshotResponse.setVirtualMachineid(vm.getUuid()); | ||||
|             DataCenterVO datacenter = ApiDBUtils.findZoneById(vm.getDataCenterId()); | ||||
|             if (datacenter != null) { | ||||
|                 vmSnapshotResponse.setZoneId(datacenter.getUuid()); | ||||
|             } | ||||
|         } | ||||
|         if (vmSnapshot.getParent() != null) { | ||||
|             VMSnapshot vmSnapshotParent = ApiDBUtils.getVMSnapshotById(vmSnapshot.getParent()); | ||||
| @ -565,6 +571,16 @@ public class ApiResponseHelper implements ResponseGenerator { | ||||
|             vmSnapshotResponse.setProjectId(project.getUuid()); | ||||
|             vmSnapshotResponse.setProjectName(project.getName()); | ||||
|         } | ||||
|         Account account = ApiDBUtils.findAccountById(vmSnapshot.getAccountId()); | ||||
|         if (account != null) { | ||||
|             vmSnapshotResponse.setAccountName(account.getAccountName()); | ||||
|         } | ||||
|         DomainVO domain = ApiDBUtils.findDomainById(vmSnapshot.getDomainId()); | ||||
|         if (domain != null) { | ||||
|             vmSnapshotResponse.setDomainId(domain.getUuid()); | ||||
|             vmSnapshotResponse.setDomainName(domain.getName()); | ||||
|         } | ||||
| 
 | ||||
|         vmSnapshotResponse.setCurrent(vmSnapshot.getCurrent()); | ||||
|         vmSnapshotResponse.setType(vmSnapshot.getType().toString()); | ||||
|         vmSnapshotResponse.setObjectName("vmsnapshot"); | ||||
|  | ||||
| @ -163,7 +163,7 @@ public class VMSnapshotManagerImpl extends MutualExclusiveIdsManagerBase impleme | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public List<VMSnapshotVO> listVMSnapshots(ListVMSnapshotCmd cmd) { | ||||
|     public Pair<List<? extends VMSnapshot>, Integer> listVMSnapshots(ListVMSnapshotCmd cmd) { | ||||
|         Account caller = getCaller(); | ||||
|         List<Long> permittedAccounts = new ArrayList<Long>(); | ||||
| 
 | ||||
| @ -243,7 +243,8 @@ public class VMSnapshotManagerImpl extends MutualExclusiveIdsManagerBase impleme | ||||
|             sc.setParameters("id", id); | ||||
|         } | ||||
| 
 | ||||
|         return _vmSnapshotDao.search(sc, searchFilter); | ||||
|         Pair<List<VMSnapshotVO>,Integer> searchAndCount = _vmSnapshotDao.searchAndCount(sc, searchFilter); | ||||
|         return new Pair<List<? extends VMSnapshot>, Integer>(searchAndCount.first(), searchAndCount.second()); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user