mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-09-10 09:37:52 +00:00
Align codebase with v4.4.1-rhel PodmanConfig structure and API signatures to resolve compilation errors. - Update all cfg.Engine.* references to cfg.ContainersConf.Engine.* or cfg.ContainersConfDefaultsRO.Engine.* - Update all cfg.Network.* references to cfg.ContainersConf.Network.* - Update all cfg.Containers.* references to cfg.ContainersConf.Containers.* or cfg.ContainersConfDefaultsRO.Containers.* - Update cfg.Machine.* references to cfg.ContainersConfDefaultsRO.Machine.* - Fix PodmanConfig initialization in config.go to use ContainersConf and ContainersConfDefaultsRO fields - Add createOptions parameter to NetworkCreate method across all implementations (abi, tunnel, handlers) - Update ContainerEngine interface to match new NetworkCreate signature - Fix manager.Store call in secrets.go to use StoreOptions struct - Update DiskUsage to handle 3 return values - Fix NewConnectionWithIdentity call signature - Remove duplicate setupRemoteConnection function - Remove duplicate readRemoteCliFlags function - Remove duplicate function declarations in container_path_resolution.go, oci_conmon_linux.go - Comment out duplicate SpecGenToOCI and helper functions in oci.go/oci_linux.go - Remove unused imports across multiple files - Fix SSHMode flag handling (field doesn't exist in current PodmanConfig) - Fix ns.NetNS type handling in container_internal_linux.go - Add missing Terminal() method to Container struct - Add missing SdNotifySocket field to ContainerConfig - Fix DefaultCapabilities to use .Get() method - Fix cgroups.AvailableControllers reference - Fix ConmonPath type conversion (attributedstring.Slice) - Add missing ErrNetworkConnected error definition - Fix NetworkCreateOptions handling in secrets.go - Update networking code to use getNetNSPathCommon helper - Fix teardownNetwork method signature - Fix makeInspectPorts to makeInspectPortBindings - Remove hardcoded IsPasta() checks - Fix runtime_libpod.go field access patterns All changes align with the v4.4.1-rhel worktree structure to ensure compatibility with upcoming cherry-picks. Substantially Assisted-by AI: Cursor <auto> Signed-off-by: Chris Evich <cevich@redhat.com>
157 lines
5.1 KiB
Go
157 lines
5.1 KiB
Go
//go:build amd64 || arm64
|
|
// +build amd64 arm64
|
|
|
|
package machine
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/containers/common/pkg/completion"
|
|
"github.com/containers/podman/v4/cmd/podman/registry"
|
|
"github.com/containers/podman/v4/libpod/events"
|
|
"github.com/containers/podman/v4/pkg/machine"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
initCmd = &cobra.Command{
|
|
Use: "init [options] [NAME]",
|
|
Short: "Initialize a virtual machine",
|
|
Long: "initialize a virtual machine ",
|
|
PersistentPreRunE: rootlessOnly,
|
|
RunE: initMachine,
|
|
Args: cobra.MaximumNArgs(1),
|
|
Example: `podman machine init myvm`,
|
|
ValidArgsFunction: completion.AutocompleteNone,
|
|
}
|
|
|
|
initOpts = machine.InitOptions{}
|
|
defaultMachineName = machine.DefaultMachineName
|
|
now bool
|
|
)
|
|
|
|
// maxMachineNameSize is set to thirty to limit huge machine names primarily
|
|
// because macOS has a much smaller file size limit.
|
|
const maxMachineNameSize = 30
|
|
|
|
func init() {
|
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
|
Command: initCmd,
|
|
Parent: machineCmd,
|
|
})
|
|
flags := initCmd.Flags()
|
|
cfg := registry.PodmanConfig()
|
|
|
|
cpusFlagName := "cpus"
|
|
flags.Uint64Var(
|
|
&initOpts.CPUS,
|
|
cpusFlagName, cfg.ContainersConfDefaultsRO.Machine.CPUs,
|
|
"Number of CPUs",
|
|
)
|
|
_ = initCmd.RegisterFlagCompletionFunc(cpusFlagName, completion.AutocompleteNone)
|
|
|
|
diskSizeFlagName := "disk-size"
|
|
flags.Uint64Var(
|
|
&initOpts.DiskSize,
|
|
diskSizeFlagName, cfg.ContainersConfDefaultsRO.Machine.DiskSize,
|
|
"Disk size in GB",
|
|
)
|
|
|
|
_ = initCmd.RegisterFlagCompletionFunc(diskSizeFlagName, completion.AutocompleteNone)
|
|
|
|
memoryFlagName := "memory"
|
|
flags.Uint64VarP(
|
|
&initOpts.Memory,
|
|
memoryFlagName, "m", cfg.ContainersConfDefaultsRO.Machine.Memory,
|
|
"Memory in MB",
|
|
)
|
|
_ = initCmd.RegisterFlagCompletionFunc(memoryFlagName, completion.AutocompleteNone)
|
|
|
|
flags.BoolVar(
|
|
&now,
|
|
"now", false,
|
|
"Start machine now",
|
|
)
|
|
timezoneFlagName := "timezone"
|
|
defaultTz := cfg.ContainersConfDefaultsRO.TZ()
|
|
if len(defaultTz) < 1 {
|
|
defaultTz = "local"
|
|
}
|
|
flags.StringVar(&initOpts.TimeZone, timezoneFlagName, defaultTz, "Set timezone")
|
|
_ = initCmd.RegisterFlagCompletionFunc(timezoneFlagName, completion.AutocompleteDefault)
|
|
|
|
flags.BoolVar(
|
|
&initOpts.ReExec,
|
|
"reexec", false,
|
|
"process was rexeced",
|
|
)
|
|
_ = flags.MarkHidden("reexec")
|
|
|
|
ImagePathFlagName := "image-path"
|
|
flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, cfg.ContainersConfDefaultsRO.Machine.Image, "Path to qcow image")
|
|
_ = initCmd.RegisterFlagCompletionFunc(ImagePathFlagName, completion.AutocompleteDefault)
|
|
|
|
VolumeFlagName := "volume"
|
|
flags.StringArrayVarP(&initOpts.Volumes, VolumeFlagName, "v", cfg.ContainersConfDefaultsRO.Machine.Volumes.Get(), "Volumes to mount, source:target")
|
|
_ = initCmd.RegisterFlagCompletionFunc(VolumeFlagName, completion.AutocompleteDefault)
|
|
|
|
VolumeDriverFlagName := "volume-driver"
|
|
flags.StringVar(&initOpts.VolumeDriver, VolumeDriverFlagName, "", "Optional volume driver")
|
|
_ = initCmd.RegisterFlagCompletionFunc(VolumeDriverFlagName, completion.AutocompleteDefault)
|
|
|
|
IgnitionPathFlagName := "ignition-path"
|
|
flags.StringVar(&initOpts.IgnitionPath, IgnitionPathFlagName, "", "Path to ignition file")
|
|
_ = initCmd.RegisterFlagCompletionFunc(IgnitionPathFlagName, completion.AutocompleteDefault)
|
|
|
|
rootfulFlagName := "rootful"
|
|
flags.BoolVar(&initOpts.Rootful, rootfulFlagName, false, "Whether this machine should prefer rootful container execution")
|
|
}
|
|
|
|
func initMachine(cmd *cobra.Command, args []string) error {
|
|
var (
|
|
err error
|
|
vm machine.VM
|
|
)
|
|
|
|
provider := GetSystemDefaultProvider()
|
|
initOpts.Name = defaultMachineName
|
|
if len(args) > 0 {
|
|
if len(args[0]) > maxMachineNameSize {
|
|
return fmt.Errorf("machine name %q must be %d characters or less", args[0], maxMachineNameSize)
|
|
}
|
|
initOpts.Name = args[0]
|
|
}
|
|
if _, err := provider.LoadVMByName(initOpts.Name); err == nil {
|
|
return fmt.Errorf("%s: %w", initOpts.Name, machine.ErrVMAlreadyExists)
|
|
}
|
|
for idx, vol := range initOpts.Volumes {
|
|
initOpts.Volumes[idx] = os.ExpandEnv(vol)
|
|
}
|
|
vm, err = provider.NewMachine(initOpts)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if finished, err := vm.Init(initOpts); err != nil || !finished {
|
|
// Finished = true, err = nil - Success! Log a message with further instructions
|
|
// Finished = false, err = nil - The installation is partially complete and podman should
|
|
// exit gracefully with no error and no success message.
|
|
// Examples:
|
|
// - a user has chosen to perform their own reboot
|
|
// - reexec for limited admin operations, returning to parent
|
|
// Finished = *, err != nil - Exit with an error message
|
|
return err
|
|
}
|
|
newMachineEvent(events.Init, events.Event{Name: initOpts.Name})
|
|
fmt.Println("Machine init complete")
|
|
|
|
if now {
|
|
return start(cmd, args)
|
|
}
|
|
extra := ""
|
|
if initOpts.Name != defaultMachineName {
|
|
extra = " " + initOpts.Name
|
|
}
|
|
fmt.Printf("To start your machine run:\n\n\tpodman machine start%s\n\n", extra)
|
|
return err
|
|
}
|