REST API wrapper plugin for the virsh CLI tool


Recommended Posts

There have been other attempts at making an API for the Unraid VM manager, allowing for starting/stopping of VMs from another interface, like Home Assistant. However, from what I've seen those attempts relied on scraping of the Unraid Web UI using a headless browser.

 

I am wondering if anyone has tried creating a wrapper around the `virsh` CLI tool available on Unraid's shell to create an API to control VM functions. It seems like this would be possible to implement as an Unraid Plugin, or potentially even in a Docker container using chroot to allow command execution on the host. This, I imagine, would be much faster and lower overhead than using the Unraid UI scraping method to control VMs.

 

I am interesting in working on this, but I don't have any experience making Unraid Plugins or apps.

Link to comment
23 minutes ago, Daniel Heppner said:

There have been other attempts at making an API for the Unraid VM manager, allowing for starting/stopping of VMs from another interface, like Home Assistant. However, from what I've seen those attempts relied on scraping of the Unraid Web UI using a headless browser.

 

I am wondering if anyone has tried creating a wrapper around the `virsh` CLI tool available on Unraid's shell to create an API to control VM functions. It seems like this would be possible to implement as an Unraid Plugin, or potentially even in a Docker container using chroot to allow command execution on the host. This, I imagine, would be much faster and lower overhead than using the Unraid UI scraping method to control VMs.

 

I am interesting in working on this, but I don't have any experience making Unraid Plugins or apps.

You can expose libvirt externally, and there are php python apis for libvirt.

 

is it just start and stop you are looking for?

  • Like 1
Link to comment
48 minutes ago, SimonF said:

You can expose libvirt externally, and there are php python apis for libvirt.

 

is it just start and stop you are looking for?

Interesting! Yes, the libvert library for Python looks like an excellent way of achieving this. Do you know if it's possible to access host VMs from inside a privileged Docker container? I'd like to package this as a container since it runs a web server.

 

But yes, all I really need is the basic functions; start, stop, kill, and list. Not looking for a full control of available domains or anything like that via API.

Link to comment
2 minutes ago, Daniel Heppner said:

Interesting! Yes, the libvert library for Python looks like an excellent way of achieving this. Do you know if it's possible to access host VMs from inside a privileged Docker container? I'd like to package this as a container since it runs a web server.

 

But yes, all I really need is the basic functions; start, stop, kill, and list. Not looking for a full control of available domains or anything like that via API.

I use virt manager in a docker that can control/access vms have a look in ca for it as an example. I believe virt manager is written in python so you may be able to get examples from the github repo.

Link to comment
1 minute ago, SimonF said:

I use virt manager in a docker that can control/access vms have a look in ca for it as an example. I believe virt manager is written in python so you may be able to get examples from the github repo.

That is perfect and I literally just found that on my own before seeing your message. I think this proves that what I want to do is possible from within a Docker container, and it doesn't even need to be privileged. I think I have all the pieces I need, I just need to put them together now. Thanks for the help.

Link to comment
10 minutes ago, Daniel Heppner said:

That is perfect and I literally just found that on my own before seeing your message. I think this proves that what I want to do is possible from within a Docker container, and it doesn't even need to be privileged. I think I have all the pieces I need, I just need to put them together now. Thanks for the help.

You will need to update the virtlibd conf file to allow access, but not able to access my system to get config change

Link to comment
18 hours ago, Daniel Heppner said:

Interesting, I was able to install virt manager Docker container and it immediately worked with the default Docker settings.

Normally it is the following that needs to be changed but maybe only if external to host.

 

stock

 

listen_tcp = 1
#listen_addr = "192.168.0.1"
listen_addr = "127.0.0.1"

 

to

listen_tcp = 1
listen_addr = "0.0.0.0"

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.