mirror of
https://github.com/containers/podman.git
synced 2025-06-25 20:26:51 +08:00
move removeFilesAndConnections
to a common file
Moves `removeFilesAndConnections` to the common file `pkg/machine/connections.go` to be reused by multiple hypervisors. Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
This commit is contained in:
@ -360,22 +360,6 @@ func (m *MacMachine) collectFilesToDestroy(opts machine.RemoveOptions) []string
|
|||||||
return files
|
return files
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeFilesAndConnections removes any files and connections associated with
|
|
||||||
// the machine during `Remove`
|
|
||||||
func (m *MacMachine) removeFilesAndConnections(files []string) {
|
|
||||||
for _, f := range files {
|
|
||||||
if err := os.Remove(f); err != nil && !errors.Is(err, os.ErrNotExist) {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := machine.RemoveConnections(m.Name); err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
if err := machine.RemoveConnections(m.Name + "-root"); err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MacMachine) Remove(name string, opts machine.RemoveOptions) (string, func() error, error) {
|
func (m *MacMachine) Remove(name string, opts machine.RemoveOptions) (string, func() error, error) {
|
||||||
var (
|
var (
|
||||||
files []string
|
files []string
|
||||||
@ -404,7 +388,7 @@ func (m *MacMachine) Remove(name string, opts machine.RemoveOptions) (string, fu
|
|||||||
|
|
||||||
confirmationMessage += "\n"
|
confirmationMessage += "\n"
|
||||||
return confirmationMessage, func() error {
|
return confirmationMessage, func() error {
|
||||||
m.removeFilesAndConnections(files)
|
machine.RemoveFilesAndConnections(files, m.Name, m.Name+"-root")
|
||||||
// TODO We will need something like this for applehv too i think
|
// TODO We will need something like this for applehv too i think
|
||||||
/*
|
/*
|
||||||
// Remove the HVSOCK for networking
|
// Remove the HVSOCK for networking
|
||||||
|
@ -6,8 +6,10 @@ package machine
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/containers/common/pkg/config"
|
"github.com/containers/common/pkg/config"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const LocalhostIP = "127.0.0.1"
|
const LocalhostIP = "127.0.0.1"
|
||||||
@ -89,3 +91,15 @@ func RemoveConnections(names ...string) error {
|
|||||||
}
|
}
|
||||||
return cfg.Write()
|
return cfg.Write()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// removeFilesAndConnections removes any files and connections with the given names
|
||||||
|
func RemoveFilesAndConnections(files []string, names ...string) {
|
||||||
|
for _, f := range files {
|
||||||
|
if err := os.Remove(f); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||||
|
logrus.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := RemoveConnections(names...); err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -328,19 +328,6 @@ func (m *HyperVMachine) collectFilesToDestroy(opts machine.RemoveOptions, diskPa
|
|||||||
return files
|
return files
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeFilesAndConnections removes any files and connections associated with
|
|
||||||
// the machine during `Remove`
|
|
||||||
func (m *HyperVMachine) removeFilesAndConnections(files []string) {
|
|
||||||
for _, f := range files {
|
|
||||||
if err := os.Remove(f); err != nil && !errors.Is(err, os.ErrNotExist) {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := machine.RemoveConnections(m.Name, m.Name+"-root"); err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// removeNetworkAndReadySocketsFromRegistry removes the Network and Ready sockets
|
// removeNetworkAndReadySocketsFromRegistry removes the Network and Ready sockets
|
||||||
// from the Windows Registry
|
// from the Windows Registry
|
||||||
func (m *HyperVMachine) removeNetworkAndReadySocketsFromRegistry() {
|
func (m *HyperVMachine) removeNetworkAndReadySocketsFromRegistry() {
|
||||||
@ -385,7 +372,7 @@ func (m *HyperVMachine) Remove(_ string, opts machine.RemoveOptions) (string, fu
|
|||||||
|
|
||||||
confirmationMessage += "\n"
|
confirmationMessage += "\n"
|
||||||
return confirmationMessage, func() error {
|
return confirmationMessage, func() error {
|
||||||
m.removeFilesAndConnections(files)
|
machine.RemoveFilesAndConnections(files, m.Name, m.Name+"-root")
|
||||||
m.removeNetworkAndReadySocketsFromRegistry()
|
m.removeNetworkAndReadySocketsFromRegistry()
|
||||||
return vm.Remove(diskPath)
|
return vm.Remove(diskPath)
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -1127,19 +1127,6 @@ func (v *MachineVM) removeQMPMonitorSocketAndVMPidFile() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeFilesAndConnections removes any files and connections associated with
|
|
||||||
// the machine during `Remove`
|
|
||||||
func (v *MachineVM) removeFilesAndConnections(files []string) {
|
|
||||||
for _, f := range files {
|
|
||||||
if err := os.Remove(f); err != nil && !errors.Is(err, os.ErrNotExist) {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := machine.RemoveConnections(v.Name, v.Name+"-root"); err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove deletes all the files associated with a machine including ssh keys, the image itself
|
// Remove deletes all the files associated with a machine including ssh keys, the image itself
|
||||||
func (v *MachineVM) Remove(_ string, opts machine.RemoveOptions) (string, func() error, error) {
|
func (v *MachineVM) Remove(_ string, opts machine.RemoveOptions) (string, func() error, error) {
|
||||||
var (
|
var (
|
||||||
@ -1181,7 +1168,7 @@ func (v *MachineVM) Remove(_ string, opts machine.RemoveOptions) (string, func()
|
|||||||
|
|
||||||
confirmationMessage += "\n"
|
confirmationMessage += "\n"
|
||||||
return confirmationMessage, func() error {
|
return confirmationMessage, func() error {
|
||||||
v.removeFilesAndConnections(files)
|
machine.RemoveFilesAndConnections(files, v.Name, v.Name+"-root")
|
||||||
return nil
|
return nil
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user