Skip to content

Commit 59b6f48

Browse files
Merge pull request #21735 from jakecorrenti/inspect-conn-vals
machine: Add `ConnectionInfo` to inspect
2 parents 70091d5 + 09095ac commit 59b6f48

6 files changed

Lines changed: 50 additions & 15 deletions

File tree

cmd/podman/machine/inspect.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,18 @@ func inspect(cmd *cobra.Command, args []string) error {
7272
return err
7373
}
7474

75+
podmanSocket, podmanPipe, err := mc.ConnectionInfo(provider.VMType())
76+
if err != nil {
77+
return err
78+
}
79+
7580
ii := machine.InspectInfo{
76-
// TODO I dont think this is useful
77-
ConfigPath: *dirs.ConfigDir,
78-
// TODO Fill this out
79-
ConnectionInfo: machine.ConnectionConfig{},
80-
Created: mc.Created,
81+
ConfigDir: *dirs.ConfigDir,
82+
ConnectionInfo: machine.ConnectionConfig{
83+
PodmanSocket: podmanSocket,
84+
PodmanPipe: podmanPipe,
85+
},
86+
Created: mc.Created,
8187
// TODO This is no longer applicable; we dont care about the provenance
8288
// of the image
8389
Image: machine.ImageConfig{

docs/source/markdown/podman-machine-inspect.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Print results with a Go template.
2525

2626
| **Placeholder** | **Description** |
2727
| ------------------- | --------------------------------------------------------------------- |
28-
| .ConfigPath ... | Machine configuration file location |
28+
| .ConfigDir ... | Machine configuration directory location |
2929
| .ConnectionInfo ... | Machine connection information |
3030
| .Created ... | Machine creation time (string, ISO3601) |
3131
| .Image ... | Machine image config |

pkg/machine/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type DistributionDownload interface {
107107
CleanCache() error
108108
}
109109
type InspectInfo struct {
110-
ConfigPath define.VMFile
110+
ConfigDir define.VMFile
111111
ConnectionInfo ConnectionConfig
112112
Created time.Time
113113
Image ImageConfig

pkg/machine/e2e/init_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ var _ = Describe("podman machine init", func() {
282282
Expect(session).To(Exit(0))
283283

284284
inspect := new(inspectMachine)
285-
inspect = inspect.withFormat("{{.ConfigPath.Path}}")
285+
inspect = inspect.withFormat("{{.ConfigDir.Path}}")
286286
inspectSession, err := mb.setCmd(inspect).run()
287287
Expect(err).ToNot(HaveOccurred())
288288
cfgpth := filepath.Join(inspectSession.outputToString(), fmt.Sprintf("%s.json", name))

pkg/machine/e2e/inspect_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package e2e_test
22

33
import (
44
"github.com/containers/podman/v5/pkg/machine"
5+
"github.com/containers/podman/v5/pkg/machine/define"
56
jsoniter "github.com/json-iterator/go"
67

78
. "github.com/onsi/ginkgo/v2"
@@ -66,13 +67,12 @@ var _ = Describe("podman inspect stop", func() {
6667
err = jsoniter.Unmarshal(inspectSession.Bytes(), &inspectInfo)
6768
Expect(err).ToNot(HaveOccurred())
6869

69-
// TODO Re-enable this for tests once inspect is fixed
70-
// switch testProvider.VMType() {
71-
// case define.WSLVirt:
72-
// Expect(inspectInfo[0].ConnectionInfo.PodmanPipe.GetPath()).To(ContainSubstring("podman-"))
73-
// default:
74-
// Expect(inspectInfo[0].ConnectionInfo.PodmanSocket.GetPath()).To(HaveSuffix("podman.sock"))
75-
// }
70+
switch testProvider.VMType() {
71+
case define.WSLVirt:
72+
Expect(inspectInfo[0].ConnectionInfo.PodmanPipe.GetPath()).To(ContainSubstring("podman-"))
73+
default:
74+
Expect(inspectInfo[0].ConnectionInfo.PodmanSocket.GetPath()).To(HaveSuffix("podman.sock"))
75+
}
7676

7777
inspect := new(inspectMachine)
7878
inspect = inspect.withFormat("{{.Name}}")

pkg/machine/vmconfigs/machine.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,35 @@ func (mc *MachineConfig) IsFirstBoot() (bool, error) {
297297
return mc.LastUp == never, nil
298298
}
299299

300+
func (mc *MachineConfig) ConnectionInfo(vmtype define.VMType) (*define.VMFile, *define.VMFile, error) {
301+
var (
302+
socket *define.VMFile
303+
pipe *define.VMFile
304+
)
305+
306+
if vmtype == define.HyperVVirt || vmtype == define.WSLVirt {
307+
pipeName := mc.Name
308+
if !strings.HasPrefix(pipeName, "podman") {
309+
pipeName = "podman-" + pipeName
310+
}
311+
pipe = &define.VMFile{Path: `\\.\pipe\` + pipeName}
312+
}
313+
314+
if vmtype == define.WSLVirt {
315+
return nil, pipe, nil
316+
}
317+
318+
sockName := "podman.sock"
319+
dataDir, err := mc.DataDir()
320+
if err != nil {
321+
logrus.Errorf("Resolving data dir: %s", err.Error())
322+
return nil, nil, err
323+
}
324+
325+
socket, err = define.NewMachineFile(filepath.Join(dataDir.Path, sockName), &sockName)
326+
return socket, pipe, err
327+
}
328+
300329
// LoadMachineByName returns a machine config based on the vm name and provider
301330
func LoadMachineByName(name string, dirs *define.MachineDirs) (*MachineConfig, error) {
302331
fullPath, err := dirs.ConfigDir.AppendToNewVMFile(name+".json", nil)

0 commit comments

Comments
 (0)