github.com/containers/podman/v4@v4.9.4/pkg/machine/os/machine_os.go (about)

     1  //go:build amd64 || arm64
     2  // +build amd64 arm64
     3  
     4  package os
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/containers/podman/v4/pkg/machine"
    10  )
    11  
    12  // MachineOS manages machine OS's from outside the machine.
    13  type MachineOS struct {
    14  	Args    []string
    15  	VM      machine.VM
    16  	VMName  string
    17  	Restart bool
    18  }
    19  
    20  // Apply applies the image by sshing into the machine and running apply from inside the VM.
    21  func (m *MachineOS) Apply(image string, opts ApplyOptions) error {
    22  	sshOpts := machine.SSHOptions{
    23  		Args: []string{"podman", "machine", "os", "apply", image},
    24  	}
    25  
    26  	if err := m.VM.SSH(m.VMName, sshOpts); err != nil {
    27  		return err
    28  	}
    29  
    30  	if m.Restart {
    31  		if err := m.VM.Stop(m.VMName, machine.StopOptions{}); err != nil {
    32  			return err
    33  		}
    34  		if err := m.VM.Start(m.VMName, machine.StartOptions{NoInfo: true}); err != nil {
    35  			return err
    36  		}
    37  		fmt.Printf("Machine %q restarted successfully\n", m.VMName)
    38  	}
    39  	return nil
    40  }