Skip to content

Extend import/export unmanaged instances to KVM#7712

Closed
itsayushpandey wants to merge 20 commits intoapache:mainfrom
itsayushpandey:ayushpandey/gsoc2023
Closed

Extend import/export unmanaged instances to KVM#7712
itsayushpandey wants to merge 20 commits intoapache:mainfrom
itsayushpandey:ayushpandey/gsoc2023

Conversation

@itsayushpandey
Copy link

@itsayushpandey itsayushpandey commented Jul 2, 2023

This PR adds supports to cloudstack for managing and unmanaging VM's in KVM Hypervisor.

This PR addresses #7127

Description

The support is extended through API's and also the UI. The Apache Cloudstack KVM plugin has been extended with new command wrappers for fetching unmanaged VM's xml attribute. The code paths in management server have been cleaned up and refined for managing KVM specific importing commands.
API's involved are :

  • unmanageVirtualmachine
  • listunmanageInstances
  • importVirtualMachine

Testing steps:

  • Build pull request and deploy a new apache cloudstack environment with KVM hosts(used monkeybox for local development and testing).
  • From the cloudstack UI, create a new virtual machine.
  • Go to tools option and choose import-export instances.
  • In the managed instance section, see if the newly created virtual machine exist.
  • From the managed instance section, choose the virtual machine and unmanaged it.
  • Once the VM is unmanaged you can see it disappear from manage instance section and it will appear in unmanage instance section.
  • To manage an unmanage instance, choose an instance from unmanage instance section.
  • On click of unmanage instance a popup will appear, where you need to enter vm name and choose vm template, service offering, network and then click import instance button.
  • You can see the unmanage instance is managed now and you can see it populate in the mananged instance section under import-export instances section.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

@boring-cyborg
Copy link

boring-cyborg bot commented Jul 2, 2023

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

@nvazquez
Copy link
Contributor

nvazquez commented Jul 2, 2023

Thanks @itsayushpandey - I'm setting the PR as draft

@nvazquez nvazquez marked this pull request as draft July 2, 2023 02:56
@nvazquez nvazquez linked an issue Jul 2, 2023 that may be closed by this pull request
@nvazquez
Copy link
Contributor

nvazquez commented Jul 2, 2023

@blueorangutan package

@blueorangutan
Copy link

@nvazquez a [SF] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✖️ el7 ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 6380

@nvazquez
Copy link
Contributor

nvazquez commented Jul 2, 2023

@itsayushpandey looks like the unit tests on UnmanagedVMsManagerImplTest are failing after the changes, can you check them?

@itsayushpandey itsayushpandey force-pushed the ayushpandey/gsoc2023 branch from 8f8b214 to ad0ab57 Compare July 3, 2023 05:23
@DaanHoogland
Copy link
Contributor

nice to see you are underway with this @itsayushpandey 👍

@nvazquez
Copy link
Contributor

nvazquez commented Jul 3, 2023

@blueorangutan package

@blueorangutan
Copy link

@nvazquez a [SF] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✖️ el7 ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 6398

@itsayushpandey
Copy link
Author

@DaanHoogland I've implemented the changes you've suggested in the latest pull request.

@itsayushpandey
Copy link
Author

@itsayushpandey looks like the unit tests on UnmanagedVMsManagerImplTest are failing after the changes, can you check them?

@nvazquez - can you please help me kick off tests run again? I have fixed the issue in previous commits and can add more tests further after code completion of functionality?

@itsayushpandey
Copy link
Author

@blueorangutan package

@blueorangutan
Copy link

@itsayushpandey a [SF] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@itsayushpandey itsayushpandey marked this pull request as ready for review July 7, 2023 02:48
@itsayushpandey itsayushpandey marked this pull request as draft July 7, 2023 04:09
@itsayushpandey itsayushpandey marked this pull request as draft July 7, 2023 04:09
@nvazquez
Copy link
Contributor

nvazquez commented Jul 7, 2023

@blueorangutan package

@blueorangutan
Copy link

@nvazquez a [SF] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@nvazquez
Copy link
Contributor

nvazquez commented Jul 7, 2023

Thanks @itsayushpandey I have tested the changes so far on an env with 2 KVM Alma Linux 8 hosts:

  • Could successfully unmanage an instance
  • When listing unmanaged instances in the cluster, I get the following error on the logs:
