Working VM image retrieval
This commit is contained in:
parent
e09ad7d1c9
commit
0f74f4aa81
4 changed files with 66 additions and 12 deletions
19
cmd/root.go
19
cmd/root.go
|
|
@ -2,6 +2,8 @@ package cmd
|
|||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"log/slog"
|
||||
|
||||
|
|
@ -29,6 +31,7 @@ var unrestrictedNetworkingFlag bool
|
|||
var vmMemAllocFlag uint32
|
||||
var vmSSHSetupTimeoutFlag uint32
|
||||
var vmOSUpTimeoutFlag uint32
|
||||
var dataDirFlag string
|
||||
|
||||
// TODO: Version command.
|
||||
|
||||
|
|
@ -44,4 +47,20 @@ func init() {
|
|||
rootCmd.PersistentFlags().Uint32Var(&vmMemAllocFlag, "vm-mem-alloc", 512, "Specifies the VM memory allocation in KiB")
|
||||
rootCmd.PersistentFlags().Uint32Var(&vmOSUpTimeoutFlag, "vm-os-up-timeout", 30, "Specifies the VM OS-up timeout in seconds.")
|
||||
rootCmd.PersistentFlags().Uint32Var(&vmSSHSetupTimeoutFlag, "vm-ssh-setup-timeout", 60, "Specifies the VM SSH server setup timeout in seconds. This cannot be lower than the OS-up timeout.")
|
||||
|
||||
defaultDataDir := "linsk-data-dir"
|
||||
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
slog.Error("Failed to get user home directory, will use a local directory as a fallback", "error", err.Error(), "dir", defaultDataDir)
|
||||
} else {
|
||||
homeDirName := ".linsk"
|
||||
if runtime.GOOS == "windows" {
|
||||
homeDirName = "Linsk"
|
||||
}
|
||||
|
||||
defaultDataDir = filepath.Join(homeDir, homeDirName)
|
||||
}
|
||||
|
||||
rootCmd.PersistentFlags().StringVar(&dataDirFlag, "data-dir", defaultDataDir, "Specifies the data directory (folder) to use. The VM images will be stored here.")
|
||||
}
|
||||
|
|
|
|||
15
cmd/utils.go
15
cmd/utils.go
|
|
@ -14,6 +14,7 @@ import (
|
|||
|
||||
"log/slog"
|
||||
|
||||
"github.com/AlexSSD7/linsk/storage"
|
||||
"github.com/AlexSSD7/linsk/vm"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
|
@ -51,6 +52,18 @@ func doUSBRootCheck() {
|
|||
}
|
||||
|
||||
func runVM(passthroughArg string, fn func(context.Context, *vm.VM, *vm.FileManager) int, forwardPortsRules []vm.PortForwardingRule, unrestrictedNetworking bool) int {
|
||||
store, err := storage.NewStorage(slog.With("caller", "storage"), dataDirFlag)
|
||||
if err != nil {
|
||||
slog.Error("Failed to create Linsk data storage", "error", err.Error(), "data-dir", dataDirFlag)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
_, err = store.ValidateImageHashOrDownload()
|
||||
if err != nil {
|
||||
slog.Error("Failed to validate image hash or download image", "error", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var passthroughConfig vm.PassthroughConfig
|
||||
|
||||
if passthroughArg != "" {
|
||||
|
|
@ -60,7 +73,7 @@ func runVM(passthroughArg string, fn func(context.Context, *vm.VM, *vm.FileManag
|
|||
|
||||
vmCfg := vm.VMConfig{
|
||||
Drives: []vm.DriveConfig{{
|
||||
Path: "alpine.qcow2",
|
||||
Path: store.GetLocalImagePath(),
|
||||
SnapshotMode: true,
|
||||
}},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue