diff options
author | Ashley Cui <acui@redhat.com> | 2022-04-27 16:56:48 -0400 |
---|---|---|
committer | Ashley Cui <acui@redhat.com> | 2022-05-04 10:31:42 -0400 |
commit | 80744c644135899a6dcc9fbe1b421dc08fc79802 (patch) | |
tree | a924d1cc59c0d99ca83f2d07800ae8655561977a /pkg/machine/wsl | |
parent | 698cb730a1a7d36bc36e447969928ccb0a6317df (diff) | |
download | podman-80744c644135899a6dcc9fbe1b421dc08fc79802.tar.gz podman-80744c644135899a6dcc9fbe1b421dc08fc79802.tar.bz2 podman-80744c644135899a6dcc9fbe1b421dc08fc79802.zip |
podman system reset removed machines incorrectly
podman system reset did not clean up machines fully, leaving some config
files, and breaking machines. Now it removes all machines files fully.
Signed-off-by: Ashley Cui <acui@redhat.com>
Diffstat (limited to 'pkg/machine/wsl')
-rw-r--r-- | pkg/machine/wsl/machine.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/pkg/machine/wsl/machine.go b/pkg/machine/wsl/machine.go index bc2ac7864..57fb36fc9 100644 --- a/pkg/machine/wsl/machine.go +++ b/pkg/machine/wsl/machine.go @@ -1442,3 +1442,79 @@ func (v *MachineVM) getResources() (resources machine.ResourceConfig) { resources.DiskSize = getDiskSize(v) return } + +// RemoveAndCleanMachines removes all machine and cleans up any other files associatied with podman machine +func (p *Provider) RemoveAndCleanMachines() error { + var ( + vm machine.VM + listResponse []*machine.ListResponse + opts machine.ListOptions + destroyOptions machine.RemoveOptions + ) + destroyOptions.Force = true + var prevErr error + + listResponse, err := p.List(opts) + if err != nil { + return err + } + + for _, mach := range listResponse { + vm, err = p.LoadVMByName(mach.Name) + if err != nil { + if prevErr != nil { + logrus.Error(prevErr) + } + prevErr = err + } + _, remove, err := vm.Remove(mach.Name, destroyOptions) + if err != nil { + if prevErr != nil { + logrus.Error(prevErr) + } + prevErr = err + } else { + if err := remove(); err != nil { + if prevErr != nil { + logrus.Error(prevErr) + } + prevErr = err + } + } + } + + // Clean leftover files in data dir + dataDir, err := machine.DataDirPrefix() + if err != nil { + if prevErr != nil { + logrus.Error(prevErr) + } + prevErr = err + } else { + err := os.RemoveAll(dataDir) + if err != nil { + if prevErr != nil { + logrus.Error(prevErr) + } + prevErr = err + } + } + + // Clean leftover files in conf dir + confDir, err := machine.ConfDirPrefix() + if err != nil { + if prevErr != nil { + logrus.Error(prevErr) + } + prevErr = err + } else { + err := os.RemoveAll(confDir) + if err != nil { + if prevErr != nil { + logrus.Error(prevErr) + } + prevErr = err + } + } + return prevErr +} |