mirror of
https://github.com/containers/podman.git
synced 2025-06-25 12:20:42 +08:00
Merge pull request #18359 from Luap99/machine-connection
machine: qemu only remove connection after confirmation
This commit is contained in:
@ -9,7 +9,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/common/pkg/config"
|
|
||||||
"github.com/containers/podman/v4/cmd/podman/registry"
|
"github.com/containers/podman/v4/cmd/podman/registry"
|
||||||
"github.com/containers/podman/v4/libpod/events"
|
"github.com/containers/podman/v4/libpod/events"
|
||||||
"github.com/containers/podman/v4/pkg/machine"
|
"github.com/containers/podman/v4/pkg/machine"
|
||||||
@ -94,24 +93,5 @@ func rm(_ *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
newMachineEvent(events.Remove, events.Event{Name: vmName})
|
newMachineEvent(events.Remove, events.Event{Name: vmName})
|
||||||
err = updateDefaultMachineInConfig(vmName)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to update default machine: %v", err)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateDefaultMachineInConfig(vmName string) error {
|
|
||||||
cfg, err := config.ReadCustomConfig()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if cfg.Engine.ActiveService == vmName {
|
|
||||||
cfg.Engine.ActiveService = ""
|
|
||||||
for machine := range cfg.Engine.ServiceDestinations {
|
|
||||||
cfg.Engine.ActiveService = machine
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cfg.Write()
|
|
||||||
}
|
|
||||||
|
@ -65,15 +65,25 @@ func ChangeDefault(name string) error {
|
|||||||
return cfg.Write()
|
return cfg.Write()
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveConnection(name string) error {
|
func RemoveConnections(names ...string) error {
|
||||||
cfg, err := config.ReadCustomConfig()
|
cfg, err := config.ReadCustomConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, ok := cfg.Engine.ServiceDestinations[name]; ok {
|
for _, name := range names {
|
||||||
delete(cfg.Engine.ServiceDestinations, name)
|
if _, ok := cfg.Engine.ServiceDestinations[name]; ok {
|
||||||
} else {
|
delete(cfg.Engine.ServiceDestinations, name)
|
||||||
return fmt.Errorf("unable to find connection named %q", name)
|
} else {
|
||||||
|
return fmt.Errorf("unable to find connection named %q", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.Engine.ActiveService == name {
|
||||||
|
cfg.Engine.ActiveService = ""
|
||||||
|
for service := range cfg.Engine.ServiceDestinations {
|
||||||
|
cfg.Engine.ActiveService = service
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return cfg.Write()
|
return cfg.Write()
|
||||||
}
|
}
|
||||||
|
@ -358,10 +358,7 @@ func (m *HyperVMachine) Remove(_ string, opts machine.RemoveOptions) (string, fu
|
|||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := machine.RemoveConnection(m.Name); err != nil {
|
if err := machine.RemoveConnections(m.Name, m.Name+"-root"); err != nil {
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
if err := machine.RemoveConnection(m.Name + "-root"); err != nil {
|
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -969,13 +969,6 @@ func (v *MachineVM) Remove(_ string, opts machine.RemoveOptions) (string, func()
|
|||||||
files = append(files, socketPath.Path)
|
files = append(files, socketPath.Path)
|
||||||
files = append(files, v.archRemovalFiles()...)
|
files = append(files, v.archRemovalFiles()...)
|
||||||
|
|
||||||
if err := machine.RemoveConnection(v.Name); err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
if err := machine.RemoveConnection(v.Name + "-root"); err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
vmConfigDir, err := machine.GetConfDir(vmtype)
|
vmConfigDir, err := machine.GetConfDir(vmtype)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
@ -1006,6 +999,9 @@ func (v *MachineVM) Remove(_ string, opts machine.RemoveOptions) (string, func()
|
|||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := machine.RemoveConnections(v.Name, v.Name+"-root"); err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -1429,10 +1429,7 @@ func (v *MachineVM) Remove(name string, opts machine.RemoveOptions) (string, fun
|
|||||||
|
|
||||||
confirmationMessage += "\n"
|
confirmationMessage += "\n"
|
||||||
return confirmationMessage, func() error {
|
return confirmationMessage, func() error {
|
||||||
if err := machine.RemoveConnection(v.Name); err != nil {
|
if err := machine.RemoveConnections(v.Name, v.Name+"-root"); err != nil {
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
if err := machine.RemoveConnection(v.Name + "-root"); err != nil {
|
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
if err := runCmdPassThrough("wsl", "--unregister", toDist(v.Name)); err != nil {
|
if err := runCmdPassThrough("wsl", "--unregister", toDist(v.Name)); err != nil {
|
||||||
|
Reference in New Issue
Block a user