func (conf *HypervisorConfig) CustomHypervisorAsset() bool {
	return conf.isCustomAsset(hypervisorAsset)
}
CustomHypervisorAsset returns true if the hypervisor asset is a custom one, false otherwise.
package virtcontainers
import (
	"bufio"
	"fmt"
	"os"
	"runtime"
	"strconv"
	"strings"
)
type HypervisorType string
const (
	QemuHypervisor HypervisorType = "qemu"
	MockHypervisor HypervisorType = "mock"
)
const (
	procMemInfo = "/proc/meminfo"
	procCPUInfo = "/proc/cpuinfo"
)
const (
	defaultVCPUs = 1
	defaultMemSzMiB = 2048
	defaultBridges = 1
	defaultBlockDriver = VirtioSCSI
)
var defaultMaxQemuVCPUs = maxQemuVCPUs()
type deviceType int
const (
	imgDev deviceType = iota
	fsDev
	netDev
	serialDev
	blockDev
	consoleDev
	serialPortDev
	vfioDev
	vhostuserDev
	cpuDev
)
func (hType *HypervisorType) Set(value string) error {
	switch value {
	case "qemu":
		*hType = QemuHypervisor
		return nil
	case "mock":
		*hType = MockHypervisor
		return nil
	default:
		return fmt.Errorf("Unknown hypervisor type %s", value)
	}
}
func (hType *HypervisorType) String() string {
	switch *hType {
	case QemuHypervisor:
		return string(QemuHypervisor)
	case MockHypervisor:
		return string(MockHypervisor)
	default:
		return ""
	}
}
func newHypervisor(hType HypervisorType) (hypervisor, error) {
	switch hType {
	case QemuHypervisor:
		return &qemu{}, nil
	case MockHypervisor:
		return &mockHypervisor{}, nil
	default:
		return nil, fmt.Errorf("Unknown hypervisor type %s", hType)
	}
}
func makeNameID(namedType string, id string) string {
	nameID := fmt.Sprintf("%s-%s", namedType, id)
	if len(nameID) > maxDevIDSize {
		nameID = string(nameID[:maxDevIDSize])
	}
	return nameID
}
type Param struct {
	Key   string
	Value string
}
type HypervisorConfig struct {
	KernelPath string
	ImagePath string
	FirmwarePath string
	MachineAccelerators string
	HypervisorPath string
	DisableBlockDeviceUse bool
	BlockDeviceDriver string
	KernelParams []Param
	HypervisorParams []Param
	HypervisorMachineType string
	Debug bool
	DefaultVCPUs uint32
	DefaultMaxVCPUs uint32
	DefaultMemSz uint32
	DefaultBridges uint32
	MemPrealloc bool
	HugePages bool
	Realtime bool
	Mlock bool
	DisableNestingChecks bool
	customAssets map[assetType]*asset
}
func (conf *HypervisorConfig) valid() (bool, error) {
	if conf.KernelPath == "" {
		return false, fmt.Errorf("Missing kernel path")
	}
	if conf.ImagePath == "" {
		return false, fmt.Errorf("Missing image path")
	}
	if conf.DefaultVCPUs == 0 {
		conf.DefaultVCPUs = defaultVCPUs
	}
	if conf.DefaultMemSz == 0 {
		conf.DefaultMemSz = defaultMemSzMiB
	}
	if conf.DefaultBridges == 0 {
		conf.DefaultBridges = defaultBridges
	}
	if conf.BlockDeviceDriver == "" {
		conf.BlockDeviceDriver = defaultBlockDriver
	}
	if conf.DefaultMaxVCPUs == 0 {
		conf.DefaultMaxVCPUs = defaultMaxQemuVCPUs
	}
	return true, nil
}
func (conf *HypervisorConfig) AddKernelParam(p Param) error {
	if p.Key == "" {
		return fmt.Errorf("Empty kernel parameter")
	}
	conf.KernelParams = append(conf.KernelParams, p)
	return nil
}
func (conf *HypervisorConfig) addCustomAsset(a *asset) error {
	if a == nil || a.path == "" {
		return nil
	}
	if !a.valid() {
		return fmt.Errorf("Invalid %s at %s", a.kind, a.path)
	}
	virtLog.Debugf("Using custom %v asset %s", a.kind, a.path)
	if conf.customAssets == nil {
		conf.customAssets = make(map[assetType]*asset)
	}
	conf.customAssets[a.kind] = a
	return nil
}
func (conf *HypervisorConfig) assetPath(t assetType) (string, error) {
	a, ok := conf.customAssets[t]
	if ok {
		return a.path, nil
	}
	switch t {
	case kernelAsset:
		return conf.KernelPath, nil
	case imageAsset:
		return conf.ImagePath, nil
	case hypervisorAsset:
		return conf.HypervisorPath, nil
	case firmwareAsset:
		return conf.FirmwarePath, nil
	default:
		return "", fmt.Errorf("Unknown asset type %v", t)
	}
}
func (conf *HypervisorConfig) isCustomAsset(t assetType) bool {
	_, ok := conf.customAssets[t]
	if ok {
		return true
	}
	return false
}
func (conf *HypervisorConfig) KernelAssetPath() (string, error) {
	return conf.assetPath(kernelAsset)
}
func (conf *HypervisorConfig) CustomKernelAsset() bool {
	return conf.isCustomAsset(kernelAsset)
}
func (conf *HypervisorConfig) ImageAssetPath() (string, error) {
	return conf.assetPath(imageAsset)
}
func (conf *HypervisorConfig) CustomImageAsset() bool {
	return conf.isCustomAsset(imageAsset)
}
func (conf *HypervisorConfig) HypervisorAssetPath() (string, error) {
	return conf.assetPath(hypervisorAsset)
}