Refactor env dir and port functions into new leaf pkgs

[NO NEW TESTS NEEDED]

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
This commit is contained in:
Jason T. Greene 2024-03-04 16:24:53 -06:00
parent e58b168e11
commit ef7727238a
31 changed files with 219 additions and 193 deletions

View File

@ -7,8 +7,8 @@ import (
"net/url" "net/url"
"strconv" "strconv"
"github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/define" "github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/provider" "github.com/containers/podman/v5/pkg/machine/provider"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
) )
@ -18,7 +18,7 @@ func getMachineConn(connectionURI string, parsedConnection *url.URL) (string, er
if err != nil { if err != nil {
return "", fmt.Errorf("getting machine provider: %w", err) return "", fmt.Errorf("getting machine provider: %w", err)
} }
dirs, err := machine.GetMachineDirs(machineProvider.VMType()) dirs, err := env.GetMachineDirs(machineProvider.VMType())
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -14,8 +14,8 @@ import (
"github.com/containers/podman/v5/cmd/podman/validate" "github.com/containers/podman/v5/cmd/podman/validate"
"github.com/containers/podman/v5/libpod/define" "github.com/containers/podman/v5/libpod/define"
"github.com/containers/podman/v5/pkg/domain/entities" "github.com/containers/podman/v5/pkg/domain/entities"
"github.com/containers/podman/v5/pkg/machine"
machineDefine "github.com/containers/podman/v5/pkg/machine/define" machineDefine "github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
@ -100,7 +100,7 @@ func hostInfo() (*entities.MachineHostInfo, error) {
host.Arch = runtime.GOARCH host.Arch = runtime.GOARCH
host.OS = runtime.GOOS host.OS = runtime.GOOS
dirs, err := machine.GetMachineDirs(provider.VMType()) dirs, err := env.GetMachineDirs(provider.VMType())
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -10,6 +10,7 @@ import (
"github.com/containers/podman/v5/cmd/podman/registry" "github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/cmd/podman/utils" "github.com/containers/podman/v5/cmd/podman/utils"
"github.com/containers/podman/v5/pkg/machine" "github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -47,7 +48,7 @@ func inspect(cmd *cobra.Command, args []string) error {
var ( var (
errs utils.OutputErrors errs utils.OutputErrors
) )
dirs, err := machine.GetMachineDirs(provider.VMType()) dirs, err := env.GetMachineDirs(provider.VMType())
if err != nil { if err != nil {
return err return err
} }

View File

@ -15,7 +15,7 @@ import (
"github.com/containers/podman/v5/cmd/podman/registry" "github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/cmd/podman/validate" "github.com/containers/podman/v5/cmd/podman/validate"
"github.com/containers/podman/v5/libpod/events" "github.com/containers/podman/v5/libpod/events"
"github.com/containers/podman/v5/pkg/machine" "github.com/containers/podman/v5/pkg/machine/env"
provider2 "github.com/containers/podman/v5/pkg/machine/provider" provider2 "github.com/containers/podman/v5/pkg/machine/provider"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
"github.com/containers/podman/v5/pkg/util" "github.com/containers/podman/v5/pkg/util"
@ -82,7 +82,7 @@ func getMachines(toComplete string) ([]string, cobra.ShellCompDirective) {
if err != nil { if err != nil {
return nil, cobra.ShellCompDirectiveNoFileComp return nil, cobra.ShellCompDirectiveNoFileComp
} }
dirs, err := machine.GetMachineDirs(provider.VMType()) dirs, err := env.GetMachineDirs(provider.VMType())
if err != nil { if err != nil {
return nil, cobra.ShellCompDirectiveNoFileComp return nil, cobra.ShellCompDirectiveNoFileComp
} }

View File

@ -10,6 +10,7 @@ import (
machineconfig "github.com/containers/common/pkg/machine" machineconfig "github.com/containers/common/pkg/machine"
pkgMachine "github.com/containers/podman/v5/pkg/machine" pkgMachine "github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/env"
pkgOS "github.com/containers/podman/v5/pkg/machine/os" pkgOS "github.com/containers/podman/v5/pkg/machine/os"
"github.com/containers/podman/v5/pkg/machine/provider" "github.com/containers/podman/v5/pkg/machine/provider"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
@ -52,7 +53,7 @@ func machineOSManager(opts ManagerOpts, _ vmconfigs.VMProvider) (pkgOS.Manager,
if err != nil { if err != nil {
return nil, err return nil, err
} }
dirs, err := pkgMachine.GetMachineDirs(p.VMType()) dirs, err := env.GetMachineDirs(p.VMType())
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -12,6 +12,7 @@ import (
"github.com/containers/podman/v5/cmd/podman/registry" "github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/cmd/podman/validate" "github.com/containers/podman/v5/cmd/podman/validate"
"github.com/containers/podman/v5/pkg/machine" "github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/shim" "github.com/containers/podman/v5/pkg/machine/shim"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -50,7 +51,7 @@ func reset(_ *cobra.Command, _ []string) error {
err error err error
) )
dirs, err := machine.GetMachineDirs(provider.VMType()) dirs, err := env.GetMachineDirs(provider.VMType())
if err != nil { if err != nil {
return err return err
} }

View File

@ -6,6 +6,7 @@ import (
"github.com/containers/podman/v5/cmd/podman/registry" "github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/libpod/events" "github.com/containers/podman/v5/libpod/events"
"github.com/containers/podman/v5/pkg/machine" "github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/shim" "github.com/containers/podman/v5/pkg/machine/shim"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -54,7 +55,7 @@ func rm(_ *cobra.Command, args []string) error {
vmName = args[0] vmName = args[0]
} }
dirs, err := machine.GetMachineDirs(provider.VMType()) dirs, err := env.GetMachineDirs(provider.VMType())
if err != nil { if err != nil {
return err return err
} }

View File

@ -8,8 +8,8 @@ import (
"github.com/containers/common/pkg/completion" "github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/strongunits" "github.com/containers/common/pkg/strongunits"
"github.com/containers/podman/v5/cmd/podman/registry" "github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/define" "github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/shim" "github.com/containers/podman/v5/pkg/machine/shim"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -99,7 +99,7 @@ func setMachine(cmd *cobra.Command, args []string) error {
vmName = args[0] vmName = args[0]
} }
dirs, err := machine.GetMachineDirs(provider.VMType()) dirs, err := env.GetMachineDirs(provider.VMType())
if err != nil { if err != nil {
return err return err
} }

View File

@ -7,6 +7,7 @@ import (
"net/url" "net/url"
"github.com/containers/podman/v5/pkg/machine/define" "github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/common/pkg/completion" "github.com/containers/common/pkg/completion"
"github.com/containers/podman/v5/cmd/podman/registry" "github.com/containers/podman/v5/cmd/podman/registry"
@ -54,7 +55,7 @@ func ssh(cmd *cobra.Command, args []string) error {
validVM bool validVM bool
) )
dirs, err := machine.GetMachineDirs(provider.VMType()) dirs, err := env.GetMachineDirs(provider.VMType())
if err != nil { if err != nil {
return err return err
} }

View File

@ -9,6 +9,7 @@ import (
"github.com/containers/podman/v5/libpod/events" "github.com/containers/podman/v5/libpod/events"
"github.com/containers/podman/v5/pkg/machine" "github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/define" "github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/shim" "github.com/containers/podman/v5/pkg/machine/shim"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -55,7 +56,7 @@ func start(_ *cobra.Command, args []string) error {
vmName = args[0] vmName = args[0]
} }
dirs, err := machine.GetMachineDirs(provider.VMType()) dirs, err := env.GetMachineDirs(provider.VMType())
if err != nil { if err != nil {
return err return err
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/containers/podman/v5/cmd/podman/registry" "github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/libpod/events" "github.com/containers/podman/v5/libpod/events"
"github.com/containers/podman/v5/pkg/machine" "github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/shim" "github.com/containers/podman/v5/pkg/machine/shim"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -46,7 +46,7 @@ func stop(cmd *cobra.Command, args []string) error {
vmName = args[0] vmName = args[0]
} }
dirs, err := machine.GetMachineDirs(provider.VMType()) dirs, err := env.GetMachineDirs(provider.VMType())
if err != nil { if err != nil {
return err return err
} }

View File

@ -3,9 +3,9 @@
package system package system
import ( import (
"github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/connection" "github.com/containers/podman/v5/pkg/machine/connection"
"github.com/containers/podman/v5/pkg/machine/define" "github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
p "github.com/containers/podman/v5/pkg/machine/provider" p "github.com/containers/podman/v5/pkg/machine/provider"
"github.com/containers/podman/v5/pkg/machine/shim" "github.com/containers/podman/v5/pkg/machine/shim"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
@ -18,7 +18,7 @@ func resetMachine() error {
if err != nil { if err != nil {
return err return err
} }
dirs, err := machine.GetMachineDirs(provider.VMType()) dirs, err := env.GetMachineDirs(provider.VMType())
if err != nil { if err != nil {
return err return err
} }

View File

@ -9,14 +9,13 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"path/filepath"
"strings" "strings"
"time" "time"
"github.com/containers/podman/v5/pkg/machine/compression" "github.com/containers/podman/v5/pkg/machine/compression"
"github.com/containers/podman/v5/pkg/machine/define" "github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
"github.com/containers/storage/pkg/homedir"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -119,147 +118,6 @@ type InspectInfo struct {
Rootful bool Rootful bool
} }
// GetCacheDir returns the dir where VM images are downloaded into when pulled
func GetCacheDir(vmType define.VMType) (string, error) {
dataDir, err := GetDataDir(vmType)
if err != nil {
return "", err
}
cacheDir := filepath.Join(dataDir, "cache")
if _, err := os.Stat(cacheDir); !errors.Is(err, os.ErrNotExist) {
return cacheDir, nil
}
return cacheDir, os.MkdirAll(cacheDir, 0755)
}
// GetDataDir returns the filepath where vm images should
// live for podman-machine.
func GetDataDir(vmType define.VMType) (string, error) {
dataDirPrefix, err := DataDirPrefix()
if err != nil {
return "", err
}
dataDir := filepath.Join(dataDirPrefix, vmType.String())
if _, err := os.Stat(dataDir); !errors.Is(err, os.ErrNotExist) {
return dataDir, nil
}
mkdirErr := os.MkdirAll(dataDir, 0755)
return dataDir, mkdirErr
}
// GetGlobalDataDir returns the root of all backends
// for shared machine data.
func GetGlobalDataDir() (string, error) {
dataDir, err := DataDirPrefix()
if err != nil {
return "", err
}
return dataDir, os.MkdirAll(dataDir, 0755)
}
func GetMachineDirs(vmType define.VMType) (*define.MachineDirs, error) {
rtDir, err := getRuntimeDir()
if err != nil {
return nil, err
}
rtDir = filepath.Join(rtDir, "podman")
configDir, err := GetConfDir(vmType)
if err != nil {
return nil, err
}
configDirFile, err := define.NewMachineFile(configDir, nil)
if err != nil {
return nil, err
}
dataDir, err := GetDataDir(vmType)
if err != nil {
return nil, err
}
dataDirFile, err := define.NewMachineFile(dataDir, nil)
if err != nil {
return nil, err
}
imageCacheDir, err := dataDirFile.AppendToNewVMFile("cache", nil)
if err != nil {
return nil, err
}
rtDirFile, err := define.NewMachineFile(rtDir, nil)
if err != nil {
return nil, err
}
dirs := define.MachineDirs{
ConfigDir: configDirFile,
DataDir: dataDirFile,
ImageCacheDir: imageCacheDir,
RuntimeDir: rtDirFile,
}
// make sure all machine dirs are present
if err := os.MkdirAll(rtDir, 0755); err != nil {
return nil, err
}
if err := os.MkdirAll(configDir, 0755); err != nil {
return nil, err
}
// Because this is a mkdirall, we make the image cache dir
// which is a subdir of datadir (so the datadir is made anyway)
err = os.MkdirAll(imageCacheDir.GetPath(), 0755)
return &dirs, err
}
// DataDirPrefix returns the path prefix for all machine data files
func DataDirPrefix() (string, error) {
data, err := homedir.GetDataHome()
if err != nil {
return "", err
}
dataDir := filepath.Join(data, "containers", "podman", "machine")
return dataDir, nil
}
// GetConfigDir returns the filepath to where configuration
// files for podman-machine should live
func GetConfDir(vmType define.VMType) (string, error) {
confDirPrefix, err := ConfDirPrefix()
if err != nil {
return "", err
}
confDir := filepath.Join(confDirPrefix, vmType.String())
if _, err := os.Stat(confDir); !errors.Is(err, os.ErrNotExist) {
return confDir, nil
}
mkdirErr := os.MkdirAll(confDir, 0755)
return confDir, mkdirErr
}
// ConfDirPrefix returns the path prefix for all machine config files
func ConfDirPrefix() (string, error) {
conf, err := homedir.GetConfigHome()
if err != nil {
return "", err
}
confDir := filepath.Join(conf, "containers", "podman", "machine")
return confDir, nil
}
// GetSSHIdentityPath returns the path to the expected SSH private key
func GetSSHIdentityPath(name string) (string, error) {
datadir, err := GetGlobalDataDir()
if err != nil {
return "", err
}
return filepath.Join(datadir, name), nil
}
// ImageConfig describes the bootable image for the VM // ImageConfig describes the bootable image for the VM
type ImageConfig struct { type ImageConfig struct {
// IgnitionFile is the path to the filesystem where the // IgnitionFile is the path to the filesystem where the
@ -314,12 +172,12 @@ func (p *Virtualization) VMType() define.VMType {
} }
func (p *Virtualization) NewDownload(vmName string) (Download, error) { func (p *Virtualization) NewDownload(vmName string) (Download, error) {
cacheDir, err := GetCacheDir(p.VMType()) cacheDir, err := env.GetCacheDir(p.VMType())
if err != nil { if err != nil {
return Download{}, err return Download{}, err
} }
dataDir, err := GetDataDir(p.VMType()) dataDir, err := env.GetDataDir(p.VMType())
if err != nil { if err != nil {
return Download{}, err return Download{}, err
} }

View File

@ -6,14 +6,15 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestGetSSHIdentityPath(t *testing.T) { func TestGetSSHIdentityPath(t *testing.T) {
name := "p-test" name := "p-test"
datadir, err := GetGlobalDataDir() datadir, err := env.GetGlobalDataDir()
assert.Nil(t, err) assert.Nil(t, err)
identityPath, err := GetSSHIdentityPath(name) identityPath, err := env.GetSSHIdentityPath(name)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, identityPath, filepath.Join(datadir, name)) assert.Equal(t, identityPath, filepath.Join(datadir, name))
} }

151
pkg/machine/env/dir.go vendored Normal file
View File

@ -0,0 +1,151 @@
package env
import (
"errors"
"os"
"path/filepath"
"github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/storage/pkg/homedir"
)
// GetCacheDir returns the dir where VM images are downloaded into when pulled
func GetCacheDir(vmType define.VMType) (string, error) {
dataDir, err := GetDataDir(vmType)
if err != nil {
return "", err
}
cacheDir := filepath.Join(dataDir, "cache")
if _, err := os.Stat(cacheDir); !errors.Is(err, os.ErrNotExist) {
return cacheDir, nil
}
return cacheDir, os.MkdirAll(cacheDir, 0755)
}
// GetDataDir returns the filepath where vm images should
// live for podman-machine.
func GetDataDir(vmType define.VMType) (string, error) {
dataDirPrefix, err := DataDirPrefix()
if err != nil {
return "", err
}
dataDir := filepath.Join(dataDirPrefix, vmType.String())
if _, err := os.Stat(dataDir); !errors.Is(err, os.ErrNotExist) {
return dataDir, nil
}
mkdirErr := os.MkdirAll(dataDir, 0755)
return dataDir, mkdirErr
}
// GetGlobalDataDir returns the root of all backends
// for shared machine data.
func GetGlobalDataDir() (string, error) {
dataDir, err := DataDirPrefix()
if err != nil {
return "", err
}
return dataDir, os.MkdirAll(dataDir, 0755)
}
func GetMachineDirs(vmType define.VMType) (*define.MachineDirs, error) {
rtDir, err := getRuntimeDir()
if err != nil {
return nil, err
}
rtDir = filepath.Join(rtDir, "podman")
configDir, err := GetConfDir(vmType)
if err != nil {
return nil, err
}
configDirFile, err := define.NewMachineFile(configDir, nil)
if err != nil {
return nil, err
}
dataDir, err := GetDataDir(vmType)
if err != nil {
return nil, err
}
dataDirFile, err := define.NewMachineFile(dataDir, nil)
if err != nil {
return nil, err
}
imageCacheDir, err := dataDirFile.AppendToNewVMFile("cache", nil)
if err != nil {
return nil, err
}
rtDirFile, err := define.NewMachineFile(rtDir, nil)
if err != nil {
return nil, err
}
dirs := define.MachineDirs{
ConfigDir: configDirFile,
DataDir: dataDirFile,
ImageCacheDir: imageCacheDir,
RuntimeDir: rtDirFile,
}
// make sure all machine dirs are present
if err := os.MkdirAll(rtDir, 0755); err != nil {
return nil, err
}
if err := os.MkdirAll(configDir, 0755); err != nil {
return nil, err
}
// Because this is a mkdirall, we make the image cache dir
// which is a subdir of datadir (so the datadir is made anyway)
err = os.MkdirAll(imageCacheDir.GetPath(), 0755)
return &dirs, err
}
// DataDirPrefix returns the path prefix for all machine data files
func DataDirPrefix() (string, error) {
data, err := homedir.GetDataHome()
if err != nil {
return "", err
}
dataDir := filepath.Join(data, "containers", "podman", "machine")
return dataDir, nil
}
// GetConfigDir returns the filepath to where configuration
// files for podman-machine should live
func GetConfDir(vmType define.VMType) (string, error) {
confDirPrefix, err := ConfDirPrefix()
if err != nil {
return "", err
}
confDir := filepath.Join(confDirPrefix, vmType.String())
if _, err := os.Stat(confDir); !errors.Is(err, os.ErrNotExist) {
return confDir, nil
}
mkdirErr := os.MkdirAll(confDir, 0755)
return confDir, mkdirErr
}
// ConfDirPrefix returns the path prefix for all machine config files
func ConfDirPrefix() (string, error) {
conf, err := homedir.GetConfigHome()
if err != nil {
return "", err
}
confDir := filepath.Join(conf, "containers", "podman", "machine")
return confDir, nil
}
// GetSSHIdentityPath returns the path to the expected SSH private key
func GetSSHIdentityPath(name string) (string, error) {
datadir, err := GetGlobalDataDir()
if err != nil {
return "", err
}
return filepath.Join(datadir, name), nil
}

View File

@ -1,4 +1,4 @@
package machine package env
import "os" import "os"

View File

@ -1,4 +1,4 @@
package machine package env
import "os" import "os"

View File

@ -1,4 +1,4 @@
package machine package env
import ( import (
"github.com/containers/podman/v5/pkg/rootless" "github.com/containers/podman/v5/pkg/rootless"

View File

@ -1,4 +1,4 @@
package machine package env
import "os" import "os"

View File

@ -10,6 +10,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/shim/diskpull" "github.com/containers/podman/v5/pkg/machine/shim/diskpull"
"github.com/Microsoft/go-winio" "github.com/Microsoft/go-winio"
@ -387,7 +388,7 @@ func (h HyperVStubber) PostStartNetworking(mc *vmconfigs.MachineConfig, noInfo b
dirs *define.MachineDirs dirs *define.MachineDirs
gvproxyPID int gvproxyPID int
) )
dirs, err = machine.GetMachineDirs(h.VMType()) dirs, err = env.GetMachineDirs(h.VMType())
if err != nil { if err != nil {
return err return err
} }
@ -503,7 +504,7 @@ func removeIgnitionFromRegistry(vm *hypervctl.VirtualMachine) error {
} }
func logCommandToFile(c *exec.Cmd, filename string) error { func logCommandToFile(c *exec.Cmd, filename string) error {
dir, err := machine.GetDataDir(define.HyperVVirt) dir, err := env.GetDataDir(define.HyperVVirt)
if err != nil { if err != nil {
return fmt.Errorf("obtain machine dir: %w", err) return fmt.Errorf("obtain machine dir: %w", err)
} }

View File

@ -17,6 +17,7 @@ import (
winio "github.com/Microsoft/go-winio" winio "github.com/Microsoft/go-winio"
"github.com/containers/podman/v5/pkg/machine/define" "github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -250,7 +251,7 @@ func FindExecutablePeer(name string) (string, error) {
} }
func GetWinProxyStateDir(name string, vmtype define.VMType) (string, error) { func GetWinProxyStateDir(name string, vmtype define.VMType) (string, error) {
dir, err := GetDataDir(vmtype) dir, err := env.GetDataDir(vmtype)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"github.com/containers/podman/v5/pkg/machine" "github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/shim" "github.com/containers/podman/v5/pkg/machine/shim"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
) )
@ -27,7 +28,7 @@ func (m *MachineOS) Apply(image string, opts ApplyOptions) error {
return err return err
} }
dirs, err := machine.GetMachineDirs(m.Provider.VMType()) dirs, err := env.GetMachineDirs(m.Provider.VMType())
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,4 +1,4 @@
package machine package ports
import ( import (
"context" "context"
@ -11,6 +11,7 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/storage/pkg/ioutils" "github.com/containers/storage/pkg/ioutils"
"github.com/containers/storage/pkg/lockfile" "github.com/containers/storage/pkg/lockfile"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -135,7 +136,7 @@ func getRandomPortHold() (io.Closer, int, error) {
} }
func acquirePortLock() (*lockfile.LockFile, error) { func acquirePortLock() (*lockfile.LockFile, error) {
lockDir, err := GetGlobalDataDir() lockDir, err := env.GetGlobalDataDir()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -150,7 +151,7 @@ func acquirePortLock() (*lockfile.LockFile, error) {
} }
func loadPortAllocations() (map[int]struct{}, error) { func loadPortAllocations() (map[int]struct{}, error) {
portDir, err := GetGlobalDataDir() portDir, err := env.GetGlobalDataDir()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -186,7 +187,7 @@ func loadPortAllocations() (map[int]struct{}, error) {
} }
func storePortAllocations(ports map[int]struct{}) error { func storePortAllocations(ports map[int]struct{}) error {
portDir, err := GetGlobalDataDir() portDir, err := env.GetGlobalDataDir()
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,6 +1,6 @@
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd
package machine package ports
import ( import (
"net" "net"

View File

@ -1,4 +1,4 @@
package machine package ports
import ( import (
"net" "net"

View File

@ -15,6 +15,7 @@ import (
"github.com/containers/podman/v5/pkg/machine/compression" "github.com/containers/podman/v5/pkg/machine/compression"
"github.com/containers/podman/v5/pkg/machine/define" "github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/ocipull" "github.com/containers/podman/v5/pkg/machine/ocipull"
"github.com/containers/podman/v5/utils" "github.com/containers/podman/v5/utils"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -31,11 +32,11 @@ func NewGenericDownloader(vmType define.VMType, vmName, pullPath string) (Distri
var ( var (
imageName string imageName string
) )
dataDir, err := GetDataDir(vmType) dataDir, err := env.GetDataDir(vmType)
if err != nil { if err != nil {
return nil, err return nil, err
} }
cacheDir, err := GetCacheDir(vmType) cacheDir, err := env.GetCacheDir(vmType)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -13,6 +13,7 @@ import (
"github.com/containers/podman/v5/pkg/machine" "github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/connection" "github.com/containers/podman/v5/pkg/machine/connection"
machineDefine "github.com/containers/podman/v5/pkg/machine/define" machineDefine "github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/ignition" "github.com/containers/podman/v5/pkg/machine/ignition"
"github.com/containers/podman/v5/pkg/machine/proxyenv" "github.com/containers/podman/v5/pkg/machine/proxyenv"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
@ -29,7 +30,7 @@ func List(vmstubbers []vmconfigs.VMProvider, _ machine.ListOptions) ([]*machine.
) )
for _, s := range vmstubbers { for _, s := range vmstubbers {
dirs, err := machine.GetMachineDirs(s.VMType()) dirs, err := env.GetMachineDirs(s.VMType())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -76,12 +77,12 @@ func Init(opts machineDefine.InitOptions, mp vmconfigs.VMProvider) (*vmconfigs.M
defer callbackFuncs.CleanIfErr(&err) defer callbackFuncs.CleanIfErr(&err)
go callbackFuncs.CleanOnSignal() go callbackFuncs.CleanOnSignal()
dirs, err := machine.GetMachineDirs(mp.VMType()) dirs, err := env.GetMachineDirs(mp.VMType())
if err != nil { if err != nil {
return nil, err return nil, err
} }
sshIdentityPath, err := machine.GetSSHIdentityPath(machineDefine.DefaultIdentityName) sshIdentityPath, err := env.GetSSHIdentityPath(machineDefine.DefaultIdentityName)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -288,7 +289,7 @@ func CheckExclusiveActiveVM(provider vmconfigs.VMProvider, mc *vmconfigs.Machine
func getMCsOverProviders(vmstubbers []vmconfigs.VMProvider) (map[string]*vmconfigs.MachineConfig, error) { func getMCsOverProviders(vmstubbers []vmconfigs.VMProvider) (map[string]*vmconfigs.MachineConfig, error) {
mcs := make(map[string]*vmconfigs.MachineConfig) mcs := make(map[string]*vmconfigs.MachineConfig)
for _, stubber := range vmstubbers { for _, stubber := range vmstubbers {
dirs, err := machine.GetMachineDirs(stubber.VMType()) dirs, err := env.GetMachineDirs(stubber.VMType())
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -12,6 +12,7 @@ import (
gvproxy "github.com/containers/gvisor-tap-vsock/pkg/types" gvproxy "github.com/containers/gvisor-tap-vsock/pkg/types"
"github.com/containers/podman/v5/pkg/machine" "github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/define" "github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -95,7 +96,7 @@ func startNetworking(mc *vmconfigs.MachineConfig, provider vmconfigs.VMProvider)
return "", 0, provider.StartNetworking(mc, nil) return "", 0, provider.StartNetworking(mc, nil)
} }
dirs, err := machine.GetMachineDirs(provider.VMType()) dirs, err := env.GetMachineDirs(provider.VMType())
if err != nil { if err != nil {
return "", 0, err return "", 0, err
} }

View File

@ -17,6 +17,7 @@ import (
"github.com/containers/common/pkg/config" "github.com/containers/common/pkg/config"
"github.com/containers/podman/v5/pkg/machine" "github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/define" "github.com/containers/podman/v5/pkg/machine/define"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/ignition" "github.com/containers/podman/v5/pkg/machine/ignition"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
"github.com/containers/podman/v5/pkg/machine/wsl/wutil" "github.com/containers/podman/v5/pkg/machine/wsl/wutil"
@ -47,7 +48,7 @@ func getConfigPath(name string) (string, error) {
//nolint:unused //nolint:unused
func getConfigPathExt(name string, extension string) (string, error) { func getConfigPathExt(name string, extension string) (string, error) {
vmConfigDir, err := machine.GetConfDir(vmtype) vmConfigDir, err := env.GetConfDir(vmtype)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -66,7 +67,7 @@ func unprovisionWSL(mc *vmconfigs.MachineConfig) error {
logrus.Error(err) logrus.Error(err)
} }
vmDataDir, err := machine.GetDataDir(vmtype) vmDataDir, err := env.GetDataDir(vmtype)
if err != nil { if err != nil {
return err return err
} }
@ -79,7 +80,7 @@ func unprovisionWSL(mc *vmconfigs.MachineConfig) error {
// we should push this stuff be more common (dir names, etc) and also use // we should push this stuff be more common (dir names, etc) and also use
// typed things where possible like vmfiles // typed things where possible like vmfiles
func provisionWSLDist(name string, imagePath string, prompt string) (string, error) { func provisionWSLDist(name string, imagePath string, prompt string) (string, error) {
vmDataDir, err := machine.GetDataDir(vmtype) vmDataDir, err := env.GetDataDir(vmtype)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -586,7 +587,7 @@ func setupWslProxyEnv() (hasProxy bool) {
//nolint:unused //nolint:unused
func obtainGlobalConfigLock() (*fileLock, error) { func obtainGlobalConfigLock() (*fileLock, error) {
lockDir, err := machine.GetGlobalDataDir() lockDir, err := env.GetGlobalDataDir()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -702,7 +703,7 @@ func isRunning(name string) (bool, error) {
//nolint:unused //nolint:unused
func getDiskSize(name string) uint64 { func getDiskSize(name string) uint64 {
vmDataDir, err := machine.GetDataDir(vmtype) vmDataDir, err := env.GetDataDir(vmtype)
if err != nil { if err != nil {
return 0 return 0
} }

View File

@ -11,6 +11,7 @@ import (
"strings" "strings"
"github.com/containers/podman/v5/pkg/machine/ocipull" "github.com/containers/podman/v5/pkg/machine/ocipull"
"github.com/containers/podman/v5/pkg/machine/ports"
"github.com/containers/podman/v5/pkg/machine/shim/diskpull" "github.com/containers/podman/v5/pkg/machine/shim/diskpull"
"github.com/containers/podman/v5/pkg/machine/stdpull" "github.com/containers/podman/v5/pkg/machine/stdpull"
"github.com/containers/podman/v5/pkg/machine/wsl/wutil" "github.com/containers/podman/v5/pkg/machine/wsl/wutil"
@ -110,7 +111,7 @@ func (w WSLStubber) Remove(mc *vmconfigs.MachineConfig) ([]string, func() error,
if err := runCmdPassThrough(wutil.FindWSL(), "--unregister", machine.ToDist(mc.Name)); err != nil { if err := runCmdPassThrough(wutil.FindWSL(), "--unregister", machine.ToDist(mc.Name)); err != nil {
logrus.Error(err) logrus.Error(err)
} }
return machine.ReleaseMachinePort(mc.SSH.Port) return ports.ReleaseMachinePort(mc.SSH.Port)
} }
return []string{}, wslRemoveFunc, nil return []string{}, wslRemoveFunc, nil

View File

@ -10,6 +10,7 @@ import (
"path/filepath" "path/filepath"
"github.com/containers/podman/v5/pkg/machine" "github.com/containers/podman/v5/pkg/machine"
"github.com/containers/podman/v5/pkg/machine/env"
"github.com/containers/podman/v5/pkg/machine/vmconfigs" "github.com/containers/podman/v5/pkg/machine/vmconfigs"
"github.com/containers/podman/v5/pkg/machine/wsl/wutil" "github.com/containers/podman/v5/pkg/machine/wsl/wutil"
"github.com/containers/podman/v5/pkg/specgen" "github.com/containers/podman/v5/pkg/specgen"
@ -226,7 +227,7 @@ func createUserModeResolvConf(dist string) error {
} }
func getUserModeNetDir() (string, error) { func getUserModeNetDir() (string, error) {
vmDataDir, err := machine.GetDataDir(vmtype) vmDataDir, err := env.GetDataDir(vmtype)
if err != nil { if err != nil {
return "", err return "", err
} }