mirror of
https://github.com/containers/podman.git
synced 2025-10-30 01:17:00 +08:00
Podman machine resets all providers
Podman machine reset now removes and resets machines from all providers availabe on the platform. On windows, if the user is does not have admin privs, machine will only reset WSL, but will emit a warning that it is unable to remove hyperV machines without elevated privs. Signed-off-by: Ashley Cui <acui@redhat.com>
This commit is contained in:
@ -38,6 +38,10 @@ func Get() (vmconfigs.VMProvider, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func GetAll(_ bool) ([]vmconfigs.VMProvider, error) {
|
||||
return []vmconfigs.VMProvider{new(qemu.QEMUStubber)}, nil
|
||||
}
|
||||
|
||||
// SupportedProviders returns the providers that are supported on the host operating system
|
||||
func SupportedProviders() []define.VMType {
|
||||
return []define.VMType{define.QemuVirt}
|
||||
|
||||
@ -42,6 +42,13 @@ func Get() (vmconfigs.VMProvider, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func GetAll(_ bool) ([]vmconfigs.VMProvider, error) {
|
||||
return []vmconfigs.VMProvider{
|
||||
new(applehv.AppleHVStubber),
|
||||
new(libkrun.LibKrunStubber),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// SupportedProviders returns the providers that are supported on the host operating system
|
||||
func SupportedProviders() []define.VMType {
|
||||
supported := []define.VMType{define.AppleHvVirt}
|
||||
|
||||
@ -43,6 +43,18 @@ func Get() (vmconfigs.VMProvider, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func GetAll(force bool) ([]vmconfigs.VMProvider, error) {
|
||||
providers := []vmconfigs.VMProvider{
|
||||
new(wsl.WSLStubber),
|
||||
}
|
||||
if !wsl.HasAdminRights() && !force {
|
||||
logrus.Warn("managing hyperv machines require admin authority.")
|
||||
} else {
|
||||
providers = append(providers, new(hyperv.HyperVStubber))
|
||||
}
|
||||
return providers, nil
|
||||
}
|
||||
|
||||
// SupportedProviders returns the providers that are supported on the host operating system
|
||||
func SupportedProviders() []define.VMType {
|
||||
return []define.VMType{define.HyperVVirt, define.WSLVirt}
|
||||
|
||||
@ -636,38 +636,61 @@ func confirmationMessage(files []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func Reset(dirs *machineDefine.MachineDirs, mp vmconfigs.VMProvider, mcs map[string]*vmconfigs.MachineConfig) error {
|
||||
func Reset(mps []vmconfigs.VMProvider, opts machine.ResetOptions) error {
|
||||
var resetErrors *multierror.Error
|
||||
for _, mc := range mcs {
|
||||
err := Stop(mc, mp, dirs, true)
|
||||
if err != nil {
|
||||
resetErrors = multierror.Append(resetErrors, err)
|
||||
}
|
||||
_, genericRm, err := mc.Remove(false, false)
|
||||
if err != nil {
|
||||
resetErrors = multierror.Append(resetErrors, err)
|
||||
}
|
||||
_, providerRm, err := mp.Remove(mc)
|
||||
if err != nil {
|
||||
resetErrors = multierror.Append(resetErrors, err)
|
||||
}
|
||||
removeDirs := []*machineDefine.MachineDirs{}
|
||||
|
||||
if err := genericRm(); err != nil {
|
||||
for _, p := range mps {
|
||||
d, err := env.GetMachineDirs(p.VMType())
|
||||
if err != nil {
|
||||
resetErrors = multierror.Append(resetErrors, err)
|
||||
continue
|
||||
}
|
||||
if err := providerRm(); err != nil {
|
||||
mcs, err := vmconfigs.LoadMachinesInDir(d)
|
||||
if err != nil {
|
||||
resetErrors = multierror.Append(resetErrors, err)
|
||||
continue
|
||||
}
|
||||
removeDirs = append(removeDirs, d)
|
||||
|
||||
for _, mc := range mcs {
|
||||
err := Stop(mc, p, d, true)
|
||||
if err != nil {
|
||||
resetErrors = multierror.Append(resetErrors, err)
|
||||
}
|
||||
_, genericRm, err := mc.Remove(false, false)
|
||||
if err != nil {
|
||||
resetErrors = multierror.Append(resetErrors, err)
|
||||
}
|
||||
_, providerRm, err := p.Remove(mc)
|
||||
if err != nil {
|
||||
resetErrors = multierror.Append(resetErrors, err)
|
||||
}
|
||||
|
||||
if err := genericRm(); err != nil {
|
||||
resetErrors = multierror.Append(resetErrors, err)
|
||||
}
|
||||
if err := providerRm(); err != nil {
|
||||
resetErrors = multierror.Append(resetErrors, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the various directories
|
||||
// We do this after all the provider rm's, since providers may still share the base machine dir.
|
||||
// Note: we cannot delete the machine run dir blindly like this because
|
||||
// other things live there like the podman.socket and so forth.
|
||||
|
||||
// in linux this ~/.local/share/containers/podman/machine
|
||||
dataDirErr := utils.GuardedRemoveAll(filepath.Dir(dirs.DataDir.GetPath()))
|
||||
// in linux this ~/.config/containers/podman/machine
|
||||
confDirErr := utils.GuardedRemoveAll(filepath.Dir(dirs.ConfigDir.GetPath()))
|
||||
resetErrors = multierror.Append(resetErrors, confDirErr, dataDirErr)
|
||||
for _, dir := range removeDirs {
|
||||
// in linux this ~/.local/share/containers/podman/machine
|
||||
dataDirErr := utils.GuardedRemoveAll(filepath.Dir(dir.DataDir.GetPath()))
|
||||
if !errors.Is(dataDirErr, os.ErrNotExist) {
|
||||
resetErrors = multierror.Append(resetErrors, dataDirErr)
|
||||
}
|
||||
// in linux this ~/.config/containers/podman/machine
|
||||
confDirErr := utils.GuardedRemoveAll(filepath.Dir(dir.ConfigDir.GetPath()))
|
||||
if !errors.Is(confDirErr, os.ErrNotExist) {
|
||||
resetErrors = multierror.Append(resetErrors, confDirErr)
|
||||
}
|
||||
}
|
||||
return resetErrors.ErrorOrNil()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user