2023-07-07 13:55:49,552 DEBUG [c.c.a.t.Request] (AgentManager-Handler-3:null) (logid:) Seq 1-1384575410439717051: Processing:  { Ans: , MgmtId: 167780820, via: 1, Ver: v1, Flags: 10, [{"com.cloud.agent.api.Answer":{"result":"false","details":"com.cloud.utils.exception.CloudRuntimeException: GetUnmanagedInstancesCommand failed due to name in virDomainLookupByName must not be NULL
	at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtGetUnmanagedInstancesCommandWrapper.execute(LibvirtGetUnmanagedInstancesCommandWrapper.java:79)
	at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtGetUnmanagedInstancesCommandWrapper.execute(LibvirtGetUnmanagedInstancesCommandWrapper.java:39)
	at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper.execute(LibvirtRequestWrapper.java:78)
	at com.cloud.hypervisor.kvm.resource.LibvirtComputingResource.executeRequest(LibvirtComputingResource.java:1858)
	at com.cloud.agent.Agent.processRequest(Agent.java:662)
	at com.cloud.agent.Agent$AgentRequestHandler.doTask(Agent.java:1082)
	at com.cloud.utils.nio.Task.call(Task.java:83)
	at com.cloud.utils.nio.Task.call(Task.java:29)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
","wait":"0","bypassHostMaintenance":"false"}}] }
2023-07-07 13:55:49,552 DEBUG [c.c.a.t.Request] (qtp649329985-20:ctx-abfd666a ctx-9a38d1ab ctx-8b7eff9f) (logid:252f89b0) Seq 1-1384575410439717051: Received:  { Ans: , MgmtId: 167780820, via: 1(ref-trl-5219-k-Ma8-nicolas-vazquez-kvm1), Ver: v1, Flags: 10, { Answer } }
2023-07-07 13:55:49,552 DEBUG [c.c.a.m.AgentManagerImpl] (qtp649329985-20:ctx-abfd666a ctx-9a38d1ab ctx-8b7eff9f) (logid:252f89b0) Details from executing class com.cloud.agent.api.GetUnmanagedInstancesCommand: com.cloud.utils.exception.CloudRuntimeException: GetUnmanagedInstancesCommand failed due to name in virDomainLookupByName must not be NULL
	at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtGetUnmanagedInstancesCommandWrapper.execute(LibvirtGetUnmanagedInstancesCommandWrapper.java:79)
	at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtGetUnmanagedInstancesCommandWrapper.execute(LibvirtGetUnmanagedInstancesCommandWrapper.java:39)
	at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper.execute(LibvirtRequestWrapper.java:78)
	at com.cloud.hypervisor.kvm.resource.LibvirtComputingResource.executeRequest(LibvirtComputingResource.java:1858)
	at com.cloud.agent.Agent.processRequest(Agent.java:662)
	at com.cloud.agent.Agent$AgentRequestHandler.doTask(Agent.java:1082)
	at com.cloud.utils.nio.Task.call(Task.java:83)
	at com.cloud.utils.nio.Task.call(Task.java:29)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

And an empty response on the API:

(localcloud) 🐱 > unmanage virtualmachine id=6ff6a2ae-bf77-4f29-8839-ec2ebc1ec547 
{
  "unmanagevirtualmachineresponse": {
    "details": "VM unmanaged successfully",
    "success": true
  }
}
(localcloud) 🐱 > list unmanagedinstances clusterid=e3f97518-b457-4e3f-9f90-8c3ee9fe4698 
(localcloud) 🐱 >

@itsayushpandey
Copy link
Author

@nvazquez I have added support to list all domains in a cluster if name is not given.
Screenshot from 2023-07-08 20-30-14

@nvazquez
Copy link
Contributor

nvazquez commented Oct 9, 2023

Hi @itsayushpandey I've tried importing an unmanaged instance but I get a different failure this time: (tested on 2xKVM Oracle Linux 8 env)

Screenshot 2023-10-08 at 21 55 43
2023-10-09 00:48:44,601 DEBUG [c.c.a.ApiServlet] (qtp649329985-21:ctx-7841d8c0) (logid:cf53b68b) ===START===  172.30.205.3 -- GET  name=i-2-5-VM&clusterid=7efee018-9300-4b01-b9be-e6eaffbb74c5&displayname=import&serviceofferingid=7138dcd2-e85b-47b4-8c4a-2f5684b0779a&hostname=import&templateid=00605e48-6639-11ee-80ce-1e00b100022f&nicnetworklist[0].nic=0&nicnetworklist[0].network=92533133-1361-4bf7-a109-31ea6456b961&nicipaddresslist[0].nic=0&nicipaddresslist[0].ip4Address=auto&command=importUnmanagedInstance&response=json
...
2023-10-09 00:48:44,628 INFO  [o.a.c.f.j.i.AsyncJobMonitor] (API-Job-Executor-31:ctx-96ee2279 job-40) (logid:526d3077) Add job-40 into job monitoring
2023-10-09 00:48:44,631 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (qtp649329985-21:ctx-7841d8c0 ctx-d6e0c682) (logid:cf53b68b) submit async job-40, details: AsyncJobVO: {id:40, userId: 2, accountId: 2, instanceType: None, instanceId: null, cmd: org.apache.cloudstack.api.command.admin.vm.ImportUnmanagedInstanceCmd, cmdInfo: {"httpmethod":"GET","clusterid":"7efee018-9300-4b01-b9be-e6eaffbb74c5","templateid":"00605e48-6639-11ee-80ce-1e00b100022f","nicipaddresslist[0].ip4Address":"auto","ctxAccountId":"2","cmdEventType":"VM.IMPORT","hostname":"import","nicipaddresslist[0].nic":"0","nicnetworklist[0].network":"92533133-1361-4bf7-a109-31ea6456b961","serviceofferingid":"7138dcd2-e85b-47b4-8c4a-2f5684b0779a","response":"json","ctxUserId":"2","displayname":"import","name":"i-2-5-VM","ctxStartEventId":"115","nicnetworklist[0].nic":"0","ctxDetails":"{\"interface com.cloud.org.Cluster\":\"7efee018-9300-4b01-b9be-e6eaffbb74c5\",\"interface com.cloud.offering.ServiceOffering\":\"7138dcd2-e85b-47b4-8c4a-2f5684b0779a\",\"interface com.cloud.template.VirtualMachineTemplate\":\"00605e48-6639-11ee-80ce-1e00b100022f\"}"}, cmdVersion: 0, status: IN_PROGRESS, processStatus: 0, resultCode: 0, result: null, initMsid: 32988318401071, completeMsid: null, lastUpdated: null, lastPolled: null, created: null, removed: null}
2023-10-09 00:48:44,632 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-31:ctx-96ee2279 job-40) (logid:db87c82e) Executing AsyncJobVO: {id:40, userId: 2, accountId: 2, instanceType: None, instanceId: null, cmd: org.apache.cloudstack.api.command.admin.vm.ImportUnmanagedInstanceCmd, cmdInfo: {"httpmethod":"GET","clusterid":"7efee018-9300-4b01-b9be-e6eaffbb74c5","templateid":"00605e48-6639-11ee-80ce-1e00b100022f","nicipaddresslist[0].ip4Address":"auto","ctxAccountId":"2","cmdEventType":"VM.IMPORT","hostname":"import","nicipaddresslist[0].nic":"0","nicnetworklist[0].network":"92533133-1361-4bf7-a109-31ea6456b961","serviceofferingid":"7138dcd2-e85b-47b4-8c4a-2f5684b0779a","response":"json","ctxUserId":"2","displayname":"import","name":"i-2-5-VM","ctxStartEventId":"115","nicnetworklist[0].nic":"0","ctxDetails":"{\"interface com.cloud.org.Cluster\":\"7efee018-9300-4b01-b9be-e6eaffbb74c5\",\"interface com.cloud.offering.ServiceOffering\":\"7138dcd2-e85b-47b4-8c4a-2f5684b0779a\",\"interface com.cloud.template.VirtualMachineTemplate\":\"00605e48-6639-11ee-80ce-1e00b100022f\"}"}, cmdVersion: 0, status: IN_PROGRESS, processStatus: 0, resultCode: 0, result: null, initMsid: 32988318401071, completeMsid: null, lastUpdated: null, lastPolled: null, created: null, removed: null}
2023-10-09 00:48:44,632 DEBUG [c.c.a.ApiServlet] (qtp649329985-21:ctx-7841d8c0 ctx-d6e0c682) (logid:cf53b68b) ===END===  172.30.205.3 -- GET  name=i-2-5-VM&clusterid=7efee018-9300-4b01-b9be-e6eaffbb74c5&displayname=import&serviceofferingid=7138dcd2-e85b-47b4-8c4a-2f5684b0779a&hostname=import&templateid=00605e48-6639-11ee-80ce-1e00b100022f&nicnetworklist[0].nic=0&nicnetworklist[0].network=92533133-1361-4bf7-a109-31ea6456b961&nicipaddresslist[0].nic=0&nicipaddresslist[0].ip4Address=auto&command=importUnmanagedInstance&response=json
2023-10-09 00:48:44,646 DEBUG [c.c.u.AccountManagerImpl] (API-Job-Executor-31:ctx-96ee2279 job-40 ctx-536981c6) (logid:db87c82e) Access granted to Account [{"accountName":"admin","id":2,"uuid":"29a6621b-6639-11ee-80ce-1e00b100022f"}] to Service offering {"id":1,"name":"Small Instance","uuid":"7138dcd2-e85b-47b4-8c4a-2f5684b0779a"}. by AffinityGroupAccessChecker
2023-10-09 00:48:44,648 TRACE [o.a.c.a.c.a.v.ImportUnmanagedInstanceCmd] (API-Job-Executor-31:ctx-96ee2279 job-40 ctx-536981c6) (logid:db87c82e) nic, '0', goes on net, '92533133-1361-4bf7-a109-31ea6456b961'
2023-10-09 00:48:44,651 TRACE [o.a.c.a.c.a.v.ImportUnmanagedInstanceCmd] (API-Job-Executor-31:ctx-96ee2279 job-40 ctx-536981c6) (logid:db87c82e) nic, '0', gets ip, 'auto'
2023-10-09 00:48:44,653 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-31:ctx-96ee2279 job-40) (logid:db87c82e) Complete async job-40, jobStatus: FAILED, resultCode: 530, result: org.apache.cloudstack.api.response.ExceptionResponse/null/{"uuidList":[],"errorcode":"530","errortext":"Failed to find unmanaged vm with name: i-2-5-VM in cluster: 7efee018-9300-4b01-b9be-e6eaffbb74c5"}
2023-10-09 00:48:44,654 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-31:ctx-96ee2279 job-40) (logid:db87c82e) Publish async job-40 complete on message bus
2023-10-09 00:48:44,654 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-31:ctx-96ee2279 job-40) (logid:db87c82e) Wake up jobs related to job-40
2023-10-09 00:48:44,654 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-31:ctx-96ee2279 job-40) (logid:db87c82e) Update db status for job-40
2023-10-09 00:48:44,655 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-31:ctx-96ee2279 job-40) (logid:db87c82e) Wake up jobs joined with job-40 and disjoin all subjobs created from job- 40
2023-10-09 00:48:44,659 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-31:ctx-96ee2279 job-40) (logid:db87c82e) Done executing org.apache.cloudstack.api.command.admin.vm.ImportUnmanagedInstanceCmd for job-40

