Example of usage
raju010193 opened this issue · 8 comments
Can you please provide usage with simple example in golang.
There is one simple example in the repo that launches and shuts down a VM.
https://github.com/intel/govmm/blob/master/qemu/examples_test.go
It builds its command line manually rather than using the structures in qemu.go
Kata Containers, another good example, https://github.com/kata-containers/runtime/blob/master/virtcontainers/qemu.go
There is one simple example in the repo that launches and shuts down a VM.
https://github.com/intel/govmm/blob/master/qemu/examples_test.go
It builds its command line manually rather than using the structures in qemu.go
i tried this example but i am getting error like panic: exit status 1. actually i am new to golang
The example expects to find a qcow2 image at the file /tmp/image.qcow2. Try placing a qcow image at this location or modifying the example to point to a qcow file on your machine. Probably best to make a copy of this file first. If this doesn't work, try add " -display none -vga none" to the list of parameters passed to qemu, e.g.,
params = append(params, "-display", "none", "-vga", "none")
point
params := make([]string, 0, 32)
// Rootfs
params = append(params, "-drive", "file=/home/swamym/Downloads/ubuntu.qcow2,if=virtio,aio=threads,format=qcow2")
// Network
params = append(params, "-net", "nic,model=virtio", "-net", "user")
// kvm
params = append(params, "-enable-kvm", "-cpu", "host")
// qmp socket
params = append(params, "-daemonize", "-qmp", "unix:/home/swamym/Downloads/qmp-socket,server,nowait")
// resources
params = append(params, "-m", "2048", "-smp", "cpus=2")
params = append(params, "-display", "none", "-vga", "none")
// LaunchCustomQemu should return as soon as the instance has launched as we
// are using the --daemonize flag. It will set up a unix domain socket
// called /tmp/qmp-socket that we can use to manage the instance.
var (
file []*os.File
)
f, _ := os.Open("/home/swamym/Downloads/ubuntu-20.04-desktop-amd64.iso")
file = append(file,f)
fmt.Println(*f)
_, err := qemu.LaunchCustomQemu(context.Background(), "", params, file, nil, nil)
if err != nil {
panic(err)
}
// This channel will be closed when the instance dies.
disconnectedCh := make(chan struct{})
// Set up our options. We don't want any logging or to receive any events.
cfg := qemu.QMPConfig{}
// Start monitoring the qemu instance. This functon will block until we have
// connect to the QMP socket and received the welcome message.
q, _, err := qemu.QMPStart(context.Background(), "/home/swamym/Downloads/qmp-socket", cfg, disconnectedCh)
if err != nil {
panic(err)
}
// This has to be the first command executed in a QMP session.
err = q.ExecuteQMPCapabilities(context.Background())
if err != nil {
panic(err)
}
// Let's try to shutdown the VM. If it hasn't shutdown in 10 seconds we'll
// send a quit message.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
err = q.ExecuteSystemPowerdown(ctx)
cancel()
if err != nil {
err = q.ExecuteQuit(context.Background())
if err != nil {
panic(err)
}
}
q.Shutdown()
i got error here LaunchCustomQemu, its exits the process why?
can you please explain clearly. i tried multiple ways but why its not working
Unfortunately, govmm doesn't capture the error message that qemu prints to the screen when a VM fails to start. The easiest way to see why your example isn't working is to place a fmt.Println(params) before the call to qemu.LaunchCustomQemu which should give you the list of parameters that are being passed to qemu. Then try manually launching qemu with these parameters from the command line, e.g.,
qemu-system-x86_64 my params
and see what error you get. You might want to try this without the .iso you're opening first.
okay,, We have aws instance and kvm already installed, now question is we need to connect AWS instance connect remotely and access the kvm . create the machine from my local device, do you have any idea about it?
As the GoVMM project has been moved under the Kata Containers project, please, feel free to open a new issue there in case you're still hitting it.
For now I'm closing the issue as there's no activity here since June 2020.