podman/cmd/podmanV2
OpenShift Merge Robot 8193751287
Merge pull request #5639 from vrothberg/v2-pod-top
V2 pod top
2020-03-30 13:59:37 +02:00
..
common podmanv2 pod create using podspecgen 2020-03-27 09:04:10 -05:00
containers podmanv2 commit 2020-03-28 10:11:50 -05:00
images V2 podman image prune 2020-03-26 18:32:44 -07:00
networks V2 podman command 2020-03-18 16:41:12 -07:00
parse podmanv2 add core container commands 2020-03-22 13:24:45 -05:00
pods podmanv2: implement pod top 2020-03-28 17:32:22 +01:00
registry V2 podman image rm | podman rmi [IMAGE] 2020-03-25 17:54:14 -07:00
report V2 podman images/image list 2020-03-24 16:06:01 -07:00
system V2 podman command 2020-03-18 16:41:12 -07:00
utils Combine GlobalFlags and EngineFlags into EngineOptions 2020-03-24 11:03:13 -07:00
volumes podmanv2 volumes 2020-03-24 16:03:49 -05:00
Makefile podmanv2 pod create using podspecgen 2020-03-27 09:04:10 -05:00
README.md Add guildline for writing podman V2 CLI commands 2020-03-19 11:54:27 -07:00
main.go V2 podman image rm | podman rmi [IMAGE] 2020-03-25 17:54:14 -07:00
root.go V2 podman image rm | podman rmi [IMAGE] 2020-03-25 17:54:14 -07:00

README.md

Adding a podman V2 commands

Build podman V2

$ cd $GOPATH/src/github.com/containers/libpod/cmd/podmanV2

If you wish to include the libpod library in your program,

$ go build -tags 'ABISupport' .

The --remote flag may be used to connect to the Podman service using the API. Otherwise, direct calls will be made to the Libpod library.

$ go build -tags '!ABISupport' .

The Libpod library is not linked into the executable. All calls are made via the API and --remote=False is an error condition.

Adding a new command podman manifests

$ mkdir -p $GOPATH/src/github.com/containers/libpod/cmd/podmanV2/manifests

Create the file $GOPATH/src/github.com/containers/libpod/cmd/podmanV2/manifests/manifest.go

package manifests

import (
    "github.com/containers/libpod/cmd/podmanV2/registry"
    "github.com/containers/libpod/pkg/domain/entities"
    "github.com/spf13/cobra"
)

var (
    // podman _manifests_
    manifestCmd = &cobra.Command{
        Use:               "manifest",
        Short:             "Manage manifests",
        Long:              "Manage manifests",
        Example:           "podman manifests IMAGE",
        TraverseChildren:  true,
        PersistentPreRunE: preRunE,
        RunE:              registry.SubCommandExists, // Report error if there is no sub command given
    }
)
func init() {
    // Subscribe command to podman
    registry.Commands = append(registry.Commands, registry.CliCommand{
        // _podman manifest_ will support both ABIMode and TunnelMode
        Mode:    []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
        // The definition for this command
        Command: manifestCmd,
    })
    // Setup cobra templates, sub commands will inherit
    manifestCmd.SetHelpTemplate(registry.HelpTemplate())
    manifestCmd.SetUsageTemplate(registry.UsageTemplate())
}

// preRunE populates the image engine for sub commands
func preRunE(cmd *cobra.Command, args []string) error {
    _, err := registry.NewImageEngine(cmd, args)
    return err
}

To "wire" in the manifest command, edit the file $GOPATH/src/github.com/containers/libpod/cmd/podmanV2/main.go to add:

package main

import	_ "github.com/containers/libpod/cmd/podmanV2/manifests"

Adding a new sub command podman manifests list

Create the file $GOPATH/src/github.com/containers/libpod/cmd/podmanV2/manifests/inspect.go

package manifests

import (
    "github.com/containers/libpod/cmd/podmanV2/registry"
    "github.com/containers/libpod/pkg/domain/entities"
    "github.com/spf13/cobra"
)

var (
    // podman manifests _inspect_
    inspectCmd = &cobra.Command{
        Use:     "inspect IMAGE",
        Short:   "Display manifest from image",
        Long:    "Displays the low-level information on a manifest identified by image name or ID",
        RunE:    inspect,
        Example: "podman manifest DEADBEEF",
    }
)

func init() {
    // Subscribe inspect sub command to manifest command
    registry.Commands = append(registry.Commands, registry.CliCommand{
        // _podman manifest inspect_ will support both ABIMode and TunnelMode
        Mode:    []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
        // The definition for this command
        Command: inspectCmd,
        Parent:  manifestCmd,
    })

    // This is where you would configure the cobra flags using inspectCmd.Flags()
}

// Business logic: cmd is inspectCmd, args is the positional arguments from os.Args
func inspect(cmd *cobra.Command, args []string) error {
    // Business logic using registry.ImageEngine
    // Do not pull from libpod directly use the domain objects and types
    return nil
}