Skip to content

Commit

Permalink
Merge pull request #21735 from jakecorrenti/inspect-conn-vals
Browse files Browse the repository at this point in the history
machine: Add `ConnectionInfo` to inspect
  • Loading branch information
openshift-merge-bot[bot] authored Feb 22, 2024
2 parents 70091d5 + 09095ac commit 59b6f48
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
16 changes: 11 additions & 5 deletions cmd/podman/machine/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion docs/source/markdown/podman-machine-inspect.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/e2e/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 7 additions & 7 deletions pkg/machine/e2e/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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}}")
Expand Down
29 changes: 29 additions & 0 deletions pkg/machine/vmconfigs/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 59b6f48

Please sign in to comment.