aboutsummaryrefslogtreecommitdiff
path: root/pkg/machine/e2e/config_init.go
blob: 7f18cce7d72dd33464e73749aee5da2653b130e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package e2e

import (
	"strconv"
)

type initMachine struct {
	/*
	      --cpus uint              Number of CPUs (default 1)
	      --disk-size uint         Disk size in GB (default 100)
	      --ignition-path string   Path to ignition file
	      --image-path string      Path to qcow image (default "testing")
	  -m, --memory uint            Memory in MB (default 2048)
	      --now                    Start machine now
	      --rootful                Whether this machine should prefer rootful container execution
	      --timezone string        Set timezone (default "local")
	  -v, --volume stringArray     Volumes to mount, source:target
	      --volume-driver string   Optional volume driver

	*/
	cpus         *uint
	diskSize     *uint
	ignitionPath string
	imagePath    string
	memory       *uint
	now          bool
	timezone     string
	rootful      bool
	volumes      []string

	cmd []string
}

func (i *initMachine) buildCmd(m *machineTestBuilder) []string {
	cmd := []string{"machine", "init"}
	if i.cpus != nil {
		cmd = append(cmd, "--cpus", strconv.Itoa(int(*i.cpus)))
	}
	if i.diskSize != nil {
		cmd = append(cmd, "--disk-size", strconv.Itoa(int(*i.diskSize)))
	}
	if l := len(i.ignitionPath); l > 0 {
		cmd = append(cmd, "--ignition-path", i.ignitionPath)
	}
	if l := len(i.imagePath); l > 0 {
		cmd = append(cmd, "--image-path", i.imagePath)
	}
	if i.memory != nil {
		cmd = append(cmd, "--memory", strconv.Itoa(int(*i.memory)))
	}
	if l := len(i.timezone); l > 0 {
		cmd = append(cmd, "--timezone", i.timezone)
	}
	for _, v := range i.volumes {
		cmd = append(cmd, "--volume", v)
	}
	if i.now {
		cmd = append(cmd, "--now")
	}
	cmd = append(cmd, m.name)
	i.cmd = cmd
	return cmd
}

func (i *initMachine) withCPUs(num uint) *initMachine {
	i.cpus = &num
	return i
}
func (i *initMachine) withDiskSize(size uint) *initMachine {
	i.diskSize = &size
	return i
}

func (i *initMachine) withIgnitionPath(path string) *initMachine {
	i.ignitionPath = path
	return i
}

func (i *initMachine) withImagePath(path string) *initMachine {
	i.imagePath = path
	return i
}

func (i *initMachine) withMemory(num uint) *initMachine {
	i.memory = &num
	return i
}

func (i *initMachine) withNow() *initMachine {
	i.now = true
	return i
}

func (i *initMachine) withTimezone(tz string) *initMachine {
	i.timezone = tz
	return i
}

func (i *initMachine) withVolume(v string) *initMachine {
	i.volumes = append(i.volumes, v)
	return i
}