Can you please check?

@nvazquez nvazquez marked this pull request as draft October 9, 2023 00:54
@itsayushpandey
Copy link
Author

Hey @nvazquez, Can you please invoke packaging and update the directory here (https://download.cloudstack.org/testing/7712/centos7/4.19/) as I'm not able to reproduce the error locally. I can try to reproduce it once I have the updated package and then try to fix it.

@github-actions
Copy link

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@nvazquez
Copy link
Contributor

Hi @itsayushpandey sorry for the delay, I have updated the packages on https://download.cloudstack.org/testing/7712/ to the last packages built on 04/10 (same ones I could hit the issue)

@itsayushpandey
Copy link
Author

Hi @nvazquez - looking at the log I see the API call:

2023-10-09 00:48:44,601 DEBUG [c.c.a.ApiServlet] (qtp649329985-21:ctx-7841d8c0) (logid:cf53b68b) ===START===  172.30.205.3 -- GET  name=i-2-5-VM&clusterid=7efee018-9300-4b01-b9be-e6eaffbb74c5&displayname=import&serviceofferingid=7138dcd2-e85b-47b4-8c4a-2f5684b0779a&**hostname=import**&templateid=00605e48-6639-11ee-80ce-1e00b100022f&nicnetworklist[0].nic=0&nicnetworklist[0].network=92533133-1361-4bf7-a109-31ea6456b961&nicipaddresslist[0].nic=0&nicipaddresslist[0].ip4Address=auto&command=importUnmanagedInstance&response=json

The hostname passed is 'import' (hostname=import), is that expected? I am unable to reproduce on monkeybox env, but I can try to check again if this is something off in UI.

Also, are you able to reproduce the bug with API or just UI?

@nvazquez
Copy link
Contributor

@itsayushpandey the import was just a text name for the VM, should be allowed. I kept testing a bit further and discovered two cases:

  • Setting displayname = hostname: fails with error: Failed to find unmanaged vm with name: X in cluster: Y
  • Setting diplayname only: fails with error: Failed to import Unmanaged VM [i-2-5-VM] because the service offering [7138dcd2-e85b-47b4-8c4a-2f5684b0779a] is not compatible due to [Service offering (7138dcd2-e85b-47b4-8c4a-2f5684b0779a) 500MHz CPU speed does not match VM CPU speed 250MHz and VM is not in powered off state (Power state: PowerOn)].

For case 1: (displayname = hostname = test-vm)

2023-10-15 00:42:10,706 DEBUG [c.c.a.ApiServlet] (qtp649329985-21:ctx-ee3d8bde) (logid:93d4e90c) ===START===  172.30.205.5 -- GET  name=i-2-5-VM&clusterid=7efee018-9300-4b01-b9be-e6eaffbb74c5&displayname=test-vm&serviceofferingid=7138dcd2-e85b-47b4-8c4a-2f5684b0779a&hostname=test-vm&templateid=00605e48-6639-11ee-80ce-1e00b100022f&nicnetworklist[0].nic=0&nicnetworklist[0].network=92533133-1361-4bf7-a109-31ea6456b961&nicipaddresslist[0].nic=0&nicipaddresslist[0].ip4Address=auto&command=importUnmanagedInstance&response=json
2023-10-15 00:42:10,706 DEBUG [c.c.a.ApiServlet] (qtp649329985-21:ctx-ee3d8bde) (logid:93d4e90c) Two factor authentication is already verified for the user 2, so skipping
2023-10-15 00:42:10,712 DEBUG [c.c.a.ApiServer] (qtp649329985-21:ctx-ee3d8bde ctx-7368cca9) (logid:93d4e90c) CIDRs from which account 'Account [{"accountName":"admin","id":2,"uuid":"29a6621b-6639-11ee-80ce-1e00b100022f"}]' is allowed to perform API calls: 0.0.0.0/0,::/0
2023-10-15 00:42:10,714 INFO  [o.a.c.a.DynamicRoleBasedAPIAccessChecker] (qtp649329985-21:ctx-ee3d8bde ctx-7368cca9) (logid:93d4e90c) Account [Account [{"accountName":"admin","id":2,"uuid":"29a6621b-6639-11ee-80ce-1e00b100022f"}]] is Root Admin or Domain Admin, all APIs are allowed.
2023-10-15 00:42:10,715 WARN  [o.a.c.a.ProjectRoleBasedApiAccessChecker] (qtp649329985-21:ctx-ee3d8bde ctx-7368cca9) (logid:93d4e90c) Project is null, ProjectRoleBasedApiAccessChecker only applies to projects, returning API [importUnmanagedInstance] for user [User {"username":"admin","uuid":"29a86c50-6639-11ee-80ce-1e00b100022f"}.] as allowed.
2023-10-15 00:42:10,715 DEBUG [o.a.c.a.StaticRoleBasedAPIAccessChecker] (qtp649329985-21:ctx-ee3d8bde ctx-7368cca9) (logid:93d4e90c) RoleService is enabled. We will use it instead of StaticRoleBasedAPIAccessChecker.
2023-10-15 00:42:10,716 DEBUG [o.a.c.r.ApiRateLimitServiceImpl] (qtp649329985-21:ctx-ee3d8bde ctx-7368cca9) (logid:93d4e90c) API rate limiting is disabled. We will not use ApiRateLimitService.
2023-10-15 00:42:10,729 INFO  [o.a.c.f.j.i.AsyncJobMonitor] (API-Job-Executor-38:ctx-e92a0323 job-47) (logid:2bd276a0) Add job-47 into job monitoring
2023-10-15 00:42:10,731 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (qtp649329985-21:ctx-ee3d8bde ctx-7368cca9) (logid:93d4e90c) submit async job-47, details: AsyncJobVO: {id:47, userId: 2, accountId: 2, instanceType: None, instanceId: null, cmd: org.apache.cloudstack.api.command.admin.vm.ImportUnmanagedInstanceCmd, cmdInfo: {"httpmethod":"GET","clusterid":"7efee018-9300-4b01-b9be-e6eaffbb74c5","templateid":"00605e48-6639-11ee-80ce-1e00b100022f","nicipaddresslist[0].ip4Address":"auto","ctxAccountId":"2","cmdEventType":"VM.IMPORT","hostname":"test-vm","nicipaddresslist[0].nic":"0","nicnetworklist[0].network":"92533133-1361-4bf7-a109-31ea6456b961","serviceofferingid":"7138dcd2-e85b-47b4-8c4a-2f5684b0779a","response":"json","ctxUserId":"2","displayname":"test-vm","name":"i-2-5-VM","ctxStartEventId":"130","nicnetworklist[0].nic":"0","ctxDetails":"{\"interface com.cloud.org.Cluster\":\"7efee018-9300-4b01-b9be-e6eaffbb74c5\",\"interface com.cloud.offering.ServiceOffering\":\"7138dcd2-e85b-47b4-8c4a-2f5684b0779a\",\"interface com.cloud.template.VirtualMachineTemplate\":\"00605e48-6639-11ee-80ce-1e00b100022f\"}"}, cmdVersion: 0, status: IN_PROGRESS, processStatus: 0, resultCode: 0, result: null, initMsid: 32988318401071, completeMsid: null, lastUpdated: null, lastPolled: null, created: null, removed: null}
2023-10-15 00:42:10,732 DEBUG [c.c.a.ApiServlet] (qtp649329985-21:ctx-ee3d8bde ctx-7368cca9) (logid:93d4e90c) ===END===  172.30.205.5 -- GET  name=i-2-5-VM&clusterid=7efee018-9300-4b01-b9be-e6eaffbb74c5&displayname=test-vm&serviceofferingid=7138dcd2-e85b-47b4-8c4a-2f5684b0779a&hostname=test-vm&templateid=00605e48-6639-11ee-80ce-1e00b100022f&nicnetworklist[0].nic=0&nicnetworklist[0].network=92533133-1361-4bf7-a109-31ea6456b961&nicipaddresslist[0].nic=0&nicipaddresslist[0].ip4Address=auto&command=importUnmanagedInstance&response=json
2023-10-15 00:42:10,734 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-38:ctx-e92a0323 job-47) (logid:e928f78c) Executing AsyncJobVO: {id:47, userId: 2, accountId: 2, instanceType: None, instanceId: null, cmd: org.apache.cloudstack.api.command.admin.vm.ImportUnmanagedInstanceCmd, cmdInfo: {"httpmethod":"GET","clusterid":"7efee018-9300-4b01-b9be-e6eaffbb74c5","templateid":"00605e48-6639-11ee-80ce-1e00b100022f","nicipaddresslist[0].ip4Address":"auto","ctxAccountId":"2","cmdEventType":"VM.IMPORT","hostname":"test-vm","nicipaddresslist[0].nic":"0","nicnetworklist[0].network":"92533133-1361-4bf7-a109-31ea6456b961","serviceofferingid":"7138dcd2-e85b-47b4-8c4a-2f5684b0779a","response":"json","ctxUserId":"2","displayname":"test-vm","name":"i-2-5-VM","ctxStartEventId":"130","nicnetworklist[0].nic":"0","ctxDetails":"{\"interface com.cloud.org.Cluster\":\"7efee018-9300-4b01-b9be-e6eaffbb74c5\",\"interface com.cloud.offering.ServiceOffering\":\"7138dcd2-e85b-47b4-8c4a-2f5684b0779a\",\"interface com.cloud.template.VirtualMachineTemplate\":\"00605e48-6639-11ee-80ce-1e00b100022f\"}"}, cmdVersion: 0, status: IN_PROGRESS, processStatus: 0, resultCode: 0, result: null, initMsid: 32988318401071, completeMsid: null, lastUpdated: null, lastPolled: null, created: null, removed: null}
2023-10-15 00:42:10,745 DEBUG [c.c.u.AccountManagerImpl] (API-Job-Executor-38:ctx-e92a0323 job-47 ctx-69001e68) (logid:e928f78c) Access granted to Account [{"accountName":"admin","id":2,"uuid":"29a6621b-6639-11ee-80ce-1e00b100022f"}] to Service offering {"id":1,"name":"Small Instance","uuid":"7138dcd2-e85b-47b4-8c4a-2f5684b0779a"}. by AffinityGroupAccessChecker
2023-10-15 00:42:10,746 TRACE [o.a.c.a.c.a.v.ImportUnmanagedInstanceCmd] (API-Job-Executor-38:ctx-e92a0323 job-47 ctx-69001e68) (logid:e928f78c) nic, '0', goes on net, '92533133-1361-4bf7-a109-31ea6456b961'
2023-10-15 00:42:10,748 TRACE [o.a.c.a.c.a.v.ImportUnmanagedInstanceCmd] (API-Job-Executor-38:ctx-e92a0323 job-47 ctx-69001e68) (logid:e928f78c) nic, '0', gets ip, 'auto'
2023-10-15 00:42:10,750 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-38:ctx-e92a0323 job-47) (logid:e928f78c) Complete async job-47, jobStatus: FAILED, resultCode: 530, result: org.apache.cloudstack.api.response.ExceptionResponse/null/{"uuidList":[],"errorcode":"530","errortext":"Failed to find unmanaged vm with name: i-2-5-VM in cluster: 7efee018-9300-4b01-b9be-e6eaffbb74c5"}
2023-10-15 00:42:10,750 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-38:ctx-e92a0323 job-47) (logid:e928f78c) Publish async job-47 complete on message bus
2023-10-15 00:42:10,750 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-38:ctx-e92a0323 job-47) (logid:e928f78c) Wake up jobs related to job-47
2023-10-15 00:42:10,751 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-38:ctx-e92a0323 job-47) (logid:e928f78c) Update db status for job-47
2023-10-15 00:42:10,751 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-38:ctx-e92a0323 job-47) (logid:e928f78c) Wake up jobs joined with job-47 and disjoin all subjobs created from job- 47
2023-10-15 00:42:10,756 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-38:ctx-e92a0323 job-47) (logid:e928f78c) Done executing org.apache.cloudstack.api.command.admin.vm.ImportUnmanagedInstanceCmd for job-47

For case 2: (displayname=test-vm2)

2023-10-15 00:46:53,585 DEBUG [c.c.a.ApiServlet] (qtp649329985-15:ctx-eb8f2e29) (logid:d980ef32) ===START===  172.30.205.5 -- GET  name=i-2-5-VM&clusterid=7efee018-9300-4b01-b9be-e6eaffbb74c5&displayname=test-vm2&serviceofferingid=7138dcd2-e85b-47b4-8c4a-2f5684b0779a&templateid=00605e48-6639-11ee-80ce-1e00b100022f&nicnetworklist[0].nic=0&nicnetworklist[0].network=92533133-1361-4bf7-a109-31ea6456b961&nicipaddresslist[0].nic=0&nicipaddresslist[0].ip4Address=auto&command=importUnmanagedInstance&response=json
2023-10-15 00:46:53,585 DEBUG [c.c.a.ApiServlet] (qtp649329985-15:ctx-eb8f2e29) (logid:d980ef32) Two factor authentication is already verified for the user 2, so skipping
2023-10-15 00:46:53,590 DEBUG [c.c.a.ApiServer] (qtp649329985-15:ctx-eb8f2e29 ctx-c0737187) (logid:d980ef32) CIDRs from which account 'Account [{"accountName":"admin","id":2,"uuid":"29a6621b-6639-11ee-80ce-1e00b100022f"}]' is allowed to perform API calls: 0.0.0.0/0,::/0
2023-10-15 00:46:53,592 INFO  [o.a.c.a.DynamicRoleBasedAPIAccessChecker] (qtp649329985-15:ctx-eb8f2e29 ctx-c0737187) (logid:d980ef32) Account [Account [{"accountName":"admin","id":2,"uuid":"29a6621b-6639-11ee-80ce-1e00b100022f"}]] is Root Admin or Domain Admin, all APIs are allowed.
2023-10-15 00:46:53,593 WARN  [o.a.c.a.ProjectRoleBasedApiAccessChecker] (qtp649329985-15:ctx-eb8f2e29 ctx-c0737187) (logid:d980ef32) Project is null, ProjectRoleBasedApiAccessChecker only applies to projects, returning API [importUnmanagedInstance] for user [User {"username":"admin","uuid":"29a86c50-6639-11ee-80ce-1e00b100022f"}.] as allowed.
2023-10-15 00:46:53,594 DEBUG [o.a.c.a.StaticRoleBasedAPIAccessChecker] (qtp649329985-15:ctx-eb8f2e29 ctx-c0737187) (logid:d980ef32) RoleService is enabled. We will use it instead of StaticRoleBasedAPIAccessChecker.
2023-10-15 00:46:53,594 DEBUG [o.a.c.r.ApiRateLimitServiceImpl] (qtp649329985-15:ctx-eb8f2e29 ctx-c0737187) (logid:d980ef32) API rate limiting is disabled. We will not use ApiRateLimitService.
2023-10-15 00:46:53,608 INFO  [o.a.c.f.j.i.AsyncJobMonitor] (API-Job-Executor-39:ctx-34bf195a job-48) (logid:9c106ca4) Add job-48 into job monitoring
2023-10-15 00:46:53,610 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (qtp649329985-15:ctx-eb8f2e29 ctx-c0737187) (logid:d980ef32) submit async job-48, details: AsyncJobVO: {id:48, userId: 2, accountId: 2, instanceType: None, instanceId: null, cmd: org.apache.cloudstack.api.command.admin.vm.ImportUnmanagedInstanceCmd, cmdInfo: {"httpmethod":"GET","clusterid":"7efee018-9300-4b01-b9be-e6eaffbb74c5","templateid":"00605e48-6639-11ee-80ce-1e00b100022f","nicipaddresslist[0].ip4Address":"auto","ctxAccountId":"2","cmdEventType":"VM.IMPORT","nicipaddresslist[0].nic":"0","nicnetworklist[0].network":"92533133-1361-4bf7-a109-31ea6456b961","serviceofferingid":"7138dcd2-e85b-47b4-8c4a-2f5684b0779a","response":"json","ctxUserId":"2","displayname":"test-vm2","name":"i-2-5-VM","ctxStartEventId":"131","nicnetworklist[0].nic":"0","ctxDetails":"{\"interface com.cloud.org.Cluster\":\"7efee018-9300-4b01-b9be-e6eaffbb74c5\",\"interface com.cloud.offering.ServiceOffering\":\"7138dcd2-e85b-47b4-8c4a-2f5684b0779a\",\"interface com.cloud.template.VirtualMachineTemplate\":\"00605e48-6639-11ee-80ce-1e00b100022f\"}"}, cmdVersion: 0, status: IN_PROGRESS, processStatus: 0, resultCode: 0, result: null, initMsid: 32988318401071, completeMsid: null, lastUpdated: null, lastPolled: null, created: null, removed: null}
2023-10-15 00:46:53,613 DEBUG [c.c.a.ApiServlet] (qtp649329985-15:ctx-eb8f2e29 ctx-c0737187) (logid:d980ef32) ===END===  172.30.205.5 -- GET  name=i-2-5-VM&clusterid=7efee018-9300-4b01-b9be-e6eaffbb74c5&displayname=test-vm2&serviceofferingid=7138dcd2-e85b-47b4-8c4a-2f5684b0779a&templateid=00605e48-6639-11ee-80ce-1e00b100022f&nicnetworklist[0].nic=0&nicnetworklist[0].network=92533133-1361-4bf7-a109-31ea6456b961&nicipaddresslist[0].nic=0&nicipaddresslist[0].ip4Address=auto&command=importUnmanagedInstance&response=json
2023-10-15 00:46:53,613 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-39:ctx-34bf195a job-48) (logid:35038313) Executing AsyncJobVO: {id:48, userId: 2, accountId: 2, instanceType: None, instanceId: null, cmd: org.apache.cloudstack.api.command.admin.vm.ImportUnmanagedInstanceCmd, cmdInfo: {"httpmethod":"GET","clusterid":"7efee018-9300-4b01-b9be-e6eaffbb74c5","templateid":"00605e48-6639-11ee-80ce-1e00b100022f","nicipaddresslist[0].ip4Address":"auto","ctxAccountId":"2","cmdEventType":"VM.IMPORT","nicipaddresslist[0].nic":"0","nicnetworklist[0].network":"92533133-1361-4bf7-a109-31ea6456b961","serviceofferingid":"7138dcd2-e85b-47b4-8c4a-2f5684b0779a","response":"json","ctxUserId":"2","displayname":"test-vm2","name":"i-2-5-VM","ctxStartEventId":"131","nicnetworklist[0].nic":"0","ctxDetails":"{\"interface com.cloud.org.Cluster\":\"7efee018-9300-4b01-b9be-e6eaffbb74c5\",\"interface com.cloud.offering.ServiceOffering\":\"7138dcd2-e85b-47b4-8c4a-2f5684b0779a\",\"interface com.cloud.template.VirtualMachineTemplate\":\"00605e48-6639-11ee-80ce-1e00b100022f\"}"}, cmdVersion: 0, status: IN_PROGRESS, processStatus: 0, resultCode: 0, result: null, initMsid: 32988318401071, completeMsid: null, lastUpdated: null, lastPolled: null, created: null, removed: null}
2023-10-15 00:46:53,624 DEBUG [c.c.u.AccountManagerImpl] (API-Job-Executor-39:ctx-34bf195a job-48 ctx-6068b350) (logid:35038313) Access granted to Account [{"accountName":"admin","id":2,"uuid":"29a6621b-6639-11ee-80ce-1e00b100022f"}] to Service offering {"id":1,"name":"Small Instance","uuid":"7138dcd2-e85b-47b4-8c4a-2f5684b0779a"}. by AffinityGroupAccessChecker
2023-10-15 00:46:53,625 TRACE [o.a.c.a.c.a.v.ImportUnmanagedInstanceCmd] (API-Job-Executor-39:ctx-34bf195a job-48 ctx-6068b350) (logid:35038313) nic, '0', goes on net, '92533133-1361-4bf7-a109-31ea6456b961'
2023-10-15 00:46:53,627 TRACE [o.a.c.a.c.a.v.ImportUnmanagedInstanceCmd] (API-Job-Executor-39:ctx-34bf195a job-48 ctx-6068b350) (logid:35038313) nic, '0', gets ip, 'auto'
2023-10-15 00:46:53,637 DEBUG [c.c.a.t.Request] (AgentManager-Handler-13:null) (logid:) Seq 1-3783305161967954085: Processing:  { Ans: , MgmtId: 32988318401071, via: 1, Ver: v1, Flags: 10, [{"com.cloud.agent.api.Answer":{"result":"false","details":"com.cloud.utils.exception.CloudRuntimeException: GetUnmanagedInstancesCommand failed due to Domain not found: no domain with matching name 'i-2-5-VM'
	at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtGetUnmanagedInstancesCommandWrapper.execute(LibvirtGetUnmanagedInstancesCommandWrapper.java:66)
	at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtGetUnmanagedInstancesCommandWrapper.execute(LibvirtGetUnmanagedInstancesCommandWrapper.java:45)
	at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper.execute(LibvirtRequestWrapper.java:78)
	at com.cloud.hypervisor.kvm.resource.LibvirtComputingResource.executeRequest(LibvirtComputingResource.java:1873)
	at com.cloud.agent.Agent.processRequest(Agent.java:682)
	at com.cloud.agent.Agent$AgentRequestHandler.doTask(Agent.java:1102)
	at com.cloud.utils.nio.Task.call(Task.java:83)
	at com.cloud.utils.nio.Task.call(Task.java:29)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
","wait":"0","bypassHostMaintenance":"false"}}] }
2023-10-15 00:46:53,637 DEBUG [c.c.a.t.Request] (API-Job-Executor-39:ctx-34bf195a job-48 ctx-6068b350) (logid:35038313) Seq 1-3783305161967954085: Received:  { Ans: , MgmtId: 32988318401071, via: 1(ol8.localdomain), Ver: v1, Flags: 10, { Answer } }
2023-10-15 00:46:53,637 DEBUG [c.c.a.m.AgentManagerImpl] (API-Job-Executor-39:ctx-34bf195a job-48 ctx-6068b350) (logid:35038313) Details from executing class com.cloud.agent.api.GetUnmanagedInstancesCommand: com.cloud.utils.exception.CloudRuntimeException: GetUnmanagedInstancesCommand failed due to Domain not found: no domain with matching name 'i-2-5-VM'
	at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtGetUnmanagedInstancesCommandWrapper.execute(LibvirtGetUnmanagedInstancesCommandWrapper.java:66)
	at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtGetUnmanagedInstancesCommandWrapper.execute(LibvirtGetUnmanagedInstancesCommandWrapper.java:45)
	at com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper.execute(LibvirtRequestWrapper.java:78)
	at com.cloud.hypervisor.kvm.resource.LibvirtComputingResource.executeRequest(LibvirtComputingResource.java:1873)
	at com.cloud.agent.Agent.processRequest(Agent.java:682)
	at com.cloud.agent.Agent$AgentRequestHandler.doTask(Agent.java:1102)
	at com.cloud.utils.nio.Task.call(Task.java:83)
	at com.cloud.utils.nio.Task.call(Task.java:29)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

2023-10-15 00:46:53,667 DEBUG [c.c.a.t.Request] (API-Job-Executor-39:ctx-34bf195a job-48 ctx-6068b350) (logid:35038313) Seq 2-3561784355296673365: Received:  { Ans: , MgmtId: 32988318401071, via: 2(ol8.localdomain), Ver: v1, Flags: 10, { GetUnmanagedInstancesAnswer } }
2023-10-15 00:46:53,667 DEBUG [c.c.a.m.AgentManagerImpl] (API-Job-Executor-39:ctx-34bf195a job-48 ctx-6068b350) (logid:35038313) Details from executing class com.cloud.agent.api.GetUnmanagedInstancesCommand: True
2023-10-15 00:46:53,669 DEBUG [o.a.c.v.UnmanagedVMsManagerImpl] (API-Job-Executor-39:ctx-34bf195a job-48 ctx-6068b350) (logid:35038313) Trying to import VM [{"name":"i-2-5-VM","powerState":"PowerOn","cpuCores":1,"cpuCoresPerSocket":-1,"memory":512,"cpuSpeed":250,"disks":[{"diskId":"0","label":"vda","capacity":8589934592,"imagePath":"/mnt/299aff78-3a80-306f-86ce-2983f2451058/4f49b73b-7972-4bc0-94ec-27b90a37222c","controller":"virtio","position":0,"datastoreName":"/4f49b73b-7972-4bc0-94ec-27b90a37222c","datastoreHost":"10.0.32.4","datastorePort":0,"datastorePath":"/acs/primary/ref-trl-5793-k-Mol8-nicolas-vazquez/ref-trl-5793-k-Mol8-nicolas-vazquez-kvm-pri1","datastoreType":"file"}],"nics":[{"nicId":"0","adapterType":"virtio","macAddress":"02:01:00:cc:00:03","network":"vnet6","vlan":-1,"pciSlot":"3"}],"vncPassword":"cmLUB0v2aaaaaaaaaaaaaa"}] with name ["i-2-5-VM"], in zone [error decoding Zone {"id": "1", "name": "ref-trl-5793-k-Mol8-nicolas-vazquez", "uuid": "a288fefa-ba31-4223-8a80-775d9559bce3"}], cluster [error decoding Cluster {id: "1", name: "p1-c1", uuid: "7efee018-9300-4b01-b9be-e6eaffbb74c5"}], and host [error decoding Host {"id":2,"name":"ol8.localdomain","type":"Routing","uuid":"6efc3059-6814-4162-adad-ba63ea970af9"}], using template [error decoding Template {"format":"QCOW2","id":4,"uniqueName":"centos55-x86_64"}], service offering [error decoding Service offering {"id":1,"name":"Small Instance","uuid":"7138dcd2-e85b-47b4-8c4a-2f5684b0779a"}.], disks map [{}], NICs map [{"0":204}] and details [{}].
2023-10-15 00:46:53,670 DEBUG [c.c.u.AccountManagerImpl] (API-Job-Executor-39:ctx-34bf195a job-48 ctx-6068b350) (logid:35038313) Access granted to Account [{"accountName":"admin","id":2,"uuid":"29a6621b-6639-11ee-80ce-1e00b100022f"}] to Service offering {"id":1,"name":"Small Instance","uuid":"7138dcd2-e85b-47b4-8c4a-2f5684b0779a"}. by AffinityGroupAccessChecker
2023-10-15 00:46:53,670 ERROR [o.a.c.v.UnmanagedVMsManagerImpl] (API-Job-Executor-39:ctx-34bf195a job-48 ctx-6068b350) (logid:35038313) Failed to import Unmanaged VM [i-2-5-VM] because the service offering [7138dcd2-e85b-47b4-8c4a-2f5684b0779a] is not compatible due to [Service offering (7138dcd2-e85b-47b4-8c4a-2f5684b0779a) 500MHz CPU speed does not match VM CPU speed 250MHz and VM is not in powered off state (Power state: PowerOn)].
org.apache.cloudstack.api.ServerApiException: Service offering (7138dcd2-e85b-47b4-8c4a-2f5684b0779a) 500MHz CPU speed does not match VM CPU speed 250MHz and VM is not in powered off state (Power state: PowerOn)
	at org.apache.cloudstack.vm.UnmanagedVMsManagerImpl.getUnmanagedInstanceServiceOffering(UnmanagedVMsManagerImpl.java:430)
	at org.apache.cloudstack.vm.UnmanagedVMsManagerImpl.importVirtualMachineInternal(UnmanagedVMsManagerImpl.java:928)
	at org.apache.cloudstack.vm.UnmanagedVMsManagerImpl.importUnmanagedInstance(UnmanagedVMsManagerImpl.java:1259)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
	at com.sun.proxy.$Proxy444.importUnmanagedInstance(Unknown Source)
	at org.apache.cloudstack.api.command.admin.vm.ImportUnmanagedInstanceCmd.execute(ImportUnmanagedInstanceCmd.java:295)
	at com.cloud.api.ApiDispatcher.dispatch(ApiDispatcher.java:172)
	at com.cloud.api.ApiAsyncJobDispatcher.runJob(ApiAsyncJobDispatcher.java:112)
	at org.apache.cloudstack.framework.jobs.impl.AsyncJobManagerImpl$5.runInContext(AsyncJobManagerImpl.java:634)
	at org.apache.cloudstack.managed.context.ManagedContextRunnable$1.run(ManagedContextRunnable.java:48)
	at org.apache.cloudstack.managed.context.impl.DefaultManagedContext$1.call(DefaultManagedContext.java:55)
	at org.apache.cloudstack.managed.context.impl.DefaultManagedContext.callWithContext(DefaultManagedContext.java:102)
	at org.apache.cloudstack.managed.context.impl.DefaultManagedContext.runWithContext(DefaultManagedContext.java:52)
	at org.apache.cloudstack.managed.context.ManagedContextRunnable.run(ManagedContextRunnable.java:45)
	at org.apache.cloudstack.framework.jobs.impl.AsyncJobManagerImpl$5.run(AsyncJobManagerImpl.java:582)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
2023-10-15 00:46:53,672 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-39:ctx-34bf195a job-48) (logid:35038313) Complete async job-48, jobStatus: FAILED, resultCode: 530, result: org.apache.cloudstack.api.response.ExceptionResponse/null/{"uuidList":[],"errorcode":"530","errortext":"Failed to import Unmanaged VM [i-2-5-VM] because the service offering [7138dcd2-e85b-47b4-8c4a-2f5684b0779a] is not compatible due to [Service offering (7138dcd2-e85b-47b4-8c4a-2f5684b0779a) 500MHz CPU speed does not match VM CPU speed 250MHz and VM is not in powered off state (Power state: PowerOn)]."}
2023-10-15 00:46:53,672 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-39:ctx-34bf195a job-48) (logid:35038313) Publish async job-48 complete on message bus
2023-10-15 00:46:53,672 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-39:ctx-34bf195a job-48) (logid:35038313) Wake up jobs related to job-48
2023-10-15 00:46:53,672 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-39:ctx-34bf195a job-48) (logid:35038313) Update db status for job-48
2023-10-15 00:46:53,673 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-39:ctx-34bf195a job-48) (logid:35038313) Wake up jobs joined with job-48 and disjoin all subjobs created from job- 48
2023-10-15 00:46:53,677 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (API-Job-Executor-39:ctx-34bf195a job-48) (logid:35038313) Done executing org.apache.cloudstack.api.command.admin.vm.ImportUnmanagedInstanceCmd for job-48

