Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart a Virtual Machine #263

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Conversation

Dhamo1107
Copy link
Contributor

This PR introduces the "Restart VM" feature for VMs managed by the KubeVirt infrastructure provider in ManageIQ.

Testing:
Verified the restart functionality for KubeVirt VMs via the UI.

Before: "Restart Guest" option is disabled for KubeVirt VMs.

After: "Restart Guest" button available and functional for KubeVirt VMs.
image
image

@Fryguy Kindly take a look at this and review the PR. Thank you!

Copy link
Member

@agrare agrare left a comment

Choose a reason for hiding this comment

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

❤️ thanks so much @Dhamo1107 !

app/models/manageiq/providers/kubevirt/infra_manager/vm.rb Outdated Show resolved Hide resolved
ext_management_system.with_provider_connection(:namespace => location) do |connection|
# Retrieve the details of the virtual machine:
vm = connection.vm(name)
vm.restart
Copy link
Member

Choose a reason for hiding this comment

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

I need to see if vm.restart do a "soft" reboot via the guest or a restart via the virtualized hardware. That would dictate if we call this reboot_guest or reset

Copy link
Member

Choose a reason for hiding this comment

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

Based on the API docs it looks like VirtualMachine#restart is a hardware reset and VirtualMachineInstance#softreboot is what we would call a reboot_guest

Copy link
Member

Choose a reason for hiding this comment

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

I think this method is good if you rename it def reset and then if we add a reboot_guest which uses vmi = connection.vm_instance(name) then you can vmi.softreboot on that object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this in power.rb:
image
and i got this error:
image

Copy link
Member

@nasark nasark Dec 10, 2024

Choose a reason for hiding this comment

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

I think you may need to implement raw_reboot_guest and raw_reset in something like module ManageIQ::Providers::Kubevirt::InfraManager::Vm::Operations::Guest https://github.com/ManageIQ/manageiq/blob/master/app/models/vm/operations/guest.rb

Copy link
Member

Choose a reason for hiding this comment

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

I forgot that with_provider_connection is still using fog-kubevirt since @nasark's most recent work here was using kubeclient. I don't see restart or softreboot in fog-kubevirt so we might have an issue there.

Given that we want to move towards kubeclient in the near future as a replacement for fog-kubevirt I think we'd be better off going in that direction rather than adding restart/soft_reboot to fog-kubevirt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @agrare, As suggested I’ve connected to the VM using the following code:

kubevirt = ext_management_system.parent_manager.connect(:service => "kubernetes", :path => "/apis/subresources.kubevirt.io", :version => "v1")

However, I’m not sure which method should be called on this kubevirt instance to perform the restart and reset operation (like kubevirt.create_virtual_machine_snapshot). I assume a similar operation should be implemented here using kubeclient. Can you please advise on the correct method I should use for this purpose?

Copy link
Member

@agrare agrare Dec 12, 2024

Choose a reason for hiding this comment

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

Yeah so it looks like kubeclient doesn't pick up on the methods like reset and softreboot because the kubevirt.io API operations don't match the rest of the k8s apis.
I was able to restart and softreboot vms with:

kubevirt = ext_management_system.parent_manager.connect(:service => "kubernetes", :path => "/apis/subresources.kubevirt.io", :version => "v1")
kubevirt.rest_client['namespaces/manageiq/virtualmachines/fedora-jade-owl-56/restart'].put({}.to_json, { 'Content-Type' => 'application/json' }.merge(client.get_headers))
kubevirt.rest_client['namespaces/manageiq/virtualmachineinstances/fedora-jade-owl-56/softreboot'].put({}.to_json, { 'Content-Type' => 'application/json' }.merge(client.get_headers))

@agrare
Copy link
Member

agrare commented Dec 16, 2024

Hey @Dhamo1107 FYI it looks like you have a merge commit in here, in our recommended git config https://www.manageiq.org/docs/guides/developer_setup/git_workflow we recommend git config --global --bool pull.rebase true so that you can git pull upstream master and it will rebase your commits onto master, rather than creating a new merge commit in your branch. That just helps us keep the history a little cleaner.

@Dhamo1107
Copy link
Contributor Author

Hi @agrare, Got it, thanks for the input, I’ll update it as recommended

@agrare
Copy link
Member

agrare commented Dec 16, 2024

I tested these changes and the reboot works perfectly, I saw a 500 error with soft_restart (I also hit this using kubeclient directly so it isn't anything in your PR that is causing it)

[----] E, [2024-12-16T10:26:20.612321#175292:97e0] ERROR -- evm: MIQ(MiqQueue#m_callback) Message id: [15721]: 500 Internal Server Error
[----] E, [2024-12-16T10:26:20.612535#175292:97e0] ERROR -- evm: [RestClient::InternalServerError]: 500 Internal Server Error  Method:[block (2 levels) in <class:LogProxy>]
[----] E, [2024-12-16T10:26:20.612641#175292:97e0] ERROR -- evm: /home/grare/adam/.gem/ruby/3.3.0/gems/rest-client-2.1.0/lib/restclient/abstract_response.rb:249:in `exception_with_response'
/home/grare/adam/.gem/ruby/3.3.0/gems/rest-client-2.1.0/lib/restclient/abstract_response.rb:129:in `return!'
/home/grare/adam/.gem/ruby/3.3.0/gems/rest-client-2.1.0/lib/restclient/request.rb:836:in `process_result'
/home/grare/adam/.gem/ruby/3.3.0/gems/rest-client-2.1.0/lib/restclient/request.rb:743:in `block in transmit'
/usr/lib/ruby/3.3.0/net/http.rb:1570:in `start'
/home/grare/adam/.gem/ruby/3.3.0/gems/rest-client-2.1.0/lib/restclient/request.rb:727:in `transmit'
/home/grare/adam/.gem/ruby/3.3.0/gems/rest-client-2.1.0/lib/restclient/request.rb:163:in `execute'
/home/grare/adam/.gem/ruby/3.3.0/gems/rest-client-2.1.0/lib/restclient/request.rb:63:in `execute'
/home/grare/adam/.gem/ruby/3.3.0/gems/rest-client-2.1.0/lib/restclient/resource.rb:79:in `put'
/home/grare/adam/src/manageiq/manageiq-providers-kubevirt/app/models/manageiq/providers/kubevirt/infra_manager/vm/operations/guest.rb:5:in `raw_reboot_guest'

The VM does restart, it happens too quickly to see if the guest came down cleanly. Possibly an issue with communicating with the guest tools? Not sure...

# Conflicts:
#	app/models/manageiq/providers/kubevirt/infra_manager/vm.rb
#	app/models/manageiq/providers/kubevirt/infra_manager/vm/operations.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Radjabov
Development

Successfully merging this pull request may close these issues.

4 participants