diff --git a/cmd/podman/machine/inspect.go b/cmd/podman/machine/inspect.go index 81699268d0..a012bbddf5 100644 --- a/cmd/podman/machine/inspect.go +++ b/cmd/podman/machine/inspect.go @@ -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{ diff --git a/docs/source/markdown/podman-machine-inspect.1.md b/docs/source/markdown/podman-machine-inspect.1.md index fdf682c26a..090bf6d014 100644 --- a/docs/source/markdown/podman-machine-inspect.1.md +++ b/docs/source/markdown/podman-machine-inspect.1.md @@ -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 | diff --git a/pkg/machine/config.go b/pkg/machine/config.go index 650443e82f..f8babf30c1 100644 --- a/pkg/machine/config.go +++ b/pkg/machine/config.go @@ -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 diff --git a/pkg/machine/e2e/init_test.go b/pkg/machine/e2e/init_test.go index 83f0b5c9a9..31121d0f0e 100644 --- a/pkg/machine/e2e/init_test.go +++ b/pkg/machine/e2e/init_test.go @@ -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)) diff --git a/pkg/machine/e2e/inspect_test.go b/pkg/machine/e2e/inspect_test.go index 6aeaf6da43..c35a6dad95 100644 --- a/pkg/machine/e2e/inspect_test.go +++ b/pkg/machine/e2e/inspect_test.go @@ -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}}") diff --git a/pkg/machine/vmconfigs/machine.go b/pkg/machine/vmconfigs/machine.go index 81d7b4e9a4..b18f6c49ac 100644 --- a/pkg/machine/vmconfigs/machine.go +++ b/pkg/machine/vmconfigs/machine.go @@ -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)