Files
podman/pkg/machine/provider/platform.go
Jake Correnti 54b71b637c Add GetAllMachinesAndRootfulness
Adds the function `GetAllMachinesAndRootfulness` which creates a map of
all podman machines, of any supported provider, on the system and
whether it is rootful or not.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
2024-09-12 14:31:55 -04:00

46 lines
1.1 KiB
Go

package provider
import (
"github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
)
func InstalledProviders() ([]define.VMType, error) {
installedTypes := []define.VMType{}
providers := GetAll()
for _, p := range providers {
installed, err := IsInstalled(p.VMType())
if err != nil {
return nil, err
}
if installed {
installedTypes = append(installedTypes, p.VMType())
}
}
return installedTypes, nil
}
// GetAllMachinesAndRootfulness collects all podman machine configs and returns
// a map in the format: { machineName: isRootful }
func GetAllMachinesAndRootfulness() (map[string]bool, error) {
providers := GetAll()
machines := map[string]bool{}
for _, provider := range providers {
dirs, err := env.GetMachineDirs(provider.VMType())
if err != nil {
return nil, err
}
providerMachines, err := vmconfigs.LoadMachinesInDir(dirs)
if err != nil {
return nil, err
}
for n, m := range providerMachines {
machines[n] = m.HostUser.Rootful
}
}
return machines, nil
}