I have tried also through the API but still hitting the same issue:

(localcloud) 🐱 > import unmanagedinstance name=i-2-5-VM displayname=test-vm3 serviceofferingid=7138dcd2-e85b-47b4-8c4a-2f5684b0779a templateid=00605e48-6639-11ee-80ce-1e00b100022f clusterid=7efee018-9300-4b01-b9be-e6eaffbb74c5 nicnetworklist[0].nic=0 nicnetworklist[0].network=92533133-1361-4bf7-a109-31ea6456b961
{
  "account": "admin",
  "accountid": "29a6621b-6639-11ee-80ce-1e00b100022f",
  "cmd": "org.apache.cloudstack.api.command.admin.vm.ImportUnmanagedInstanceCmd",
  "completed": "2023-10-15T00:52:53+0000",
  "created": "2023-10-15T00:52:53+0000",
  "domainid": "005a7503-6639-11ee-80ce-1e00b100022f",
  "domainpath": "ROOT",
  "jobid": "ed443bee-8284-4b24-82f9-75e47e5ac3d9",
  "jobprocstatus": 0,
  "jobresult": {
    "errorcode": 530,
    "errortext": "Failed to import Unmanaged VM [i-2-5-VM] because the service offering [7138dcd2-e85b-47b4-8c4a-2f5684b0779a] is not compatible due to [Service offering (7138dcd2-e85b-47b4-8c4a-2f5684b0779a) 500MHz CPU speed does not match VM CPU speed 250MHz and VM is not in powered off state (Power state: PowerOn)]."
  },
  "jobresultcode": 530,
  "jobresulttype": "object",
  "jobstatus": 2,
  "userid": "29a86c50-6639-11ee-80ce-1e00b100022f"
}

