mirror of
https://github.com/containers/podman.git
synced 2025-06-19 16:33:24 +08:00
Minor cleanup from podman 4
This PR is only a few cleanup items where code is no longer used. More to come I'm sure [NO NEW TESTS NEEDED] Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
@ -5,20 +5,17 @@ package machine
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"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/vmconfigs"
|
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
|
||||||
"github.com/containers/storage/pkg/homedir"
|
"github.com/containers/storage/pkg/homedir"
|
||||||
"github.com/containers/storage/pkg/lockfile"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,8 +25,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
DefaultIgnitionUserName = "core"
|
ForwarderBinaryName = "gvproxy"
|
||||||
ForwarderBinaryName = "gvproxy"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Download struct {
|
type Download struct {
|
||||||
@ -88,6 +84,7 @@ type RemoveOptions struct {
|
|||||||
|
|
||||||
type InspectOptions struct{}
|
type InspectOptions struct{}
|
||||||
|
|
||||||
|
// TODO This can be removed when WSL is refactored into podman 5
|
||||||
type VM interface {
|
type VM interface {
|
||||||
Init(opts define.InitOptions) (bool, error)
|
Init(opts define.InitOptions) (bool, error)
|
||||||
Inspect() (*InspectInfo, error)
|
Inspect() (*InspectInfo, error)
|
||||||
@ -146,7 +143,7 @@ func GetDataDir(vmType define.VMType) (string, error) {
|
|||||||
return dataDir, mkdirErr
|
return dataDir, mkdirErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGLobalDataDir returns the root of all backends
|
// GetGlobalDataDir returns the root of all backends
|
||||||
// for shared machine data.
|
// for shared machine data.
|
||||||
func GetGlobalDataDir() (string, error) {
|
func GetGlobalDataDir() (string, error) {
|
||||||
dataDir, err := DataDirPrefix()
|
dataDir, err := DataDirPrefix()
|
||||||
@ -279,6 +276,7 @@ const (
|
|||||||
DockerGlobal
|
DockerGlobal
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO THis should be able to be removed once WSL is refactored for podman5
|
||||||
type Virtualization struct {
|
type Virtualization struct {
|
||||||
artifact define.Artifact
|
artifact define.Artifact
|
||||||
compression compression.ImageCompression
|
compression compression.ImageCompression
|
||||||
@ -357,96 +355,3 @@ func WaitAndPingAPI(sock string) {
|
|||||||
logrus.Warn("API socket failed ping test")
|
logrus.Warn("API socket failed ping test")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dl Download) NewFcosDownloader(imageStream FCOSStream) (DistributionDownload, error) {
|
|
||||||
info, err := dl.GetFCOSDownload(imageStream)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
urlSplit := strings.Split(info.Location, "/")
|
|
||||||
dl.ImageName = urlSplit[len(urlSplit)-1]
|
|
||||||
downloadURL, err := url.Parse(info.Location)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Complete the download struct
|
|
||||||
dl.Arch = GetFcosArch()
|
|
||||||
// This could be eliminated as a struct and be a generated()
|
|
||||||
dl.LocalPath = filepath.Join(dl.CacheDir, dl.ImageName)
|
|
||||||
dl.Sha256sum = info.Sha256Sum
|
|
||||||
dl.URL = downloadURL
|
|
||||||
fcd := FcosDownload{
|
|
||||||
Download: dl,
|
|
||||||
}
|
|
||||||
dataDir, err := GetDataDir(dl.VMKind)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
fcd.Download.LocalUncompressedFile = fcd.GetLocalUncompressedFile(dataDir)
|
|
||||||
return fcd, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// AcquireVMImage determines if the image is already in a FCOS stream. If so,
|
|
||||||
// retrieves the image path of the uncompressed file. Otherwise, the user has
|
|
||||||
// provided an alternative image, so we set the image path and download the image.
|
|
||||||
func (dl Download) AcquireVMImage(imagePath string) (*define.VMFile, FCOSStream, error) {
|
|
||||||
var (
|
|
||||||
err error
|
|
||||||
imageLocation *define.VMFile
|
|
||||||
fcosStream FCOSStream
|
|
||||||
)
|
|
||||||
|
|
||||||
switch imagePath {
|
|
||||||
// TODO these need to be re-typed as FCOSStreams
|
|
||||||
case Testing.String(), Next.String(), Stable.String(), "":
|
|
||||||
// Get image as usual
|
|
||||||
fcosStream, err = FCOSStreamFromString(imagePath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
dd, err := dl.NewFcosDownloader(fcosStream)
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
imageLocation, err = define.NewMachineFile(dd.Get().LocalUncompressedFile, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := DownloadImage(dd); err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
// The user has provided an alternate image which can be a file path
|
|
||||||
// or URL.
|
|
||||||
fcosStream = CustomStream
|
|
||||||
imgPath, err := dl.AcquireAlternateImage(imagePath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
imageLocation = imgPath
|
|
||||||
}
|
|
||||||
return imageLocation, fcosStream, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: GetLock
|
|
||||||
func GetLock(name string, vmtype define.VMType) (*lockfile.LockFile, error) {
|
|
||||||
// FIXME: there's a painful amount of `GetConfDir` calls scattered
|
|
||||||
// across the code base. This should be done once and stored
|
|
||||||
// somewhere instead.
|
|
||||||
vmConfigDir, err := GetConfDir(vmtype)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
lockPath := filepath.Join(vmConfigDir, name+".lock")
|
|
||||||
lock, err := lockfile.GetLockFile(lockPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("creating lockfile for VM: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return lock, nil
|
|
||||||
}
|
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
const (
|
const (
|
||||||
// Used for testing the latest podman in fcos
|
// Used for testing the latest podman in fcos
|
||||||
// special builds
|
// special builds
|
||||||
podmanTesting = "podman-testing"
|
|
||||||
PodmanTestingHost = "fedorapeople.org"
|
PodmanTestingHost = "fedorapeople.org"
|
||||||
PodmanTestingURL = "groups/podman/testing"
|
PodmanTestingURL = "groups/podman/testing"
|
||||||
)
|
)
|
||||||
@ -202,8 +201,6 @@ const (
|
|||||||
Stable
|
Stable
|
||||||
// Podman-Testing
|
// Podman-Testing
|
||||||
PodmanTesting
|
PodmanTesting
|
||||||
// Unknown
|
|
||||||
UnknownStream
|
|
||||||
// Custom
|
// Custom
|
||||||
CustomStream
|
CustomStream
|
||||||
)
|
)
|
||||||
@ -223,22 +220,7 @@ func (st FCOSStream) String() string {
|
|||||||
return "custom"
|
return "custom"
|
||||||
}
|
}
|
||||||
|
|
||||||
func FCOSStreamFromString(s string) (FCOSStream, error) {
|
// TODO can be removed when WSL is refactored into podman 5
|
||||||
switch s {
|
|
||||||
case Testing.String():
|
|
||||||
return Testing, nil
|
|
||||||
case Next.String():
|
|
||||||
return Next, nil
|
|
||||||
case PodmanTesting.String():
|
|
||||||
return PodmanTesting, nil
|
|
||||||
case Stable.String():
|
|
||||||
return Stable, nil
|
|
||||||
case CustomStream.String():
|
|
||||||
return CustomStream, nil
|
|
||||||
}
|
|
||||||
return UnknownStream, fmt.Errorf("unknown fcos stream: %s", s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsValidFCOSStreamString(s string) bool {
|
func IsValidFCOSStreamString(s string) bool {
|
||||||
switch s {
|
switch s {
|
||||||
case Testing.String():
|
case Testing.String():
|
||||||
|
Reference in New Issue
Block a user