mirror of
https://github.com/linka-cloud/d2vm.git
synced 2025-07-04 10:32:27 +00:00
run/qemu: remove usb and device flags
refactor: move qemu to its own package tests: implements end to end tests for the convert command with the following images: alpine:3.17, ubuntu:20.04, debian:11, centos:8 Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
141
pkg/qemu/config.go
Normal file
141
pkg/qemu/config.go
Normal file
@ -0,0 +1,141 @@
|
||||
// Copyright 2023 Linka Cloud All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package qemu
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Option func(c *config)
|
||||
|
||||
type Disk struct {
|
||||
Path string
|
||||
Size int
|
||||
Format string
|
||||
}
|
||||
|
||||
type PublishedPort struct {
|
||||
Guest uint16
|
||||
Host uint16
|
||||
Protocol string
|
||||
}
|
||||
|
||||
// config contains the config for Qemu
|
||||
type config struct {
|
||||
path string
|
||||
uuid uuid.UUID
|
||||
gui bool
|
||||
disks []Disk
|
||||
networking string
|
||||
arch string
|
||||
cpus uint
|
||||
memory uint
|
||||
accel string
|
||||
detached bool
|
||||
qemuBinPath string
|
||||
qemuImgPath string
|
||||
publishedPorts []PublishedPort
|
||||
netdevConfig string
|
||||
|
||||
stdin io.Reader
|
||||
stdout io.Writer
|
||||
stderr io.Writer
|
||||
}
|
||||
|
||||
func WithGUI() Option {
|
||||
return func(c *config) {
|
||||
c.gui = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithDisks(disks ...Disk) Option {
|
||||
return func(c *config) {
|
||||
c.disks = disks
|
||||
}
|
||||
}
|
||||
|
||||
func WithNetworking(networking string) Option {
|
||||
return func(c *config) {
|
||||
c.networking = networking
|
||||
}
|
||||
}
|
||||
|
||||
func WithArch(arch string) Option {
|
||||
return func(c *config) {
|
||||
c.arch = arch
|
||||
}
|
||||
}
|
||||
|
||||
func WithCPUs(cpus uint) Option {
|
||||
return func(c *config) {
|
||||
c.cpus = cpus
|
||||
}
|
||||
}
|
||||
|
||||
func WithMemory(memory uint) Option {
|
||||
return func(c *config) {
|
||||
c.memory = memory
|
||||
}
|
||||
}
|
||||
|
||||
func WithAccel(accel string) Option {
|
||||
return func(c *config) {
|
||||
c.accel = accel
|
||||
}
|
||||
}
|
||||
|
||||
func WithDetached() Option {
|
||||
return func(c *config) {
|
||||
c.detached = true
|
||||
}
|
||||
}
|
||||
|
||||
func WithQemuBinPath(path string) Option {
|
||||
return func(c *config) {
|
||||
c.qemuBinPath = path
|
||||
}
|
||||
}
|
||||
|
||||
func WithQemuImgPath(path string) Option {
|
||||
return func(c *config) {
|
||||
c.qemuImgPath = path
|
||||
}
|
||||
}
|
||||
|
||||
func WithPublishedPorts(ports ...PublishedPort) Option {
|
||||
return func(c *config) {
|
||||
c.publishedPorts = ports
|
||||
}
|
||||
}
|
||||
|
||||
func WithStdin(r io.Reader) Option {
|
||||
return func(c *config) {
|
||||
c.stdin = r
|
||||
}
|
||||
}
|
||||
|
||||
func WithStdout(w io.Writer) Option {
|
||||
return func(c *config) {
|
||||
c.stdout = w
|
||||
}
|
||||
}
|
||||
|
||||
func WithStderr(w io.Writer) Option {
|
||||
return func(c *config) {
|
||||
c.stderr = w
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user