Let me know if you need some help on this if you are not able to reproduce it, I could investigate and push a fix

@itsayushpandey
Copy link
Author

@nvazquez my understanding is that expected behaviour for KVM is hostname is not same as VM Name. I think that is only for VMWare? Or may be I am misunderstanding the https://cloudstack.apache.org/api/apidocs-4.14/apis/importUnmanagedInstance.html (the host name of the instance) as the host's name on which the VM exist. But instead it means the VM's name on the host? Please let me know and I can revise code?

@nvazquez
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@nvazquez a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 7452

@yadvr
Copy link
Member

yadvr commented Oct 25, 2023

@nvazquez are you able to proceed further on this?
@blueorangutan package

@blueorangutan
Copy link

@rohityadavcloud a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 7498

@nvazquez
Copy link
Contributor

Yes @rohityadavcloud I had a sync with @itsayushpandey and I will be checking the remaining issues

Copy link
Contributor

@shwstppr shwstppr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks promising. Added some comments. Would need testing
If there are assumptions and prerequisites for KVM import/unmanage they must be updated in the official docs

Comment on lines +90 to +96
@Parameter(name = ApiConstants.SERVICE_OFFERING_ID,
type = CommandType.UUID,
entityType = ServiceOfferingResponse.class,
required = true,
description = "the ID of the service offering for the virtual machine")
private Long serviceOfferingId;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this refactoring needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was a harmless refactoring as it moves all required params together. I can change back if you think it doesn't add value?

Comment on lines +528 to +529
if (diskIdsWithoutOffering.size() > 1 || rootDisk == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("VM has total %d disks, disk offering mapping not provided for %d disks. Disk IDs that may need a disk offering - %s", disks.size(), diskIdsWithoutOffering.size() - 1, String.join(", ", diskIdsWithoutOffering)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case rootDisk is null at this point when we have already checked callerDiskIds.size() != disks.size() - 1?

} else {
dataDisks.add(disk);
DiskOffering diskOffering = diskOfferingDao.findById(dataDiskOfferingMap.getOrDefault(disk.getDiskId(), null));
if ((disk.getCapacity() == null || disk.getCapacity() <= 0) && diskOffering != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we not getting capacity from the hypervisor?

(StringUtils.isEmpty(networkBroadcastUri) || !String.format("pvlan://%d-%s%d", nic.getVlan(), pvLanType, nic.getPvlan()).equals(networkBroadcastUri))) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("PVLAN of network(ID: %s) %s is found different from the VLAN of nic(ID: %s) pvlan://%d-%s%d during VM import", network.getUuid(), networkBroadcastUri, nic.getNicId(), nic.getVlan(), pvLanType, nic.getPvlan()));
private void checksOnlyNeededForVmware(UnmanagedInstanceTO.Nic nic, Network network, final Hypervisor.HypervisorType hypervisorType) {
if (hypervisorType == Hypervisor.HypervisorType.VMware) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not return early if it is not VMware
if (!Hypervisor.HypervisorType.VMware.equals(hypervisorType)) {
return;
//continue with rest

Question - why VLAN checks are not needed for KVM?

allDetails.put(VmDetailConstants.NIC_ADAPTER, unmanagedInstance.getNics().get(0).getAdapterType());
}

if (StringUtils.isNotEmpty(unmanagedInstance.getVncPassword())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should there be a hypervisor check?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think its needed as for missing VNC password, we don't execute it at all and code remains simple?

(My thinking was that hypervisors plugins that need to pass back VNC password will set it in UnmanagedInstanceTO, and if it is passed we process it here without worrying about hypervisor type.)

throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Unable to retrieve details for unmanaged VM: %s", name));
}

if (template.getName().equals(VM_IMPORT_DEFAULT_TEMPLATE_NAME) && cluster.getHypervisorType().equals(Hypervisor.HypervisorType.KVM)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question - why import with default template is not allowed for KVM?

@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] { UnmanageVMPreserveNic };
return new ConfigKey<?>[]{UnmanageVMPreserveNic};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be from IntelliJ auto formatting from some rules I had setup. If this is against formatting conventions, I can revert it?

nullable(String.class), nullable(Hypervisor.HypervisorType.class), nullable(Map.class), nullable(VirtualMachine.PowerState.class))).thenReturn(userVm);
NetworkVO networkVO = Mockito.mock(NetworkVO.class);
when(networkVO.getGuestType()).thenReturn(Network.GuestType.L2);
when(networkVO.getBroadcastUri()).thenReturn(URI.create(String.format("vlan://%d", instanceNic.getVlan())));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? Not used anymore/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mocking was not needed (tests pass after removal) after refactoring in other PRs (not this PR). So after rebasing, I was getting Mockito failures and so is not needed anymore.

