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/api/handlers"
|
||||||
"github.com/containers/podman/v4/pkg/bindings"
|
"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"
|
"github.com/containers/podman/v4/pkg/errorhandling"
|
||||||
jsoniter "github.com/json-iterator/go"
|
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 (
|
var (
|
||||||
pcr entities.PodCreateReport
|
pcr entitiesTypes.PodCreateReport
|
||||||
)
|
)
|
||||||
if spec == nil {
|
if spec == nil {
|
||||||
spec = new(entities.PodSpec)
|
spec = new(entitiesTypes.PodSpec)
|
||||||
}
|
}
|
||||||
conn, err := bindings.GetClient(ctx)
|
conn, err := bindings.GetClient(ctx)
|
||||||
if err != nil {
|
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.
|
// 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 (
|
var (
|
||||||
report entities.PodInspectReport
|
report entitiesTypes.PodInspectReport
|
||||||
)
|
)
|
||||||
if options == nil {
|
if options == nil {
|
||||||
options = new(InspectOptions)
|
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
|
// Kill sends a SIGTERM to all the containers in a pod. The optional signal parameter
|
||||||
// can be used to override SIGTERM.
|
// 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 (
|
var (
|
||||||
report entities.PodKillReport
|
report entitiesTypes.PodKillReport
|
||||||
)
|
)
|
||||||
if options == nil {
|
if options == nil {
|
||||||
options = new(KillOptions)
|
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.
|
// Pause pauses all running containers in a given pod.
|
||||||
func Pause(ctx context.Context, nameOrID string, options *PauseOptions) (*entities.PodPauseReport, error) {
|
func Pause(ctx context.Context, nameOrID string, options *PauseOptions) (*entitiesTypes.PodPauseReport, error) {
|
||||||
var report entities.PodPauseReport
|
var report entitiesTypes.PodPauseReport
|
||||||
if options == nil {
|
if options == nil {
|
||||||
options = new(PauseOptions)
|
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.
|
// Prune by default removes all non-running pods in local storage.
|
||||||
// And with force set true removes all pods.
|
// And with force set true removes all pods.
|
||||||
func Prune(ctx context.Context, options *PruneOptions) ([]*entities.PodPruneReport, error) {
|
func Prune(ctx context.Context, options *PruneOptions) ([]*entitiesTypes.PodPruneReport, error) {
|
||||||
var reports []*entities.PodPruneReport
|
var reports []*entitiesTypes.PodPruneReport
|
||||||
if options == nil {
|
if options == nil {
|
||||||
options = new(PruneOptions)
|
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
|
// List returns all pods in local storage. The optional filters parameter can
|
||||||
// be used to refine which pods should be listed.
|
// 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 (
|
var (
|
||||||
podsReports []*entities.ListPodsReport
|
podsReports []*entitiesTypes.ListPodsReport
|
||||||
)
|
)
|
||||||
if options == nil {
|
if options == nil {
|
||||||
options = new(ListOptions)
|
options = new(ListOptions)
|
||||||
@ -169,8 +169,8 @@ func List(ctx context.Context, options *ListOptions) ([]*entities.ListPodsReport
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Restart restarts all containers in a pod.
|
// Restart restarts all containers in a pod.
|
||||||
func Restart(ctx context.Context, nameOrID string, options *RestartOptions) (*entities.PodRestartReport, error) {
|
func Restart(ctx context.Context, nameOrID string, options *RestartOptions) (*entitiesTypes.PodRestartReport, error) {
|
||||||
var report entities.PodRestartReport
|
var report entitiesTypes.PodRestartReport
|
||||||
if options == nil {
|
if options == nil {
|
||||||
options = new(RestartOptions)
|
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
|
// Remove deletes a Pod from local storage. The optional force parameter denotes
|
||||||
// that the Pod can be removed even if in a running state.
|
// that the Pod can be removed even if in a running state.
|
||||||
func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) (*entities.PodRmReport, error) {
|
func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) (*entitiesTypes.PodRmReport, error) {
|
||||||
var report entities.PodRmReport
|
var report entitiesTypes.PodRmReport
|
||||||
if options == nil {
|
if options == nil {
|
||||||
options = new(RemoveOptions)
|
options = new(RemoveOptions)
|
||||||
}
|
}
|
||||||
@ -213,8 +213,8 @@ func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) (*enti
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start starts all containers in a pod.
|
// Start starts all containers in a pod.
|
||||||
func Start(ctx context.Context, nameOrID string, options *StartOptions) (*entities.PodStartReport, error) {
|
func Start(ctx context.Context, nameOrID string, options *StartOptions) (*entitiesTypes.PodStartReport, error) {
|
||||||
var report entities.PodStartReport
|
var report entitiesTypes.PodStartReport
|
||||||
if options == nil {
|
if options == nil {
|
||||||
options = new(StartOptions)
|
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
|
// Stop stops all containers in a Pod. The optional timeout parameter can be
|
||||||
// used to override the timeout before the container is killed.
|
// used to override the timeout before the container is killed.
|
||||||
func Stop(ctx context.Context, nameOrID string, options *StopOptions) (*entities.PodStopReport, error) {
|
func Stop(ctx context.Context, nameOrID string, options *StopOptions) (*entitiesTypes.PodStopReport, error) {
|
||||||
var report entities.PodStopReport
|
var report entitiesTypes.PodStopReport
|
||||||
if options == nil {
|
if options == nil {
|
||||||
options = new(StopOptions)
|
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.
|
// 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 {
|
if options == nil {
|
||||||
options = new(UnpauseOptions)
|
options = new(UnpauseOptions)
|
||||||
}
|
}
|
||||||
_ = options
|
_ = options
|
||||||
var report entities.PodUnpauseReport
|
var report entitiesTypes.PodUnpauseReport
|
||||||
conn, err := bindings.GetClient(ctx)
|
conn, err := bindings.GetClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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.
|
// 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 {
|
if options == nil {
|
||||||
options = new(StatsOptions)
|
options = new(StatsOptions)
|
||||||
}
|
}
|
||||||
@ -338,7 +338,7 @@ func Stats(ctx context.Context, namesOrIDs []string, options *StatsOptions) ([]*
|
|||||||
params.Add("namesOrIDs", i)
|
params.Add("namesOrIDs", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
var reports []*entities.PodStatsReport
|
var reports []*entitiesTypes.PodStatsReport
|
||||||
response, err := conn.DoRequest(ctx, nil, http.MethodGet, "/pods/stats", params, nil)
|
response, err := conn.DoRequest(ctx, nil, http.MethodGet, "/pods/stats", params, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -3,7 +3,6 @@ package entities
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
commonFlag "github.com/containers/common/pkg/flag"
|
commonFlag "github.com/containers/common/pkg/flag"
|
||||||
"github.com/containers/podman/v4/libpod/define"
|
"github.com/containers/podman/v4/libpod/define"
|
||||||
@ -19,31 +18,11 @@ type PodKillOptions struct {
|
|||||||
Signal string
|
Signal string
|
||||||
}
|
}
|
||||||
|
|
||||||
type PodKillReport struct {
|
type PodKillReport = types.PodKillReport
|
||||||
Errs []error
|
|
||||||
Id string //nolint:revive,stylecheck
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListPodsReport struct {
|
type ListPodsReport = types.ListPodsReport
|
||||||
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 {
|
type ListPodContainer = types.ListPodContainer
|
||||||
Id string //nolint:revive,stylecheck
|
|
||||||
Names string
|
|
||||||
Status string
|
|
||||||
RestartCount uint
|
|
||||||
}
|
|
||||||
|
|
||||||
type PodPauseOptions struct {
|
type PodPauseOptions struct {
|
||||||
All bool
|
All bool
|
||||||
@ -91,11 +70,7 @@ type PodRmOptions struct {
|
|||||||
|
|
||||||
type PodRmReport = types.PodRmReport
|
type PodRmReport = types.PodRmReport
|
||||||
|
|
||||||
// PddSpec is an abstracted version of PodSpecGen designed to eventually accept options
|
type PodSpec = types.PodSpec
|
||||||
// not meant to be in a specgen
|
|
||||||
type PodSpec struct {
|
|
||||||
PodSpecGen specgen.PodSpecGenerator
|
|
||||||
}
|
|
||||||
|
|
||||||
// PodCreateOptions provides all possible options for creating a pod and its infra container.
|
// 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.
|
// 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
|
Sort string
|
||||||
}
|
}
|
||||||
|
|
||||||
type PodInspectReport struct {
|
type PodInspectReport = types.PodInspectReport
|
||||||
*define.InspectPodData
|
|
||||||
}
|
|
||||||
|
|
||||||
// PodStatsOptions are options for the pod stats command.
|
// PodStatsOptions are options for the pod stats command.
|
||||||
type PodStatsOptions struct {
|
type PodStatsOptions struct {
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/containers/podman/v4/libpod/define"
|
||||||
|
"github.com/containers/podman/v4/pkg/specgen"
|
||||||
|
)
|
||||||
|
|
||||||
type PodPruneReport struct {
|
type PodPruneReport struct {
|
||||||
Err error
|
Err error
|
||||||
Id string //nolint:revive,stylecheck
|
Id string //nolint:revive,stylecheck
|
||||||
@ -73,3 +80,39 @@ type PodStatsReport struct {
|
|||||||
// example: elastic_pascal
|
// example: elastic_pascal
|
||||||
Name string
|
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