mirror of
https://github.com/containers/podman.git
synced 2025-06-21 17:38:12 +08:00
Merge pull request #2387 from baude/remotepodrm
enable podman-remote pod rm
This commit is contained in:
7
API.md
7
API.md
@ -51,6 +51,8 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in
|
|||||||
|
|
||||||
[func GetPodStats(name: string) string, ContainerStats](#GetPodStats)
|
[func GetPodStats(name: string) string, ContainerStats](#GetPodStats)
|
||||||
|
|
||||||
|
[func GetPodsByContext(all: bool, latest: bool, args: []string) []string](#GetPodsByContext)
|
||||||
|
|
||||||
[func GetVersion() string, string, string, string, string, int](#GetVersion)
|
[func GetVersion() string, string, string, string, string, int](#GetVersion)
|
||||||
|
|
||||||
[func GetVolumes(args: []string, all: bool) Volume](#GetVolumes)
|
[func GetVolumes(args: []string, all: bool) Volume](#GetVolumes)
|
||||||
@ -529,6 +531,11 @@ $ varlink call unix:/run/podman/io.podman/io.podman.GetPodStats '{"name": "7f62b
|
|||||||
"pod": "7f62b508b6f12b11d8fe02e0db4de6b9e43a7d7699b33a4fc0d574f6e82b4ebd"
|
"pod": "7f62b508b6f12b11d8fe02e0db4de6b9e43a7d7699b33a4fc0d574f6e82b4ebd"
|
||||||
}
|
}
|
||||||
~~~
|
~~~
|
||||||
|
### <a name="GetPodsByContext"></a>func GetPodsByContext
|
||||||
|
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
|
||||||
|
|
||||||
|
method GetPodsByContext(all: [bool](https://godoc.org/builtin#bool), latest: [bool](https://godoc.org/builtin#bool), args: [[]string](#[]string)) [[]string](#[]string)</div>
|
||||||
|
|
||||||
### <a name="GetVersion"></a>func GetVersion
|
### <a name="GetVersion"></a>func GetVersion
|
||||||
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
|
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ func getMainCommands() []*cobra.Command {
|
|||||||
_diffCommand,
|
_diffCommand,
|
||||||
_execCommand,
|
_execCommand,
|
||||||
generateCommand.Command,
|
generateCommand.Command,
|
||||||
podCommand.Command,
|
|
||||||
_containerKubeCommand,
|
_containerKubeCommand,
|
||||||
_psCommand,
|
_psCommand,
|
||||||
_loadCommand,
|
_loadCommand,
|
||||||
@ -100,7 +99,6 @@ func getPodSubCommands() []*cobra.Command {
|
|||||||
_podPauseCommand,
|
_podPauseCommand,
|
||||||
_podPsCommand,
|
_podPsCommand,
|
||||||
_podRestartCommand,
|
_podRestartCommand,
|
||||||
_podRmCommand,
|
|
||||||
_podStartCommand,
|
_podStartCommand,
|
||||||
_podStatsCommand,
|
_podStatsCommand,
|
||||||
_podStopCommand,
|
_podStopCommand,
|
||||||
|
@ -45,6 +45,7 @@ var mainCommands = []*cobra.Command{
|
|||||||
_infoCommand,
|
_infoCommand,
|
||||||
_inspectCommand,
|
_inspectCommand,
|
||||||
_killCommand,
|
_killCommand,
|
||||||
|
podCommand.Command,
|
||||||
_pullCommand,
|
_pullCommand,
|
||||||
_pushCommand,
|
_pushCommand,
|
||||||
_rmiCommand,
|
_rmiCommand,
|
||||||
|
@ -18,7 +18,13 @@ var podCommand = cliconfig.PodmanCommand{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//podSubCommands are implemented both in local and remote clients
|
||||||
|
var podSubCommands = []*cobra.Command{
|
||||||
|
_podRmCommand,
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
podCommand.AddCommand(podSubCommands...)
|
||||||
podCommand.AddCommand(getPodSubCommands()...)
|
podCommand.AddCommand(getPodSubCommands()...)
|
||||||
podCommand.SetUsageTemplate(UsageTemplate())
|
podCommand.SetUsageTemplate(UsageTemplate())
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/containers/libpod/libpod/adapter"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -42,36 +42,30 @@ func init() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// saveCmd saves the image to either docker-archive or oci
|
// podRmCmd deletes pods
|
||||||
func podRmCmd(c *cliconfig.PodRmValues) error {
|
func podRmCmd(c *cliconfig.PodRmValues) error {
|
||||||
if err := checkMutuallyExclusiveFlags(&c.PodmanCommand); err != nil {
|
if err := checkMutuallyExclusiveFlags(&c.PodmanCommand); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "could not get runtime")
|
return errors.Wrapf(err, "could not get runtime")
|
||||||
}
|
}
|
||||||
defer runtime.Shutdown(false)
|
defer runtime.Shutdown(false)
|
||||||
|
podRmIds, podRmErrors := runtime.RemovePods(getContext(), c)
|
||||||
ctx := getContext()
|
for _, p := range podRmIds {
|
||||||
force := c.Force
|
fmt.Println(p)
|
||||||
|
|
||||||
// getPodsFromContext returns an error when a requested pod
|
|
||||||
// isn't found. The only fatal error scenerio is when there are no pods
|
|
||||||
// in which case the following loop will be skipped.
|
|
||||||
pods, lastError := getPodsFromContext(&c.PodmanCommand, runtime)
|
|
||||||
|
|
||||||
for _, pod := range pods {
|
|
||||||
err = runtime.RemovePod(ctx, pod, force, force)
|
|
||||||
if err != nil {
|
|
||||||
if lastError != nil {
|
|
||||||
logrus.Errorf("%q", lastError)
|
|
||||||
}
|
}
|
||||||
lastError = errors.Wrapf(err, "failed to delete pod %v", pod.ID())
|
if len(podRmErrors) == 0 {
|
||||||
} else {
|
return nil
|
||||||
fmt.Println(pod.ID())
|
|
||||||
}
|
}
|
||||||
|
// Grab the last error
|
||||||
|
lastError := podRmErrors[len(podRmErrors)-1]
|
||||||
|
// Remove the last error from the error slice
|
||||||
|
podRmErrors = podRmErrors[:len(podRmErrors)-1]
|
||||||
|
|
||||||
|
for _, err := range podRmErrors {
|
||||||
|
logrus.Errorf("%q", err)
|
||||||
}
|
}
|
||||||
return lastError
|
return lastError
|
||||||
}
|
}
|
||||||
|
@ -1102,6 +1102,8 @@ method VolumesPrune() -> (prunedNames: []string, prunedErrors: []string)
|
|||||||
|
|
||||||
method ImageSave(options: ImageSaveOptions) -> (reply: MoreResponse)
|
method ImageSave(options: ImageSaveOptions) -> (reply: MoreResponse)
|
||||||
|
|
||||||
|
method GetPodsByContext(all: bool, latest: bool, args: []string) -> (pods: []string)
|
||||||
|
|
||||||
# ImageNotFound means the image could not be found by the provided name or ID in local storage.
|
# ImageNotFound means the image could not be found by the provided name or ID in local storage.
|
||||||
error ImageNotFound (id: string)
|
error ImageNotFound (id: string)
|
||||||
|
|
||||||
|
38
libpod/adapter/pods.go
Normal file
38
libpod/adapter/pods.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// +build !remoteclient
|
||||||
|
|
||||||
|
package adapter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/containers/libpod/libpod/adapter/shortcuts"
|
||||||
|
|
||||||
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
|
"github.com/containers/libpod/libpod"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Pod ...
|
||||||
|
type Pod struct {
|
||||||
|
*libpod.Pod
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovePods ...
|
||||||
|
func (r *LocalRuntime) RemovePods(ctx context.Context, cli *cliconfig.PodRmValues) ([]string, []error) {
|
||||||
|
var (
|
||||||
|
errs []error
|
||||||
|
podids []string
|
||||||
|
)
|
||||||
|
pods, err := shortcuts.GetPodsByContext(cli.All, cli.Latest, cli.InputArgs, r.Runtime)
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
return nil, errs
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range pods {
|
||||||
|
if err := r.RemovePod(ctx, p, cli.Force, cli.Force); err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
} else {
|
||||||
|
podids = append(podids, p.ID())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return podids, errs
|
||||||
|
}
|
44
libpod/adapter/pods_remote.go
Normal file
44
libpod/adapter/pods_remote.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// +build remoteclient
|
||||||
|
|
||||||
|
package adapter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
|
"github.com/containers/libpod/cmd/podman/varlink"
|
||||||
|
"github.com/containers/libpod/libpod"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Pod ...
|
||||||
|
type Pod struct {
|
||||||
|
remotepod
|
||||||
|
}
|
||||||
|
|
||||||
|
type remotepod struct {
|
||||||
|
config *libpod.PodConfig
|
||||||
|
state *libpod.PodInspectState
|
||||||
|
Runtime *LocalRuntime
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LocalRuntime) RemovePods(ctx context.Context, cli *cliconfig.PodRmValues) ([]string, []error) {
|
||||||
|
var (
|
||||||
|
rmErrs []error
|
||||||
|
rmPods []string
|
||||||
|
)
|
||||||
|
podIDs, err := iopodman.GetPodsByContext().Call(r.Conn, cli.All, cli.Latest, cli.InputArgs)
|
||||||
|
if err != nil {
|
||||||
|
rmErrs = append(rmErrs, err)
|
||||||
|
return nil, rmErrs
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range podIDs {
|
||||||
|
reply, err := iopodman.RemovePod().Call(r.Conn, p, cli.Force)
|
||||||
|
if err != nil {
|
||||||
|
rmErrs = append(rmErrs, err)
|
||||||
|
} else {
|
||||||
|
rmPods = append(rmPods, reply)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rmPods, rmErrs
|
||||||
|
}
|
27
libpod/adapter/shortcuts/shortcuts.go
Normal file
27
libpod/adapter/shortcuts/shortcuts.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package shortcuts
|
||||||
|
|
||||||
|
import "github.com/containers/libpod/libpod"
|
||||||
|
|
||||||
|
// GetPodsByContext gets pods whether all, latest, or a slice of names/ids
|
||||||
|
func GetPodsByContext(all, latest bool, pods []string, runtime *libpod.Runtime) ([]*libpod.Pod, error) {
|
||||||
|
var outpods []*libpod.Pod
|
||||||
|
if all {
|
||||||
|
return runtime.GetAllPods()
|
||||||
|
}
|
||||||
|
if latest {
|
||||||
|
p, err := runtime.GetLatestPod()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
outpods = append(outpods, p)
|
||||||
|
return outpods, nil
|
||||||
|
}
|
||||||
|
for _, p := range pods {
|
||||||
|
pod, err := runtime.LookupPod(p)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
outpods = append(outpods, pod)
|
||||||
|
}
|
||||||
|
return outpods, nil
|
||||||
|
}
|
@ -2,6 +2,7 @@ package varlinkapi
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/containers/libpod/libpod/adapter/shortcuts"
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@ -271,3 +272,17 @@ func (i *LibpodAPI) GetPodStats(call iopodman.VarlinkCall, name string) error {
|
|||||||
}
|
}
|
||||||
return call.ReplyGetPodStats(pod.ID(), containersStats)
|
return call.ReplyGetPodStats(pod.ID(), containersStats)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPodsByContext returns a slice of pod ids based on all, latest, or a list
|
||||||
|
func (i *LibpodAPI) GetPodsByContext(call iopodman.VarlinkCall, all, latest bool, input []string) error {
|
||||||
|
var podids []string
|
||||||
|
|
||||||
|
pods, err := shortcuts.GetPodsByContext(all, latest, input, i.Runtime)
|
||||||
|
if err != nil {
|
||||||
|
return call.ReplyErrorOccurred(err.Error())
|
||||||
|
}
|
||||||
|
for _, p := range pods {
|
||||||
|
podids = append(podids, p.ID())
|
||||||
|
}
|
||||||
|
return call.ReplyGetPodsByContext(podids)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user