summaryrefslogtreecommitdiff
path: root/cmd/podman/machine
diff options
context:
space:
mode:
authorAshley Cui <acui@redhat.com>2022-04-21 09:09:49 -0400
committerAshley Cui <acui@redhat.com>2022-04-27 13:56:14 -0400
commite7390f30b95daf90c0f32e8cf963dce3f8d5cf9d (patch)
treec0b962e598a1643f6f91cfd365c04cf0dc2a2d86 /cmd/podman/machine
parent5ac00a7287e4a9e6292f4a6ca5dfa9a02e5ca907 (diff)
downloadpodman-e7390f30b95daf90c0f32e8cf963dce3f8d5cf9d.tar.gz
podman-e7390f30b95daf90c0f32e8cf963dce3f8d5cf9d.tar.bz2
podman-e7390f30b95daf90c0f32e8cf963dce3f8d5cf9d.zip
Allow changing of CPUs, Memory, and Disk Size
Allow podman machine set to change CPUs, Memory and Disk size of a QEMU machine after its been created. Disk size can only be increased. If one setting fails to be changed, the other settings will still be applied. Signed-off-by: Ashley Cui <acui@redhat.com>
Diffstat (limited to 'cmd/podman/machine')
-rw-r--r--cmd/podman/machine/set.go60
1 files changed, 57 insertions, 3 deletions
diff --git a/cmd/podman/machine/set.go b/cmd/podman/machine/set.go
index 4c15f1de1..a994c981b 100644
--- a/cmd/podman/machine/set.go
+++ b/cmd/podman/machine/set.go
@@ -4,6 +4,9 @@
package machine
import (
+ "fmt"
+ "os"
+
"github.com/containers/common/pkg/completion"
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/pkg/machine"
@@ -23,9 +26,17 @@ var (
)
var (
- setOpts = machine.SetOptions{}
+ setFlags = SetFlags{}
+ setOpts = machine.SetOptions{}
)
+type SetFlags struct {
+ CPUs uint64
+ DiskSize uint64
+ Memory uint64
+ Rootful bool
+}
+
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Command: setCmd,
@@ -34,7 +45,32 @@ func init() {
flags := setCmd.Flags()
rootfulFlagName := "rootful"
- flags.BoolVar(&setOpts.Rootful, rootfulFlagName, false, "Whether this machine should prefer rootful container execution")
+ flags.BoolVar(&setFlags.Rootful, rootfulFlagName, false, "Whether this machine should prefer rootful container execution")
+
+ cpusFlagName := "cpus"
+ flags.Uint64Var(
+ &setFlags.CPUs,
+ cpusFlagName, 0,
+ "Number of CPUs",
+ )
+ _ = setCmd.RegisterFlagCompletionFunc(cpusFlagName, completion.AutocompleteNone)
+
+ diskSizeFlagName := "disk-size"
+ flags.Uint64Var(
+ &setFlags.DiskSize,
+ diskSizeFlagName, 0,
+ "Disk size in GB",
+ )
+
+ _ = setCmd.RegisterFlagCompletionFunc(diskSizeFlagName, completion.AutocompleteNone)
+
+ memoryFlagName := "memory"
+ flags.Uint64VarP(
+ &setFlags.Memory,
+ memoryFlagName, "m", 0,
+ "Memory in MB",
+ )
+ _ = setCmd.RegisterFlagCompletionFunc(memoryFlagName, completion.AutocompleteNone)
}
func setMachine(cmd *cobra.Command, args []string) error {
@@ -53,5 +89,23 @@ func setMachine(cmd *cobra.Command, args []string) error {
return err
}
- return vm.Set(vmName, setOpts)
+ if cmd.Flags().Changed("rootful") {
+ setOpts.Rootful = &setFlags.Rootful
+ }
+ if cmd.Flags().Changed("cpus") {
+ setOpts.CPUs = &setFlags.CPUs
+ }
+ if cmd.Flags().Changed("memory") {
+ setOpts.Memory = &setFlags.Memory
+ }
+ if cmd.Flags().Changed("disk-size") {
+ setOpts.DiskSize = &setFlags.DiskSize
+ }
+
+ setErrs, lasterr := vm.Set(vmName, setOpts)
+ for _, err := range setErrs {
+ fmt.Fprintf(os.Stderr, "%v\n", err)
+ }
+
+ return lasterr
}