orchard create vm: introduce --disk-size command-line argument (#313)

This commit is contained in:
Nikolay Edigaryev 2025-04-29 16:21:46 +02:00 committed by GitHub
parent b25b154a31
commit 507db0fcfe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 0 deletions

View File

@ -16,6 +16,7 @@ var ErrVMFailed = errors.New("failed to create VM")
var image string
var cpu uint64
var memory uint64
var diskSize uint64
var netSoftnet bool
var netBridged string
var headless bool
@ -40,6 +41,8 @@ func newCreateVMCommand() *cobra.Command {
command.PersistentFlags().StringVar(&image, "image", "ghcr.io/cirruslabs/macos-sonoma-base:latest", "image to use")
command.PersistentFlags().Uint64Var(&cpu, "cpu", 4, "number of CPUs to use")
command.PersistentFlags().Uint64Var(&memory, "memory", 8*1024, "megabytes of memory to use")
command.PersistentFlags().Uint64Var(&diskSize, "disk-size", 0, "resize the VMs disk to the specified size in GB "+
"(no resizing is done by default and VM's image default size is used)")
command.PersistentFlags().BoolVar(&netSoftnet, "net-softnet", false, "whether to use Softnet network isolation")
command.PersistentFlags().StringVar(&netBridged, "net-bridged", "", "whether to use Bridged network mode")
command.PersistentFlags().BoolVar(&headless, "headless", true, "whether to run without graphics")
@ -97,6 +100,7 @@ func runCreateVM(cmd *cobra.Command, args []string) error {
Image: image,
CPU: cpu,
Memory: memory,
DiskSize: diskSize,
NetSoftnet: netSoftnet,
NetBridged: netBridged,
Headless: headless,

View File

@ -80,6 +80,16 @@ func runGetVM(cmd *cobra.Command, args []string) error {
}
table.AddRow("Memory", memory)
var diskSize string
if vm.DiskSize != 0 {
diskSize = fmt.Sprintf("%d GB", vm.DiskSize)
} else {
diskSize = "VM image's default"
}
table.AddRow("Disk size", diskSize)
table.AddRow("Softnet enabled", vm.NetSoftnet)
table.AddRow("Bridged networking interface", nonEmptyOrNone(vm.NetBridged))
table.AddRow("Headless mode", vm.Headless)

View File

@ -251,6 +251,14 @@ func (vm *VM) cloneAndConfigure(ctx context.Context) error {
}
}
if diskSize := vm.Resource.DiskSize; diskSize != 0 {
_, _, err = tart.Tart(ctx, vm.logger, "set", "--disk-size",
strconv.FormatUint(diskSize, 10), vm.id())
if err != nil {
return err
}
}
// Randomize VM's MAC-address, this is important when using shared (NAT) networking
// with full /var/db/dhcpd_leases file (e.g. 256 entries) having an expired entry
// for a MAC address used by some OCI image, for example:

View File

@ -23,6 +23,7 @@ type VM struct {
ImagePullPolicy ImagePullPolicy `json:"imagePullPolicy,omitempty"`
CPU uint64 `json:"cpu,omitempty"`
Memory uint64 `json:"memory,omitempty"`
DiskSize uint64 `json:"diskSize,omitempty"`
NetSoftnet bool `json:"net-softnet,omitempty"`
NetBridged string `json:"net-bridged,omitempty"`
Headless bool `json:"headless,omitempty"`