github.com/containers/podman/v4@v4.9.4/pkg/machine/e2e/config_init_test.go (about)

     1  package e2e_test
     2  
     3  import (
     4  	"strconv"
     5  )
     6  
     7  type initMachine struct {
     8  	/*
     9  	      --cpus uint              Number of CPUs (default 1)
    10  	      --disk-size uint         Disk size in GiB (default 100)
    11  	      --ignition-path string   Path to ignition file
    12  	      --username string        Username of the remote user (default "core" for FCOS, "user" for Fedora)
    13  	      --image-path string      Path to bootable image (default "testing")
    14  	  -m, --memory uint            Memory in MiB (default 2048)
    15  	      --now                    Start machine now
    16  	      --rootful                Whether this machine should prefer rootful container execution
    17  	      --timezone string        Set timezone (default "local")
    18  	  -v, --volume stringArray     Volumes to mount, source:target
    19  	      --volume-driver string   Optional volume driver
    20  
    21  	*/
    22  	cpus               *uint
    23  	diskSize           *uint
    24  	ignitionPath       string
    25  	username           string
    26  	imagePath          string
    27  	memory             *uint
    28  	now                bool
    29  	timezone           string
    30  	rootful            bool
    31  	volumes            []string
    32  	userModeNetworking bool
    33  
    34  	cmd []string
    35  }
    36  
    37  func (i *initMachine) buildCmd(m *machineTestBuilder) []string {
    38  	cmd := []string{"machine", "init"}
    39  	if i.cpus != nil {
    40  		cmd = append(cmd, "--cpus", strconv.Itoa(int(*i.cpus)))
    41  	}
    42  	if i.diskSize != nil {
    43  		cmd = append(cmd, "--disk-size", strconv.Itoa(int(*i.diskSize)))
    44  	}
    45  	if l := len(i.ignitionPath); l > 0 {
    46  		cmd = append(cmd, "--ignition-path", i.ignitionPath)
    47  	}
    48  	if l := len(i.username); l > 0 {
    49  		cmd = append(cmd, "--username", i.username)
    50  	}
    51  	if l := len(i.imagePath); l > 0 {
    52  		cmd = append(cmd, "--image-path", i.imagePath)
    53  	}
    54  	if i.memory != nil {
    55  		cmd = append(cmd, "--memory", strconv.Itoa(int(*i.memory)))
    56  	}
    57  	if l := len(i.timezone); l > 0 {
    58  		cmd = append(cmd, "--timezone", i.timezone)
    59  	}
    60  	for _, v := range i.volumes {
    61  		cmd = append(cmd, "--volume", v)
    62  	}
    63  	if i.now {
    64  		cmd = append(cmd, "--now")
    65  	}
    66  	if i.rootful {
    67  		cmd = append(cmd, "--rootful")
    68  	}
    69  	if i.userModeNetworking {
    70  		cmd = append(cmd, "--user-mode-networking")
    71  	}
    72  	cmd = append(cmd, m.name)
    73  	i.cmd = cmd
    74  	return cmd
    75  }
    76  
    77  func (i *initMachine) withCPUs(num uint) *initMachine {
    78  	i.cpus = &num
    79  	return i
    80  }
    81  func (i *initMachine) withDiskSize(size uint) *initMachine {
    82  	i.diskSize = &size
    83  	return i
    84  }
    85  
    86  func (i *initMachine) withIgnitionPath(path string) *initMachine { //nolint:unused
    87  	i.ignitionPath = path
    88  	return i
    89  }
    90  
    91  func (i *initMachine) withUsername(username string) *initMachine {
    92  	i.username = username
    93  	return i
    94  }
    95  
    96  func (i *initMachine) withImagePath(path string) *initMachine {
    97  	i.imagePath = path
    98  	return i
    99  }
   100  
   101  func (i *initMachine) withMemory(num uint) *initMachine {
   102  	i.memory = &num
   103  	return i
   104  }
   105  
   106  func (i *initMachine) withNow() *initMachine {
   107  	i.now = true
   108  	return i
   109  }
   110  
   111  func (i *initMachine) withTimezone(tz string) *initMachine {
   112  	i.timezone = tz
   113  	return i
   114  }
   115  
   116  func (i *initMachine) withVolume(v string) *initMachine {
   117  	i.volumes = append(i.volumes, v)
   118  	return i
   119  }
   120  
   121  func (i *initMachine) withRootful(r bool) *initMachine {
   122  	i.rootful = r
   123  	return i
   124  }
   125  
   126  func (i *initMachine) withUserModeNetworking(r bool) *initMachine {
   127  	i.userModeNetworking = r
   128  	return i
   129  }