mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00

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>
46 lines
1.1 KiB
Go
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
|
|
}
|