mirror of https://github.com/containers/podman.git
Merge pull request #21735 from jakecorrenti/inspect-conn-vals
machine: Add `ConnectionInfo` to inspect
This commit is contained in:
commit
59b6f48d90
|
@ -72,12 +72,18 @@ func inspect(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
podmanSocket, podmanPipe, err := mc.ConnectionInfo(provider.VMType())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ii := machine.InspectInfo{
|
||||
// TODO I dont think this is useful
|
||||
ConfigPath: *dirs.ConfigDir,
|
||||
// TODO Fill this out
|
||||
ConnectionInfo: machine.ConnectionConfig{},
|
||||
Created: mc.Created,
|
||||
ConfigDir: *dirs.ConfigDir,
|
||||
ConnectionInfo: machine.ConnectionConfig{
|
||||
PodmanSocket: podmanSocket,
|
||||
PodmanPipe: podmanPipe,
|
||||
},
|
||||
Created: mc.Created,
|
||||
// TODO This is no longer applicable; we dont care about the provenance
|
||||
// of the image
|
||||
Image: machine.ImageConfig{
|
||||
|
|
|
@ -25,7 +25,7 @@ Print results with a Go template.
|
|||
|
||||
| **Placeholder** | **Description** |
|
||||
| ------------------- | --------------------------------------------------------------------- |
|
||||
| .ConfigPath ... | Machine configuration file location |
|
||||
| .ConfigDir ... | Machine configuration directory location |
|
||||
| .ConnectionInfo ... | Machine connection information |
|
||||
| .Created ... | Machine creation time (string, ISO3601) |
|
||||
| .Image ... | Machine image config |
|
||||
|
|
|
@ -107,7 +107,7 @@ type DistributionDownload interface {
|
|||
CleanCache() error
|
||||
}
|
||||
type InspectInfo struct {
|
||||
ConfigPath define.VMFile
|
||||
ConfigDir define.VMFile
|
||||
ConnectionInfo ConnectionConfig
|
||||
Created time.Time
|
||||
Image ImageConfig
|
||||
|
|
|
@ -282,7 +282,7 @@ var _ = Describe("podman machine init", func() {
|
|||
Expect(session).To(Exit(0))
|
||||
|
||||
inspect := new(inspectMachine)
|
||||
inspect = inspect.withFormat("{{.ConfigPath.Path}}")
|
||||
inspect = inspect.withFormat("{{.ConfigDir.Path}}")
|
||||
inspectSession, err := mb.setCmd(inspect).run()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
cfgpth := filepath.Join(inspectSession.outputToString(), fmt.Sprintf("%s.json", name))
|
||||
|
|
|
@ -2,6 +2,7 @@ package e2e_test
|
|||
|
||||
import (
|
||||
"github.com/containers/podman/v5/pkg/machine"
|
||||
"github.com/containers/podman/v5/pkg/machine/define"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
|
@ -66,13 +67,12 @@ var _ = Describe("podman inspect stop", func() {
|
|||
err = jsoniter.Unmarshal(inspectSession.Bytes(), &inspectInfo)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// TODO Re-enable this for tests once inspect is fixed
|
||||
// switch testProvider.VMType() {
|
||||
// case define.WSLVirt:
|
||||
// Expect(inspectInfo[0].ConnectionInfo.PodmanPipe.GetPath()).To(ContainSubstring("podman-"))
|
||||
// default:
|
||||
// Expect(inspectInfo[0].ConnectionInfo.PodmanSocket.GetPath()).To(HaveSuffix("podman.sock"))
|
||||
// }
|
||||
switch testProvider.VMType() {
|
||||
case define.WSLVirt:
|
||||
Expect(inspectInfo[0].ConnectionInfo.PodmanPipe.GetPath()).To(ContainSubstring("podman-"))
|
||||
default:
|
||||
Expect(inspectInfo[0].ConnectionInfo.PodmanSocket.GetPath()).To(HaveSuffix("podman.sock"))
|
||||
}
|
||||
|
||||
inspect := new(inspectMachine)
|
||||
inspect = inspect.withFormat("{{.Name}}")
|
||||
|
|
|
@ -297,6 +297,35 @@ func (mc *MachineConfig) IsFirstBoot() (bool, error) {
|
|||
return mc.LastUp == never, nil
|
||||
}
|
||||
|
||||
func (mc *MachineConfig) ConnectionInfo(vmtype define.VMType) (*define.VMFile, *define.VMFile, error) {
|
||||
var (
|
||||
socket *define.VMFile
|
||||
pipe *define.VMFile
|
||||
)
|
||||
|
||||
if vmtype == define.HyperVVirt || vmtype == define.WSLVirt {
|
||||
pipeName := mc.Name
|
||||
if !strings.HasPrefix(pipeName, "podman") {
|
||||
pipeName = "podman-" + pipeName
|
||||
}
|
||||
pipe = &define.VMFile{Path: `\\.\pipe\` + pipeName}
|
||||
}
|
||||
|
||||
if vmtype == define.WSLVirt {
|
||||
return nil, pipe, nil
|
||||
}
|
||||
|
||||
sockName := "podman.sock"
|
||||
dataDir, err := mc.DataDir()
|
||||
if err != nil {
|
||||
logrus.Errorf("Resolving data dir: %s", err.Error())
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
socket, err = define.NewMachineFile(filepath.Join(dataDir.Path, sockName), &sockName)
|
||||
return socket, pipe, err
|
||||
}
|
||||
|
||||
// LoadMachineByName returns a machine config based on the vm name and provider
|
||||
func LoadMachineByName(name string, dirs *define.MachineDirs) (*MachineConfig, error) {
|
||||
fullPath, err := dirs.ConfigDir.AppendToNewVMFile(name+".json", nil)
|
||||
|
|
Loading…
Reference in New Issue