:key="network.id"
:label="network.displaytext + (network.broadcasturi ? ' (' + network.broadcasturi + ')' : '')">
{{ network.displaytext + (network.broadcasturi ? ' (' + network.broadcasturi + ')' : '') }}
<div v-if="this.hypervisor === 'KVM'">{{ network.displaytext + ' - ' + (network.id.slice(0,8)) }}</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea about these constants. Would be better to make a new method with some doc

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can create a separate method for generating this string?

Context: This is the label for network name in selection dropdown. Since displaytext can be non-unique, I added 8 characters of the UUID for differentiating in case of KVM. For VMWare we had broadcast URI from Vlan.

@github-actions
Copy link

github-actions bot commented Nov 3, 2023

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@shwstppr
Copy link
Contributor

shwstppr commented Nov 3, 2023

@itsayushpandey cc @nvazquez can you please check and address merge conflicts?

Will this be ready for testing for 4.19.0?

@nvazquez
Copy link
Contributor

nvazquez commented Nov 3, 2023

Yes @shwstppr I'll be addressing the issues soon and move it forward for testing along with KVM ingestion

@nvazquez
Copy link
Contributor

nvazquez commented Nov 8, 2023

Hi guys, I'm closing this issue as the work introduced on this PR has been included on #7976 to be tested in parallel (commit: 7e14f84)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend Import-Export Instances to the KVM Hypervisor

8 participants