diff options
author | baude <bbaude@redhat.com> | 2021-03-25 10:35:43 -0500 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2021-03-27 10:08:11 -0500 |
commit | 7a79f708a4521ba7c42da83a204a01ace010ace3 (patch) | |
tree | 42e4128908fa127d158ad0673b033740d416d1f4 /cmd/podman/machine/init.go | |
parent | ec47312eebf11abcf74b5bf06df19ee2fb7b8afd (diff) | |
download | podman-7a79f708a4521ba7c42da83a204a01ace010ace3.tar.gz podman-7a79f708a4521ba7c42da83a204a01ace010ace3.tar.bz2 podman-7a79f708a4521ba7c42da83a204a01ace010ace3.zip |
Podman machine enhancements
Podman machine remove is now called `rm`.
Podman machine create now supports resizing the image to the value of
--disk-size as provided. The default is to 10G.
Added systemd unit file on guest via ignition that sends a Ready message
to the host over a virtio-socket so that we know when the VM is booted
and ready for use.
Podman machine commands no longer require a VM name as an argument. A
default VM name is defined and if no VM name is provided as a arg, the
default will be used.
[NO TESTS NEEDED]
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/machine/init.go')
-rw-r--r-- | cmd/podman/machine/init.go | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/cmd/podman/machine/init.go b/cmd/podman/machine/init.go index 900f67e2f..05474fd89 100644 --- a/cmd/podman/machine/init.go +++ b/cmd/podman/machine/init.go @@ -8,6 +8,7 @@ import ( "github.com/containers/podman/v3/pkg/domain/entities" "github.com/containers/podman/v3/pkg/machine" "github.com/containers/podman/v3/pkg/machine/qemu" + "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -23,17 +24,8 @@ var ( } ) -type InitCLIOptions struct { - CPUS uint64 - Memory uint64 - Devices []string - ImagePath string - IgnitionPath string - Name string -} - var ( - initOpts = InitCLIOptions{} + initOpts = machine.InitOptions{} defaultMachineName string = "podman-machine-default" ) @@ -53,6 +45,15 @@ func init() { ) _ = initCmd.RegisterFlagCompletionFunc(cpusFlagName, completion.AutocompleteNone) + diskSizeFlagName := "disk-size" + flags.Uint64Var( + &initOpts.DiskSize, + diskSizeFlagName, 10, + "Disk size in GB", + ) + + _ = initCmd.RegisterFlagCompletionFunc(diskSizeFlagName, completion.AutocompleteNone) + memoryFlagName := "memory" flags.Uint64VarP( &initOpts.Memory, @@ -72,28 +73,24 @@ func init() { // TODO should we allow for a users to append to the qemu cmdline? func initMachine(cmd *cobra.Command, args []string) error { - initOpts.Name = defaultMachineName - if len(args) > 0 { - initOpts.Name = args[0] - } - vmOpts := machine.InitOptions{ - CPUS: initOpts.CPUS, - Memory: initOpts.Memory, - IgnitionPath: initOpts.IgnitionPath, - ImagePath: initOpts.ImagePath, - Name: initOpts.Name, - } var ( vm machine.VM vmType string err error ) + initOpts.Name = defaultMachineName + if len(args) > 0 { + initOpts.Name = args[0] + } switch vmType { default: // qemu is the default - vm, err = qemu.NewMachine(vmOpts) + if _, err := qemu.LoadVMByName(initOpts.Name); err == nil { + return errors.Wrap(machine.ErrVMAlreadyExists, initOpts.Name) + } + vm, err = qemu.NewMachine(initOpts) } if err != nil { return err } - return vm.Init(vmOpts) + return vm.Init(initOpts) } |