mirror of
https://github.com/containers/podman.git
synced 2025-11-29 01:28:22 +08:00
This allows users to set the associated machine's system connection to the system default when running `podman machine init --now` or `podman machine start`. It also changes the default bbehavior of these commands in that the user will be prompted and asked if they would like to switch the system connection. It also introduces a command line switch called `--update-connection`. If the switch is unset, then the user will be prmpted. If the command value is explicitly set to `false`, the user will not be prompted and the system connection will not be altered. If the value is set to `true`, the system connection will be made the default and the user will not be prompted. Fixes: https://issues.redhat.com/browse/RUN-3632 Signed-off-by: Brent Baude <bbaude@redhat.com>
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
//go:build amd64 || arm64
|
|
|
|
package os
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/containers/podman/v6/pkg/machine"
|
|
"github.com/containers/podman/v6/pkg/machine/shim"
|
|
"github.com/containers/podman/v6/pkg/machine/vmconfigs"
|
|
)
|
|
|
|
// MachineOS manages machine OS's from outside the machine.
|
|
type MachineOS struct {
|
|
Args []string
|
|
VM *vmconfigs.MachineConfig
|
|
Provider vmconfigs.VMProvider
|
|
VMName string
|
|
Restart bool
|
|
}
|
|
|
|
// Apply applies the image by sshing into the machine and running apply from inside the VM.
|
|
func (m *MachineOS) Apply(image string, _ ApplyOptions) error {
|
|
var off bool
|
|
args := []string{"podman", "machine", "os", "apply", image}
|
|
|
|
if err := machine.LocalhostSSH(m.VM.SSH.RemoteUsername, m.VM.SSH.IdentityPath, m.VMName, m.VM.SSH.Port, args); err != nil {
|
|
return err
|
|
}
|
|
|
|
if m.Restart {
|
|
if err := shim.Stop(m.VM, m.Provider, off); err != nil {
|
|
return err
|
|
}
|
|
if err := shim.Start(m.VM, m.Provider, machine.StartOptions{NoInfo: true}, &off); err != nil {
|
|
return err
|
|
}
|
|
fmt.Printf("Machine %q restarted successfully\n", m.VMName)
|
|
}
|
|
return nil
|
|
}
|