|
155 | 155 | import org.apache.cloudstack.api.command.admin.vm.ListVmsForImportCmd; |
156 | 156 | import org.apache.cloudstack.api.command.admin.vm.UnmanageVMInstanceCmd; |
157 | 157 | import org.apache.cloudstack.api.response.ListResponse; |
158 | | -import org.apache.cloudstack.api.response.NicResponse; |
159 | | -import org.apache.cloudstack.api.response.UnmanagedInstanceDiskResponse; |
160 | 158 | import org.apache.cloudstack.api.response.UnmanagedInstanceResponse; |
161 | 159 | import org.apache.cloudstack.api.response.UserVmResponse; |
162 | 160 | import org.apache.cloudstack.context.CallContext; |
@@ -341,83 +339,6 @@ private VMTemplateVO createDefaultDummyVmImportTemplate(boolean isKVM) { |
341 | 339 | return template; |
342 | 340 | } |
343 | 341 |
|
344 | | - private UnmanagedInstanceResponse createUnmanagedInstanceResponse(UnmanagedInstanceTO instance, Cluster cluster, Host host) { |
345 | | - UnmanagedInstanceResponse response = new UnmanagedInstanceResponse(); |
346 | | - response.setName(instance.getName()); |
347 | | - |
348 | | - if (cluster != null) { |
349 | | - response.setClusterId(cluster.getUuid()); |
350 | | - } |
351 | | - if (host != null) { |
352 | | - response.setHostId(host.getUuid()); |
353 | | - response.setHostName(host.getName()); |
354 | | - if (host.getHypervisorType() != null) { |
355 | | - response.setHypervisor(host.getHypervisorType().toString()); |
356 | | - } |
357 | | - response.setHypervisorVersion(host.getHypervisorVersion()); |
358 | | - } else { |
359 | | - // In case the unmanaged instance is on an external host |
360 | | - if (instance.getHostName() != null) { |
361 | | - response.setHostName(instance.getHostName()); |
362 | | - } |
363 | | - if (instance.getHostHypervisorVersion() != null) { |
364 | | - response.setHypervisorVersion(instance.getHostHypervisorVersion()); |
365 | | - } |
366 | | - if (instance.getHypervisorType() != null) { |
367 | | - response.setHypervisor(instance.getHypervisorType()); |
368 | | - } |
369 | | - } |
370 | | - response.setPowerState(instance.getPowerState().toString()); |
371 | | - response.setCpuCores(instance.getCpuCores()); |
372 | | - response.setCpuSpeed(instance.getCpuSpeed()); |
373 | | - response.setCpuCoresPerSocket(instance.getCpuCoresPerSocket()); |
374 | | - response.setMemory(instance.getMemory()); |
375 | | - response.setOperatingSystemId(instance.getOperatingSystemId()); |
376 | | - response.setOperatingSystem(instance.getOperatingSystem()); |
377 | | - response.setObjectName("unmanagedinstance"); |
378 | | - |
379 | | - if (instance.getDisks() != null) { |
380 | | - for (UnmanagedInstanceTO.Disk disk : instance.getDisks()) { |
381 | | - UnmanagedInstanceDiskResponse diskResponse = new UnmanagedInstanceDiskResponse(); |
382 | | - diskResponse.setDiskId(disk.getDiskId()); |
383 | | - if (StringUtils.isNotEmpty(disk.getLabel())) { |
384 | | - diskResponse.setLabel(disk.getLabel()); |
385 | | - } |
386 | | - diskResponse.setCapacity(disk.getCapacity()); |
387 | | - diskResponse.setController(disk.getController()); |
388 | | - diskResponse.setControllerUnit(disk.getControllerUnit()); |
389 | | - diskResponse.setPosition(disk.getPosition()); |
390 | | - diskResponse.setImagePath(disk.getImagePath()); |
391 | | - diskResponse.setDatastoreName(disk.getDatastoreName()); |
392 | | - diskResponse.setDatastoreHost(disk.getDatastoreHost()); |
393 | | - diskResponse.setDatastorePath(disk.getDatastorePath()); |
394 | | - diskResponse.setDatastoreType(disk.getDatastoreType()); |
395 | | - response.addDisk(diskResponse); |
396 | | - } |
397 | | - } |
398 | | - |
399 | | - if (instance.getNics() != null) { |
400 | | - for (UnmanagedInstanceTO.Nic nic : instance.getNics()) { |
401 | | - NicResponse nicResponse = new NicResponse(); |
402 | | - nicResponse.setId(nic.getNicId()); |
403 | | - nicResponse.setNetworkName(nic.getNetwork()); |
404 | | - nicResponse.setMacAddress(nic.getMacAddress()); |
405 | | - if (StringUtils.isNotEmpty(nic.getAdapterType())) { |
406 | | - nicResponse.setAdapterType(nic.getAdapterType()); |
407 | | - } |
408 | | - if (!CollectionUtils.isEmpty(nic.getIpAddress())) { |
409 | | - nicResponse.setIpAddresses(nic.getIpAddress()); |
410 | | - } |
411 | | - nicResponse.setVlanId(nic.getVlan()); |
412 | | - nicResponse.setIsolatedPvlanId(nic.getPvlan()); |
413 | | - nicResponse.setIsolatedPvlanType(nic.getPvlanType()); |
414 | | - response.addNic(nicResponse); |
415 | | - } |
416 | | - } |
417 | | - |
418 | | - return response; |
419 | | - } |
420 | | - |
421 | 342 | private List<String> getAdditionalNameFilters(Cluster cluster) { |
422 | 343 | List<String> additionalNameFilter = new ArrayList<>(); |
423 | 344 | if (cluster == null) { |
@@ -3016,9 +2937,8 @@ public ListResponse<UnmanagedInstanceResponse> listVmsForImport(ListVmsForImport |
3016 | 2937 | !instance.getName().toLowerCase().contains(keyword)) { |
3017 | 2938 | continue; |
3018 | 2939 | } |
3019 | | - responses.add(createUnmanagedInstanceResponse(instance, null, null)); |
| 2940 | + responses.add(responseGenerator.createUnmanagedInstanceResponse(instance, null, null)); |
3020 | 2941 | } |
3021 | | - |
3022 | 2942 | ListResponse<UnmanagedInstanceResponse> listResponses = new ListResponse<>(); |
3023 | 2943 | listResponses.setResponses(responses, responses.size()); |
3024 | 2944 | return listResponses; |
|
0 commit comments