func()

in machine.go [171:214]


func (cfg *Config) Validate() error {
	if cfg.DisableValidation {
		return nil
	}

	if _, err := os.Stat(cfg.KernelImagePath); err != nil {
		return fmt.Errorf("failed to stat kernel image path, %q: %v", cfg.KernelImagePath, err)
	}

	if cfg.InitrdPath != "" {
		if _, err := os.Stat(cfg.InitrdPath); err != nil {
			return fmt.Errorf("failed to stat initrd image path, %q: %v", cfg.InitrdPath, err)
		}
	}

	for _, drive := range cfg.Drives {
		if BoolValue(drive.IsRootDevice) {
			rootPath := StringValue(drive.PathOnHost)
			if _, err := os.Stat(rootPath); err != nil {
				return fmt.Errorf("failed to stat host drive path, %q: %v", rootPath, err)
			}

			break
		}
	}

	// Check the non-existence of some files:
	if _, err := os.Stat(cfg.SocketPath); err == nil {
		return fmt.Errorf("socket %s already exists", cfg.SocketPath)
	}

	if cfg.MachineCfg.VcpuCount == nil ||
		Int64Value(cfg.MachineCfg.VcpuCount) < 1 {
		return fmt.Errorf("machine needs a nonzero VcpuCount")
	}
	if cfg.MachineCfg.MemSizeMib == nil ||
		Int64Value(cfg.MachineCfg.MemSizeMib) < 1 {
		return fmt.Errorf("machine needs a nonzero amount of memory")
	}
	if cfg.MachineCfg.HtEnabled == nil {
		return fmt.Errorf("machine needs a setting for ht_enabled")
	}
	return nil
}