mirror of
https://github.com/containers/podman.git
synced 2025-07-15 03:02:52 +08:00
bindings: pods uses entities/types
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -8,17 +8,17 @@ import (
|
||||
|
||||
"github.com/containers/podman/v4/pkg/api/handlers"
|
||||
"github.com/containers/podman/v4/pkg/bindings"
|
||||
"github.com/containers/podman/v4/pkg/domain/entities"
|
||||
entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types"
|
||||
"github.com/containers/podman/v4/pkg/errorhandling"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
func CreatePodFromSpec(ctx context.Context, spec *entities.PodSpec) (*entities.PodCreateReport, error) {
|
||||
func CreatePodFromSpec(ctx context.Context, spec *entitiesTypes.PodSpec) (*entitiesTypes.PodCreateReport, error) {
|
||||
var (
|
||||
pcr entities.PodCreateReport
|
||||
pcr entitiesTypes.PodCreateReport
|
||||
)
|
||||
if spec == nil {
|
||||
spec = new(entities.PodSpec)
|
||||
spec = new(entitiesTypes.PodSpec)
|
||||
}
|
||||
conn, err := bindings.GetClient(ctx)
|
||||
if err != nil {
|
||||
@ -54,9 +54,9 @@ func Exists(ctx context.Context, nameOrID string, options *ExistsOptions) (bool,
|
||||
}
|
||||
|
||||
// Inspect returns low-level information about the given pod.
|
||||
func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*entities.PodInspectReport, error) {
|
||||
func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*entitiesTypes.PodInspectReport, error) {
|
||||
var (
|
||||
report entities.PodInspectReport
|
||||
report entitiesTypes.PodInspectReport
|
||||
)
|
||||
if options == nil {
|
||||
options = new(InspectOptions)
|
||||
@ -77,9 +77,9 @@ func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*en
|
||||
|
||||
// Kill sends a SIGTERM to all the containers in a pod. The optional signal parameter
|
||||
// can be used to override SIGTERM.
|
||||
func Kill(ctx context.Context, nameOrID string, options *KillOptions) (*entities.PodKillReport, error) {
|
||||
func Kill(ctx context.Context, nameOrID string, options *KillOptions) (*entitiesTypes.PodKillReport, error) {
|
||||
var (
|
||||
report entities.PodKillReport
|
||||
report entitiesTypes.PodKillReport
|
||||
)
|
||||
if options == nil {
|
||||
options = new(KillOptions)
|
||||
@ -102,8 +102,8 @@ func Kill(ctx context.Context, nameOrID string, options *KillOptions) (*entities
|
||||
}
|
||||
|
||||
// Pause pauses all running containers in a given pod.
|
||||
func Pause(ctx context.Context, nameOrID string, options *PauseOptions) (*entities.PodPauseReport, error) {
|
||||
var report entities.PodPauseReport
|
||||
func Pause(ctx context.Context, nameOrID string, options *PauseOptions) (*entitiesTypes.PodPauseReport, error) {
|
||||
var report entitiesTypes.PodPauseReport
|
||||
if options == nil {
|
||||
options = new(PauseOptions)
|
||||
}
|
||||
@ -123,8 +123,8 @@ func Pause(ctx context.Context, nameOrID string, options *PauseOptions) (*entiti
|
||||
|
||||
// Prune by default removes all non-running pods in local storage.
|
||||
// And with force set true removes all pods.
|
||||
func Prune(ctx context.Context, options *PruneOptions) ([]*entities.PodPruneReport, error) {
|
||||
var reports []*entities.PodPruneReport
|
||||
func Prune(ctx context.Context, options *PruneOptions) ([]*entitiesTypes.PodPruneReport, error) {
|
||||
var reports []*entitiesTypes.PodPruneReport
|
||||
if options == nil {
|
||||
options = new(PruneOptions)
|
||||
}
|
||||
@ -144,9 +144,9 @@ func Prune(ctx context.Context, options *PruneOptions) ([]*entities.PodPruneRepo
|
||||
|
||||
// List returns all pods in local storage. The optional filters parameter can
|
||||
// be used to refine which pods should be listed.
|
||||
func List(ctx context.Context, options *ListOptions) ([]*entities.ListPodsReport, error) {
|
||||
func List(ctx context.Context, options *ListOptions) ([]*entitiesTypes.ListPodsReport, error) {
|
||||
var (
|
||||
podsReports []*entities.ListPodsReport
|
||||
podsReports []*entitiesTypes.ListPodsReport
|
||||
)
|
||||
if options == nil {
|
||||
options = new(ListOptions)
|
||||
@ -169,8 +169,8 @@ func List(ctx context.Context, options *ListOptions) ([]*entities.ListPodsReport
|
||||
}
|
||||
|
||||
// Restart restarts all containers in a pod.
|
||||
func Restart(ctx context.Context, nameOrID string, options *RestartOptions) (*entities.PodRestartReport, error) {
|
||||
var report entities.PodRestartReport
|
||||
func Restart(ctx context.Context, nameOrID string, options *RestartOptions) (*entitiesTypes.PodRestartReport, error) {
|
||||
var report entitiesTypes.PodRestartReport
|
||||
if options == nil {
|
||||
options = new(RestartOptions)
|
||||
}
|
||||
@ -190,8 +190,8 @@ func Restart(ctx context.Context, nameOrID string, options *RestartOptions) (*en
|
||||
|
||||
// Remove deletes a Pod from local storage. The optional force parameter denotes
|
||||
// that the Pod can be removed even if in a running state.
|
||||
func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) (*entities.PodRmReport, error) {
|
||||
var report entities.PodRmReport
|
||||
func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) (*entitiesTypes.PodRmReport, error) {
|
||||
var report entitiesTypes.PodRmReport
|
||||
if options == nil {
|
||||
options = new(RemoveOptions)
|
||||
}
|
||||
@ -213,8 +213,8 @@ func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) (*enti
|
||||
}
|
||||
|
||||
// Start starts all containers in a pod.
|
||||
func Start(ctx context.Context, nameOrID string, options *StartOptions) (*entities.PodStartReport, error) {
|
||||
var report entities.PodStartReport
|
||||
func Start(ctx context.Context, nameOrID string, options *StartOptions) (*entitiesTypes.PodStartReport, error) {
|
||||
var report entitiesTypes.PodStartReport
|
||||
if options == nil {
|
||||
options = new(StartOptions)
|
||||
}
|
||||
@ -239,8 +239,8 @@ func Start(ctx context.Context, nameOrID string, options *StartOptions) (*entiti
|
||||
|
||||
// Stop stops all containers in a Pod. The optional timeout parameter can be
|
||||
// used to override the timeout before the container is killed.
|
||||
func Stop(ctx context.Context, nameOrID string, options *StopOptions) (*entities.PodStopReport, error) {
|
||||
var report entities.PodStopReport
|
||||
func Stop(ctx context.Context, nameOrID string, options *StopOptions) (*entitiesTypes.PodStopReport, error) {
|
||||
var report entitiesTypes.PodStopReport
|
||||
if options == nil {
|
||||
options = new(StopOptions)
|
||||
}
|
||||
@ -302,12 +302,12 @@ func Top(ctx context.Context, nameOrID string, options *TopOptions) ([]string, e
|
||||
}
|
||||
|
||||
// Unpause unpauses all paused containers in a Pod.
|
||||
func Unpause(ctx context.Context, nameOrID string, options *UnpauseOptions) (*entities.PodUnpauseReport, error) {
|
||||
func Unpause(ctx context.Context, nameOrID string, options *UnpauseOptions) (*entitiesTypes.PodUnpauseReport, error) {
|
||||
if options == nil {
|
||||
options = new(UnpauseOptions)
|
||||
}
|
||||
_ = options
|
||||
var report entities.PodUnpauseReport
|
||||
var report entitiesTypes.PodUnpauseReport
|
||||
conn, err := bindings.GetClient(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -322,7 +322,7 @@ func Unpause(ctx context.Context, nameOrID string, options *UnpauseOptions) (*en
|
||||
}
|
||||
|
||||
// Stats display resource-usage statistics of one or more pods.
|
||||
func Stats(ctx context.Context, namesOrIDs []string, options *StatsOptions) ([]*entities.PodStatsReport, error) {
|
||||
func Stats(ctx context.Context, namesOrIDs []string, options *StatsOptions) ([]*entitiesTypes.PodStatsReport, error) {
|
||||
if options == nil {
|
||||
options = new(StatsOptions)
|
||||
}
|
||||
@ -338,7 +338,7 @@ func Stats(ctx context.Context, namesOrIDs []string, options *StatsOptions) ([]*
|
||||
params.Add("namesOrIDs", i)
|
||||
}
|
||||
|
||||
var reports []*entities.PodStatsReport
|
||||
var reports []*entitiesTypes.PodStatsReport
|
||||
response, err := conn.DoRequest(ctx, nil, http.MethodGet, "/pods/stats", params, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -3,7 +3,6 @@ package entities
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
commonFlag "github.com/containers/common/pkg/flag"
|
||||
"github.com/containers/podman/v4/libpod/define"
|
||||
@ -19,31 +18,11 @@ type PodKillOptions struct {
|
||||
Signal string
|
||||
}
|
||||
|
||||
type PodKillReport struct {
|
||||
Errs []error
|
||||
Id string //nolint:revive,stylecheck
|
||||
}
|
||||
type PodKillReport = types.PodKillReport
|
||||
|
||||
type ListPodsReport struct {
|
||||
Cgroup string
|
||||
Containers []*ListPodContainer
|
||||
Created time.Time
|
||||
Id string //nolint:revive,stylecheck
|
||||
InfraId string //nolint:revive,stylecheck
|
||||
Name string
|
||||
Namespace string
|
||||
// Network names connected to infra container
|
||||
Networks []string
|
||||
Status string
|
||||
Labels map[string]string
|
||||
}
|
||||
type ListPodsReport = types.ListPodsReport
|
||||
|
||||
type ListPodContainer struct {
|
||||
Id string //nolint:revive,stylecheck
|
||||
Names string
|
||||
Status string
|
||||
RestartCount uint
|
||||
}
|
||||
type ListPodContainer = types.ListPodContainer
|
||||
|
||||
type PodPauseOptions struct {
|
||||
All bool
|
||||
@ -91,11 +70,7 @@ type PodRmOptions struct {
|
||||
|
||||
type PodRmReport = types.PodRmReport
|
||||
|
||||
// PddSpec is an abstracted version of PodSpecGen designed to eventually accept options
|
||||
// not meant to be in a specgen
|
||||
type PodSpec struct {
|
||||
PodSpecGen specgen.PodSpecGenerator
|
||||
}
|
||||
type PodSpec = types.PodSpec
|
||||
|
||||
// PodCreateOptions provides all possible options for creating a pod and its infra container.
|
||||
// The JSON tags below are made to match the respective field in ContainerCreateOptions for the purpose of mapping.
|
||||
@ -447,9 +422,7 @@ type PodPSOptions struct {
|
||||
Sort string
|
||||
}
|
||||
|
||||
type PodInspectReport struct {
|
||||
*define.InspectPodData
|
||||
}
|
||||
type PodInspectReport = types.PodInspectReport
|
||||
|
||||
// PodStatsOptions are options for the pod stats command.
|
||||
type PodStatsOptions struct {
|
||||
|
@ -1,5 +1,12 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/containers/podman/v4/libpod/define"
|
||||
"github.com/containers/podman/v4/pkg/specgen"
|
||||
)
|
||||
|
||||
type PodPruneReport struct {
|
||||
Err error
|
||||
Id string //nolint:revive,stylecheck
|
||||
@ -73,3 +80,39 @@ type PodStatsReport struct {
|
||||
// example: elastic_pascal
|
||||
Name string
|
||||
}
|
||||
|
||||
// PodSpec is an abstracted version of PodSpecGen designed to eventually accept options
|
||||
// not meant to be in a specgen
|
||||
type PodSpec struct {
|
||||
PodSpecGen specgen.PodSpecGenerator
|
||||
}
|
||||
|
||||
type PodInspectReport struct {
|
||||
*define.InspectPodData
|
||||
}
|
||||
|
||||
type PodKillReport struct {
|
||||
Errs []error
|
||||
Id string //nolint:revive,stylecheck
|
||||
}
|
||||
|
||||
type ListPodsReport struct {
|
||||
Cgroup string
|
||||
Containers []*ListPodContainer
|
||||
Created time.Time
|
||||
Id string //nolint:revive,stylecheck
|
||||
InfraId string //nolint:revive,stylecheck
|
||||
Name string
|
||||
Namespace string
|
||||
// Network names connected to infra container
|
||||
Networks []string
|
||||
Status string
|
||||
Labels map[string]string
|
||||
}
|
||||
|
||||
type ListPodContainer struct {
|
||||
Id string //nolint:revive,stylecheck
|
||||
Names string
|
||||
Status string
|
||||
RestartCount uint
|
||||
}
|
||||
|
Reference in New Issue
Block a user