mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-09-30 03:51:43 +02:00
Better state syncing and other improvements (#24)
This commit is contained in:
@@ -21,7 +21,7 @@ func newCreateVMCommand() *cobra.Command {
|
||||
|
||||
command.PersistentFlags().StringVar(&image, "image", "ghcr.io/cirruslabs/macos-ventura-base:latest", "image to use")
|
||||
command.PersistentFlags().Uint64Var(&cpu, "cpu", 4, "number of CPUs to use")
|
||||
command.PersistentFlags().Uint64Var(&memory, "memory", 8, "gigabytes of memory to use")
|
||||
command.PersistentFlags().Uint64Var(&memory, "memory", 8*1024, "megabytes of memory to use")
|
||||
command.PersistentFlags().BoolVar(&softnet, "softnet", false, "whether to use Softnet network isolation")
|
||||
command.PersistentFlags().BoolVar(&headless, "headless", true, "whether to run without graphics")
|
||||
|
||||
|
||||
@@ -21,5 +21,5 @@ func runDeleteVM(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return client.VMs().Delete(cmd.Context(), name, false)
|
||||
return client.VMs().Delete(cmd.Context(), name)
|
||||
}
|
||||
|
||||
@@ -6,8 +6,12 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/zap"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var devDataDirPath string
|
||||
|
||||
func NewCommand() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
Use: "dev",
|
||||
@@ -15,6 +19,9 @@ func NewCommand() *cobra.Command {
|
||||
RunE: runDev,
|
||||
}
|
||||
|
||||
command.PersistentFlags().StringVarP(&devDataDirPath, "data-dir", "d", ".dev-data",
|
||||
"path to persist data between runs")
|
||||
|
||||
return command
|
||||
}
|
||||
|
||||
@@ -30,12 +37,15 @@ func runDev(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}()
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
return err
|
||||
if !filepath.IsAbs(devDataDirPath) {
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
devDataDirPath = path.Join(pwd, devDataDirPath)
|
||||
}
|
||||
|
||||
dataDir, err := controller.NewDataDir(tempDir)
|
||||
dataDir, err := controller.NewDataDir(devDataDirPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -46,7 +56,7 @@ func runDev(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
worker, err := worker.New(worker.WithDataDirPath(tempDir), worker.WithLogger(logger))
|
||||
worker, err := worker.New(worker.WithDataDirPath(devDataDirPath), worker.WithLogger(logger))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/cirruslabs/orchard/internal/command/dev"
|
||||
"github.com/cirruslabs/orchard/internal/command/get"
|
||||
"github.com/cirruslabs/orchard/internal/command/list"
|
||||
"github.com/cirruslabs/orchard/internal/command/stop"
|
||||
"github.com/cirruslabs/orchard/internal/command/worker"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -24,6 +25,7 @@ func NewRootCmd() *cobra.Command {
|
||||
get.NewCommand(),
|
||||
list.NewCommand(),
|
||||
deletepkg.NewCommand(),
|
||||
stop.NewCommand(),
|
||||
)
|
||||
|
||||
addGroupedCommands(command, "Administrative Tasks:",
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package stop
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewCommand() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
Use: "stop",
|
||||
Short: "Stop resources",
|
||||
}
|
||||
|
||||
command.AddCommand(newStopVMCommand())
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package stop
|
||||
|
||||
import (
|
||||
"github.com/cirruslabs/orchard/pkg/client"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func newStopVMCommand() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "vm",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runStopVM,
|
||||
}
|
||||
}
|
||||
|
||||
func runStopVM(cmd *cobra.Command, args []string) error {
|
||||
name := args[0]
|
||||
|
||||
client, err := client.New()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = client.VMs().Stop(cmd.Context(), name)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user