podman

Форк
0
/
machine_os.go 
46 строк · 1.2 Кб
1
//go:build amd64 || arm64
2

3
package os
4

5
import (
6
	"fmt"
7

8
	"github.com/containers/podman/v5/pkg/machine"
9
	"github.com/containers/podman/v5/pkg/machine/env"
10
	"github.com/containers/podman/v5/pkg/machine/shim"
11
	"github.com/containers/podman/v5/pkg/machine/vmconfigs"
12
)
13

14
// MachineOS manages machine OS's from outside the machine.
15
type MachineOS struct {
16
	Args     []string
17
	VM       *vmconfigs.MachineConfig
18
	Provider vmconfigs.VMProvider
19
	VMName   string
20
	Restart  bool
21
}
22

23
// Apply applies the image by sshing into the machine and running apply from inside the VM.
24
func (m *MachineOS) Apply(image string, opts ApplyOptions) error {
25
	args := []string{"podman", "machine", "os", "apply", image}
26

27
	if err := machine.CommonSSH(m.VM.SSH.RemoteUsername, m.VM.SSH.IdentityPath, m.VMName, m.VM.SSH.Port, args); err != nil {
28
		return err
29
	}
30

31
	dirs, err := env.GetMachineDirs(m.Provider.VMType())
32
	if err != nil {
33
		return err
34
	}
35

36
	if m.Restart {
37
		if err := shim.Stop(m.VM, m.Provider, dirs, false); err != nil {
38
			return err
39
		}
40
		if err := shim.Start(m.VM, m.Provider, dirs, machine.StartOptions{NoInfo: true}); err != nil {
41
			return err
42
		}
43
		fmt.Printf("Machine %q restarted successfully\n", m.VMName)
44
	}
45
	return nil
46
}
47

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.