forked from containers/podman
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request containers#13829 from baude/machineinspect
Introduce machine inspect
- Loading branch information
Showing
6 changed files
with
174 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//go:build amd64 || arm64 | ||
// +build amd64 arm64 | ||
|
||
package machine | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
|
||
"github.com/containers/podman/v4/cmd/podman/common" | ||
"github.com/containers/podman/v4/cmd/podman/registry" | ||
"github.com/containers/podman/v4/cmd/podman/utils" | ||
"github.com/containers/podman/v4/libpod/define" | ||
"github.com/containers/podman/v4/pkg/machine" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
inspectCmd = &cobra.Command{ | ||
Use: "inspect [options] [MACHINE...]", | ||
Short: "Inspect an existing machine", | ||
Long: "Provide details on a managed virtual machine", | ||
RunE: inspect, | ||
Example: `podman machine inspect myvm`, | ||
ValidArgsFunction: autocompleteMachine, | ||
} | ||
inspectFlag = inspectFlagType{} | ||
) | ||
|
||
type inspectFlagType struct { | ||
format string | ||
} | ||
|
||
func init() { | ||
registry.Commands = append(registry.Commands, registry.CliCommand{ | ||
Command: inspectCmd, | ||
Parent: machineCmd, | ||
}) | ||
|
||
flags := inspectCmd.Flags() | ||
formatFlagName := "format" | ||
flags.StringVar(&inspectFlag.format, formatFlagName, "", "Format volume output using JSON or a Go template") | ||
_ = inspectCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(machine.InspectInfo{})) | ||
} | ||
|
||
func inspect(cmd *cobra.Command, args []string) error { | ||
var ( | ||
errs utils.OutputErrors | ||
) | ||
if len(args) < 1 { | ||
args = append(args, defaultMachineName) | ||
} | ||
vms := make([]machine.InspectInfo, 0, len(args)) | ||
provider := getSystemDefaultProvider() | ||
for _, vmName := range args { | ||
vm, err := provider.LoadVMByName(vmName) | ||
if err != nil { | ||
errs = append(errs, err) | ||
continue | ||
} | ||
state, err := vm.State() | ||
if err != nil { | ||
errs = append(errs, err) | ||
continue | ||
} | ||
ii := machine.InspectInfo{ | ||
State: state, | ||
VM: vm, | ||
} | ||
vms = append(vms, ii) | ||
} | ||
if len(inspectFlag.format) > 0 { | ||
// need jhonce to work his template magic | ||
return define.ErrNotImplemented | ||
} | ||
if err := printJSON(vms); err != nil { | ||
logrus.Error(err) | ||
} | ||
return errs.PrintErrors() | ||
} | ||
|
||
func printJSON(data []machine.InspectInfo) error { | ||
enc := json.NewEncoder(os.Stdout) | ||
// by default, json marshallers will force utf=8 from | ||
// a string. this breaks healthchecks that use <,>, &&. | ||
enc.SetEscapeHTML(false) | ||
enc.SetIndent("", " ") | ||
return enc.Encode(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
% podman-machine-inspect(1) | ||
|
||
## NAME | ||
podman\-machine\-inspect - Inspect one or more virtual machines | ||
|
||
## SYNOPSIS | ||
**podman machine inspect** [*options] *name* ... | ||
|
||
## DESCRIPTION | ||
|
||
Inspect one or more virtual machines | ||
|
||
Obtain greater detail about Podman virtual machines. More than one virtual machine can be | ||
inspected at once. | ||
|
||
## OPTIONS | ||
#### **--format** | ||
|
||
Print results with a Go template. | ||
|
||
#### **--help** | ||
|
||
Print usage statement. | ||
|
||
## EXAMPLES | ||
|
||
``` | ||
$ podman machine inspect podman-machine-default | ||
``` | ||
|
||
## SEE ALSO | ||
**[podman(1)](podman.1.md)**, **[podman-machine(1)](podman-machine.1.md)** | ||
|
||
## HISTORY | ||
April 2022, Originally compiled by Brent Baude <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +11,19 @@ podman\-machine - Manage Podman's virtual machine | |
|
||
## SUBCOMMANDS | ||
|
||
| Command | Man Page | Description | | ||
| ------- | ------------------------------------------------------- | --------------------------------- | | ||
| init | [podman-machine-init(1)](podman-machine-init.1.md) | Initialize a new virtual machine | | ||
| list | [podman-machine-list(1)](podman-machine-list.1.md) | List virtual machines | | ||
| rm | [podman-machine-rm(1)](podman-machine-rm.1.md) | Remove a virtual machine | | ||
| set | [podman-machine-set(1)](podman-machine-set.1.md) | Sets a virtual machine setting | | ||
| ssh | [podman-machine-ssh(1)](podman-machine-ssh.1.md) | SSH into a virtual machine | | ||
| start | [podman-machine-start(1)](podman-machine-start.1.md) | Start a virtual machine | | ||
| stop | [podman-machine-stop(1)](podman-machine-stop.1.md) | Stop a virtual machine | | ||
| Command | Man Page | Description | | ||
|---------|------------------------------------------------------|-----------------------------------| | ||
| init | [podman-machine-init(1)](podman-machine-init.1.md) | Initialize a new virtual machine | | ||
| inspect | [podman-machine-inspect(1)](podman-machine-inspect.1.md) | Inspect one or more virtual machines | | ||
| list | [podman-machine-list(1)](podman-machine-list.1.md) | List virtual machines | | ||
| rm | [podman-machine-rm(1)](podman-machine-rm.1.md) | Remove a virtual machine | | ||
| set | [podman-machine-set(1)](podman-machine-set.1.md) | Sets a virtual machine setting | | ||
| ssh | [podman-machine-ssh(1)](podman-machine-ssh.1.md) | SSH into a virtual machine | | ||
| start | [podman-machine-start(1)](podman-machine-start.1.md) | Start a virtual machine | | ||
| stop | [podman-machine-stop(1)](podman-machine-stop.1.md) | Stop a virtual machine | | ||
|
||
## SEE ALSO | ||
**[podman(1)](podman.1.md)**, **[podman-machine-init(1)](podman-machine-init.1.md)**, **[podman-machine-list(1)](podman-machine-list.1.md)**, **[podman-machine-rm(1)](podman-machine-rm.1.md)**, **[podman-machine-ssh(1)](podman-machine-ssh.1.md)**, **[podman-machine-start(1)](podman-machine-start.1.md)**, **[podman-machine-stop(1)](podman-machine-stop.1.md)** | ||
**[podman(1)](podman.1.md)**, **[podman-machine-init(1)](podman-machine-init.1.md)**, **[podman-machine-list(1)](podman-machine-list.1.md)**, **[podman-machine-rm(1)](podman-machine-rm.1.md)**, **[podman-machine-ssh(1)](podman-machine-ssh.1.md)**, **[podman-machine-start(1)](podman-machine-start.1.md)**, **[podman-machine-stop(1)](podman-machine-stop.1.md)**, **[podman-machine-inspect(1)](podman-machine-inspect.1.md)** | ||
|
||
## HISTORY | ||
March 2021, Originally compiled by Ashley Cui <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters