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

Support for Virt driver #2032

Closed
wants to merge 2 commits into from
Closed

Support for Virt driver #2032

wants to merge 2 commits into from

Conversation

afbjorklund
Copy link
Member

@afbjorklund afbjorklund commented Nov 25, 2023

This is a driver based on libvirt.org, for remote hypervisors.

The libvirt functions are in a plugin, to minimize dependencies.


Currently only shows version:

var VERSION uint32 = libvirt.VERSION_NUMBER

func Version() (uint32, error) { return libvirt.GetVersion() }

To prove that it can access the API.

@@ -30,3 +30,9 @@ config GUESTAGENT_ARCH_RISCV64
help
Build lima-guestagent for "riscv64" Arch
default y

config PLUGIN_VIRT
bool "plugin for vmType virt"
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 should be called "libvirt"

Copy link
Member

Choose a reason for hiding this comment

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

I also wonder if we can split out this to a separate plugin binary.

Same applies to the vbox driver, cloud drivers, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, it just requires more work. And it would be needed, for cloud.

@afbjorklund
Copy link
Member Author

afbjorklund commented Nov 26, 2023

Apparently this experiment does not work, since putting libvirt in go.mod requires libvirt-dev:

 No package 'libvirt' found
  Package libvirt was not found in the pkg-config search path.
  Perhaps you should add the directory containing `libvirt.pc'
  to the PKG_CONFIG_PATH environment variable

This makes it impossible to disable, even if it is not used during the build.

So it would need a separate module.

This is a driver based on libvirt.org, for remote hypervisors.

The libvirt functions are in a plugin, to minimize dependencies.

Currently only shows version.

Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
Simple test to see if the machine would even start properly.

Needs more code for qemu:///system, like storage and network.

Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
@afbjorklund
Copy link
Member Author

  1. Running "session" qemu with libvirt doesn't add any except complexity (until there is proper "system" qemu support)
  2. Trying to load libvirt from a plugin doesn't work due to go modules, needs a separate binary like docker-machine-kvm

@afbjorklund
Copy link
Member Author

afbjorklund commented Nov 29, 2023

All that you needed to do was to set the build tag libvirt_dlopen, then it doesn't need pkgconfig or the libraries...
(and that means that there is no real need to use the plugin module, but go straight for RPC for external drivers)

@afbjorklund
Copy link
Member Author

afbjorklund commented Nov 29, 2023

Hmm, libvirt has dozens of connection points (function wrappers) so maybe it should be a plugin after all.
Then Go would still dlopen the virt.so plugin, which would in turn dlopen the libvirt.so.0 library (et al).

@AkihiroSuda
Copy link
Member

Would it be possible to just exec virsh?

@afbjorklund
Copy link
Member Author

afbjorklund commented Nov 29, 2023

Yes, that should work. Something like virsh create {{.Dir}}/domain.xml

func CreateDomain(xml string) error {
	conn, err := libvirt.NewConnect(connectString)
	if err != nil {
		return err
	}
	defer conn.Close()
	vm, err := conn.DomainDefineXML(xml)
	if err != nil {
		return err
	}
	return vm.Create()
}

@afbjorklund
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants