mirror of https://github.com/containers/podman.git
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:
parent
e58b168e11
commit
ef7727238a
|
@ -7,8 +7,8 @@ import (
|
|||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/containers/podman/v5/pkg/machine"
|
||||
"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/vmconfigs"
|
||||
)
|
||||
|
@ -18,7 +18,7 @@ func getMachineConn(connectionURI string, parsedConnection *url.URL) (string, er
|
|||
if err != nil {
|
||||
return "", fmt.Errorf("getting machine provider: %w", err)
|
||||
}
|
||||
dirs, err := machine.GetMachineDirs(machineProvider.VMType())
|
||||
dirs, err := env.GetMachineDirs(machineProvider.VMType())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ import (
|
|||
"github.com/containers/podman/v5/cmd/podman/validate"
|
||||
"github.com/containers/podman/v5/libpod/define"
|
||||
"github.com/containers/podman/v5/pkg/domain/entities"
|
||||
"github.com/containers/podman/v5/pkg/machine"
|
||||
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/spf13/cobra"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
@ -100,7 +100,7 @@ func hostInfo() (*entities.MachineHostInfo, error) {
|
|||
host.Arch = runtime.GOARCH
|
||||
host.OS = runtime.GOOS
|
||||
|
||||
dirs, err := machine.GetMachineDirs(provider.VMType())
|
||||
dirs, err := env.GetMachineDirs(provider.VMType())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/containers/podman/v5/cmd/podman/registry"
|
||||
"github.com/containers/podman/v5/cmd/podman/utils"
|
||||
"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/spf13/cobra"
|
||||
)
|
||||
|
@ -47,7 +48,7 @@ func inspect(cmd *cobra.Command, args []string) error {
|
|||
var (
|
||||
errs utils.OutputErrors
|
||||
)
|
||||
dirs, err := machine.GetMachineDirs(provider.VMType())
|
||||
dirs, err := env.GetMachineDirs(provider.VMType())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
"github.com/containers/podman/v5/cmd/podman/registry"
|
||||
"github.com/containers/podman/v5/cmd/podman/validate"
|
||||
"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"
|
||||
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
|
||||
"github.com/containers/podman/v5/pkg/util"
|
||||
|
@ -82,7 +82,7 @@ func getMachines(toComplete string) ([]string, cobra.ShellCompDirective) {
|
|||
if err != nil {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
dirs, err := machine.GetMachineDirs(provider.VMType())
|
||||
dirs, err := env.GetMachineDirs(provider.VMType())
|
||||
if err != nil {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
machineconfig "github.com/containers/common/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"
|
||||
"github.com/containers/podman/v5/pkg/machine/provider"
|
||||
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
|
||||
|
@ -52,7 +53,7 @@ func machineOSManager(opts ManagerOpts, _ vmconfigs.VMProvider) (pkgOS.Manager,
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dirs, err := pkgMachine.GetMachineDirs(p.VMType())
|
||||
dirs, err := env.GetMachineDirs(p.VMType())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/containers/podman/v5/cmd/podman/registry"
|
||||
"github.com/containers/podman/v5/cmd/podman/validate"
|
||||
"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/vmconfigs"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -50,7 +51,7 @@ func reset(_ *cobra.Command, _ []string) error {
|
|||
err error
|
||||
)
|
||||
|
||||
dirs, err := machine.GetMachineDirs(provider.VMType())
|
||||
dirs, err := env.GetMachineDirs(provider.VMType())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/containers/podman/v5/cmd/podman/registry"
|
||||
"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/vmconfigs"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -54,7 +55,7 @@ func rm(_ *cobra.Command, args []string) error {
|
|||
vmName = args[0]
|
||||
}
|
||||
|
||||
dirs, err := machine.GetMachineDirs(provider.VMType())
|
||||
dirs, err := env.GetMachineDirs(provider.VMType())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/strongunits"
|
||||
"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/env"
|
||||
"github.com/containers/podman/v5/pkg/machine/shim"
|
||||
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -99,7 +99,7 @@ func setMachine(cmd *cobra.Command, args []string) error {
|
|||
vmName = args[0]
|
||||
}
|
||||
|
||||
dirs, err := machine.GetMachineDirs(provider.VMType())
|
||||
dirs, err := env.GetMachineDirs(provider.VMType())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"net/url"
|
||||
|
||||
"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/podman/v5/cmd/podman/registry"
|
||||
|
@ -54,7 +55,7 @@ func ssh(cmd *cobra.Command, args []string) error {
|
|||
validVM bool
|
||||
)
|
||||
|
||||
dirs, err := machine.GetMachineDirs(provider.VMType())
|
||||
dirs, err := env.GetMachineDirs(provider.VMType())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/containers/podman/v5/libpod/events"
|
||||
"github.com/containers/podman/v5/pkg/machine"
|
||||
"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/vmconfigs"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -55,7 +56,7 @@ func start(_ *cobra.Command, args []string) error {
|
|||
vmName = args[0]
|
||||
}
|
||||
|
||||
dirs, err := machine.GetMachineDirs(provider.VMType())
|
||||
dirs, err := env.GetMachineDirs(provider.VMType())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
"github.com/containers/podman/v5/cmd/podman/registry"
|
||||
"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/vmconfigs"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -46,7 +46,7 @@ func stop(cmd *cobra.Command, args []string) error {
|
|||
vmName = args[0]
|
||||
}
|
||||
|
||||
dirs, err := machine.GetMachineDirs(provider.VMType())
|
||||
dirs, err := env.GetMachineDirs(provider.VMType())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
package system
|
||||
|
||||
import (
|
||||
"github.com/containers/podman/v5/pkg/machine"
|
||||
"github.com/containers/podman/v5/pkg/machine/connection"
|
||||
"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"
|
||||
"github.com/containers/podman/v5/pkg/machine/shim"
|
||||
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
|
||||
|
@ -18,7 +18,7 @@ func resetMachine() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dirs, err := machine.GetMachineDirs(provider.VMType())
|
||||
dirs, err := env.GetMachineDirs(provider.VMType())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -9,14 +9,13 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containers/podman/v5/pkg/machine/compression"
|
||||
"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/storage/pkg/homedir"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -119,147 +118,6 @@ type InspectInfo struct {
|
|||
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
|
||||
type ImageConfig struct {
|
||||
// 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) {
|
||||
cacheDir, err := GetCacheDir(p.VMType())
|
||||
cacheDir, err := env.GetCacheDir(p.VMType())
|
||||
if err != nil {
|
||||
return Download{}, err
|
||||
}
|
||||
|
||||
dataDir, err := GetDataDir(p.VMType())
|
||||
dataDir, err := env.GetDataDir(p.VMType())
|
||||
if err != nil {
|
||||
return Download{}, err
|
||||
}
|
||||
|
|
|
@ -6,14 +6,15 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/containers/podman/v5/pkg/machine/env"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetSSHIdentityPath(t *testing.T) {
|
||||
name := "p-test"
|
||||
datadir, err := GetGlobalDataDir()
|
||||
datadir, err := env.GetGlobalDataDir()
|
||||
assert.Nil(t, err)
|
||||
identityPath, err := GetSSHIdentityPath(name)
|
||||
identityPath, err := env.GetSSHIdentityPath(name)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, identityPath, filepath.Join(datadir, name))
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package machine
|
||||
package env
|
||||
|
||||
import "os"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package machine
|
||||
package env
|
||||
|
||||
import "os"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package machine
|
||||
package env
|
||||
|
||||
import (
|
||||
"github.com/containers/podman/v5/pkg/rootless"
|
|
@ -1,4 +1,4 @@
|
|||
package machine
|
||||
package env
|
||||
|
||||
import "os"
|
||||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/containers/podman/v5/pkg/machine/env"
|
||||
"github.com/containers/podman/v5/pkg/machine/shim/diskpull"
|
||||
|
||||
"github.com/Microsoft/go-winio"
|
||||
|
@ -387,7 +388,7 @@ func (h HyperVStubber) PostStartNetworking(mc *vmconfigs.MachineConfig, noInfo b
|
|||
dirs *define.MachineDirs
|
||||
gvproxyPID int
|
||||
)
|
||||
dirs, err = machine.GetMachineDirs(h.VMType())
|
||||
dirs, err = env.GetMachineDirs(h.VMType())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -503,7 +504,7 @@ func removeIgnitionFromRegistry(vm *hypervctl.VirtualMachine) error {
|
|||
}
|
||||
|
||||
func logCommandToFile(c *exec.Cmd, filename string) error {
|
||||
dir, err := machine.GetDataDir(define.HyperVVirt)
|
||||
dir, err := env.GetDataDir(define.HyperVVirt)
|
||||
if err != nil {
|
||||
return fmt.Errorf("obtain machine dir: %w", err)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
|
||||
winio "github.com/Microsoft/go-winio"
|
||||
"github.com/containers/podman/v5/pkg/machine/define"
|
||||
"github.com/containers/podman/v5/pkg/machine/env"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -250,7 +251,7 @@ func FindExecutablePeer(name string) (string, error) {
|
|||
}
|
||||
|
||||
func GetWinProxyStateDir(name string, vmtype define.VMType) (string, error) {
|
||||
dir, err := GetDataDir(vmtype)
|
||||
dir, err := env.GetDataDir(vmtype)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"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/vmconfigs"
|
||||
)
|
||||
|
@ -27,7 +28,7 @@ func (m *MachineOS) Apply(image string, opts ApplyOptions) error {
|
|||
return err
|
||||
}
|
||||
|
||||
dirs, err := machine.GetMachineDirs(m.Provider.VMType())
|
||||
dirs, err := env.GetMachineDirs(m.Provider.VMType())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package machine
|
||||
package ports
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -11,6 +11,7 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/containers/podman/v5/pkg/machine/env"
|
||||
"github.com/containers/storage/pkg/ioutils"
|
||||
"github.com/containers/storage/pkg/lockfile"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -135,7 +136,7 @@ func getRandomPortHold() (io.Closer, int, error) {
|
|||
}
|
||||
|
||||
func acquirePortLock() (*lockfile.LockFile, error) {
|
||||
lockDir, err := GetGlobalDataDir()
|
||||
lockDir, err := env.GetGlobalDataDir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -150,7 +151,7 @@ func acquirePortLock() (*lockfile.LockFile, error) {
|
|||
}
|
||||
|
||||
func loadPortAllocations() (map[int]struct{}, error) {
|
||||
portDir, err := GetGlobalDataDir()
|
||||
portDir, err := env.GetGlobalDataDir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -186,7 +187,7 @@ func loadPortAllocations() (map[int]struct{}, error) {
|
|||
}
|
||||
|
||||
func storePortAllocations(ports map[int]struct{}) error {
|
||||
portDir, err := GetGlobalDataDir()
|
||||
portDir, err := env.GetGlobalDataDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd
|
||||
|
||||
package machine
|
||||
package ports
|
||||
|
||||
import (
|
||||
"net"
|
|
@ -1,4 +1,4 @@
|
|||
package machine
|
||||
package ports
|
||||
|
||||
import (
|
||||
"net"
|
|
@ -15,6 +15,7 @@ import (
|
|||
|
||||
"github.com/containers/podman/v5/pkg/machine/compression"
|
||||
"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/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -31,11 +32,11 @@ func NewGenericDownloader(vmType define.VMType, vmName, pullPath string) (Distri
|
|||
var (
|
||||
imageName string
|
||||
)
|
||||
dataDir, err := GetDataDir(vmType)
|
||||
dataDir, err := env.GetDataDir(vmType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cacheDir, err := GetCacheDir(vmType)
|
||||
cacheDir, err := env.GetCacheDir(vmType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/containers/podman/v5/pkg/machine"
|
||||
"github.com/containers/podman/v5/pkg/machine/connection"
|
||||
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/proxyenv"
|
||||
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
|
||||
|
@ -29,7 +30,7 @@ func List(vmstubbers []vmconfigs.VMProvider, _ machine.ListOptions) ([]*machine.
|
|||
)
|
||||
|
||||
for _, s := range vmstubbers {
|
||||
dirs, err := machine.GetMachineDirs(s.VMType())
|
||||
dirs, err := env.GetMachineDirs(s.VMType())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -76,12 +77,12 @@ func Init(opts machineDefine.InitOptions, mp vmconfigs.VMProvider) (*vmconfigs.M
|
|||
defer callbackFuncs.CleanIfErr(&err)
|
||||
go callbackFuncs.CleanOnSignal()
|
||||
|
||||
dirs, err := machine.GetMachineDirs(mp.VMType())
|
||||
dirs, err := env.GetMachineDirs(mp.VMType())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sshIdentityPath, err := machine.GetSSHIdentityPath(machineDefine.DefaultIdentityName)
|
||||
sshIdentityPath, err := env.GetSSHIdentityPath(machineDefine.DefaultIdentityName)
|
||||
if err != nil {
|
||||
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) {
|
||||
mcs := make(map[string]*vmconfigs.MachineConfig)
|
||||
for _, stubber := range vmstubbers {
|
||||
dirs, err := machine.GetMachineDirs(stubber.VMType())
|
||||
dirs, err := env.GetMachineDirs(stubber.VMType())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
gvproxy "github.com/containers/gvisor-tap-vsock/pkg/types"
|
||||
"github.com/containers/podman/v5/pkg/machine"
|
||||
"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/sirupsen/logrus"
|
||||
)
|
||||
|
@ -95,7 +96,7 @@ func startNetworking(mc *vmconfigs.MachineConfig, provider vmconfigs.VMProvider)
|
|||
return "", 0, provider.StartNetworking(mc, nil)
|
||||
}
|
||||
|
||||
dirs, err := machine.GetMachineDirs(provider.VMType())
|
||||
dirs, err := env.GetMachineDirs(provider.VMType())
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/podman/v5/pkg/machine"
|
||||
"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/vmconfigs"
|
||||
"github.com/containers/podman/v5/pkg/machine/wsl/wutil"
|
||||
|
@ -47,7 +48,7 @@ func getConfigPath(name string) (string, error) {
|
|||
|
||||
//nolint:unused
|
||||
func getConfigPathExt(name string, extension string) (string, error) {
|
||||
vmConfigDir, err := machine.GetConfDir(vmtype)
|
||||
vmConfigDir, err := env.GetConfDir(vmtype)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -66,7 +67,7 @@ func unprovisionWSL(mc *vmconfigs.MachineConfig) error {
|
|||
logrus.Error(err)
|
||||
}
|
||||
|
||||
vmDataDir, err := machine.GetDataDir(vmtype)
|
||||
vmDataDir, err := env.GetDataDir(vmtype)
|
||||
if err != nil {
|
||||
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
|
||||
// typed things where possible like vmfiles
|
||||
func provisionWSLDist(name string, imagePath string, prompt string) (string, error) {
|
||||
vmDataDir, err := machine.GetDataDir(vmtype)
|
||||
vmDataDir, err := env.GetDataDir(vmtype)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -586,7 +587,7 @@ func setupWslProxyEnv() (hasProxy bool) {
|
|||
|
||||
//nolint:unused
|
||||
func obtainGlobalConfigLock() (*fileLock, error) {
|
||||
lockDir, err := machine.GetGlobalDataDir()
|
||||
lockDir, err := env.GetGlobalDataDir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -702,7 +703,7 @@ func isRunning(name string) (bool, error) {
|
|||
|
||||
//nolint:unused
|
||||
func getDiskSize(name string) uint64 {
|
||||
vmDataDir, err := machine.GetDataDir(vmtype)
|
||||
vmDataDir, err := env.GetDataDir(vmtype)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"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/stdpull"
|
||||
"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 {
|
||||
logrus.Error(err)
|
||||
}
|
||||
return machine.ReleaseMachinePort(mc.SSH.Port)
|
||||
return ports.ReleaseMachinePort(mc.SSH.Port)
|
||||
}
|
||||
|
||||
return []string{}, wslRemoveFunc, nil
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"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/wsl/wutil"
|
||||
"github.com/containers/podman/v5/pkg/specgen"
|
||||
|
@ -226,7 +227,7 @@ func createUserModeResolvConf(dist string) error {
|
|||
}
|
||||
|
||||
func getUserModeNetDir() (string, error) {
|
||||
vmDataDir, err := machine.GetDataDir(vmtype)
|
||||
vmDataDir, err := env.GetDataDir(vmtype)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue