diff options
Diffstat (limited to 'pkg/bindings/pods/pods.go')
-rw-r--r-- | pkg/bindings/pods/pods.go | 113 |
1 files changed, 75 insertions, 38 deletions
diff --git a/pkg/bindings/pods/pods.go b/pkg/bindings/pods/pods.go index c3f98eaab..4fcaf81f1 100644 --- a/pkg/bindings/pods/pods.go +++ b/pkg/bindings/pods/pods.go @@ -2,10 +2,8 @@ package pods import ( "context" - "errors" "net/http" "net/url" - "strconv" "strings" "github.com/containers/podman/v2/pkg/api/handlers" @@ -15,10 +13,14 @@ import ( jsoniter "github.com/json-iterator/go" ) -func CreatePodFromSpec(ctx context.Context, s *specgen.PodSpecGenerator) (*entities.PodCreateReport, error) { +func CreatePodFromSpec(ctx context.Context, s *specgen.PodSpecGenerator, options *CreateOptions) (*entities.PodCreateReport, error) { var ( pcr entities.PodCreateReport ) + if options == nil { + options = new(CreateOptions) + } + _ = options conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -49,10 +51,14 @@ func Exists(ctx context.Context, nameOrID string) (bool, error) { } // Inspect returns low-level information about the given pod. -func Inspect(ctx context.Context, nameOrID string) (*entities.PodInspectReport, error) { +func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) (*entities.PodInspectReport, error) { var ( report entities.PodInspectReport ) + if options == nil { + options = new(InspectOptions) + } + _ = options conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -66,17 +72,20 @@ func Inspect(ctx context.Context, nameOrID string) (*entities.PodInspectReport, // 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, signal *string) (*entities.PodKillReport, error) { +func Kill(ctx context.Context, nameOrID string, options *KillOptions) (*entities.PodKillReport, error) { var ( report entities.PodKillReport ) + if options == nil { + options = new(KillOptions) + } conn, err := bindings.GetClient(ctx) if err != nil { return nil, err } - params := url.Values{} - if signal != nil { - params.Set("signal", *signal) + params, err := options.ToParams() + if err != nil { + return nil, err } response, err := conn.DoRequest(nil, http.MethodPost, "/pods/%s/kill", params, nil, nameOrID) if err != nil { @@ -86,8 +95,12 @@ func Kill(ctx context.Context, nameOrID string, signal *string) (*entities.PodKi } // Pause pauses all running containers in a given pod. -func Pause(ctx context.Context, nameOrID string) (*entities.PodPauseReport, error) { +func Pause(ctx context.Context, nameOrID string, options *PauseOptions) (*entities.PodPauseReport, error) { var report entities.PodPauseReport + if options == nil { + options = new(PauseOptions) + } + _ = options conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -101,8 +114,12 @@ func Pause(ctx context.Context, nameOrID string) (*entities.PodPauseReport, erro // Prune by default removes all non-running pods in local storage. // And with force set true removes all pods. -func Prune(ctx context.Context) ([]*entities.PodPruneReport, error) { +func Prune(ctx context.Context, options *PruneOptions) ([]*entities.PodPruneReport, error) { var reports []*entities.PodPruneReport + if options == nil { + options = new(PruneOptions) + } + _ = options conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -116,21 +133,20 @@ func Prune(ctx context.Context) ([]*entities.PodPruneReport, error) { // 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, filters map[string][]string) ([]*entities.ListPodsReport, error) { +func List(ctx context.Context, options *ListOptions) ([]*entities.ListPodsReport, error) { var ( podsReports []*entities.ListPodsReport ) + if options == nil { + options = new(ListOptions) + } conn, err := bindings.GetClient(ctx) if err != nil { return nil, err } - params := url.Values{} - if filters != nil { - stringFilter, err := bindings.FiltersToString(filters) - if err != nil { - return nil, err - } - params.Set("filters", stringFilter) + params, err := options.ToParams() + if err != nil { + return nil, err } response, err := conn.DoRequest(nil, http.MethodGet, "/pods/json", params, nil) if err != nil { @@ -140,8 +156,12 @@ func List(ctx context.Context, filters map[string][]string) ([]*entities.ListPod } // Restart restarts all containers in a pod. -func Restart(ctx context.Context, nameOrID string) (*entities.PodRestartReport, error) { +func Restart(ctx context.Context, nameOrID string, options *RestartOptions) (*entities.PodRestartReport, error) { var report entities.PodRestartReport + if options == nil { + options = new(RestartOptions) + } + _ = options conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -155,15 +175,18 @@ func Restart(ctx context.Context, nameOrID string) (*entities.PodRestartReport, // Remove deletes a Pod from 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, force *bool) (*entities.PodRmReport, error) { +func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) (*entities.PodRmReport, error) { var report entities.PodRmReport + if options == nil { + options = new(RemoveOptions) + } conn, err := bindings.GetClient(ctx) if err != nil { return nil, err } - params := url.Values{} - if force != nil { - params.Set("force", strconv.FormatBool(*force)) + params, err := options.ToParams() + if err != nil { + return nil, err } response, err := conn.DoRequest(nil, http.MethodDelete, "/pods/%s", params, nil, nameOrID) if err != nil { @@ -173,8 +196,12 @@ func Remove(ctx context.Context, nameOrID string, force *bool) (*entities.PodRmR } // Start starts all containers in a pod. -func Start(ctx context.Context, nameOrID string) (*entities.PodStartReport, error) { +func Start(ctx context.Context, nameOrID string, options *StartOptions) (*entities.PodStartReport, error) { var report entities.PodStartReport + if options == nil { + options = new(StartOptions) + } + _ = options conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -192,15 +219,18 @@ func Start(ctx context.Context, nameOrID string) (*entities.PodStartReport, erro // 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, timeout *int) (*entities.PodStopReport, error) { +func Stop(ctx context.Context, nameOrID string, options *StopOptions) (*entities.PodStopReport, error) { var report entities.PodStopReport + if options == nil { + options = new(StopOptions) + } conn, err := bindings.GetClient(ctx) if err != nil { return nil, err } - params := url.Values{} - if timeout != nil { - params.Set("t", strconv.Itoa(*timeout)) + params, err := options.ToParams() + if err != nil { + return nil, err } response, err := conn.DoRequest(nil, http.MethodPost, "/pods/%s/stop", params, nil, nameOrID) if err != nil { @@ -215,15 +245,16 @@ func Stop(ctx context.Context, nameOrID string, timeout *int) (*entities.PodStop // Top gathers statistics about the running processes in a pod. The nameOrID can be a pod name // or a partial/full ID. The descriptors allow for specifying which data to collect from each process. -func Top(ctx context.Context, nameOrID string, descriptors []string) ([]string, error) { +func Top(ctx context.Context, nameOrID string, options *TopOptions) ([]string, error) { + if options == nil { + options = new(TopOptions) + } conn, err := bindings.GetClient(ctx) if err != nil { return nil, err } params := url.Values{} - - if len(descriptors) > 0 { - // flatten the slice into one string + if descriptors := options.GetDescriptors(); len(descriptors) > 0 { params.Set("ps_args", strings.Join(descriptors, ",")) } response, err := conn.DoRequest(nil, http.MethodGet, "/pods/%s/top", params, nil, nameOrID) @@ -248,7 +279,11 @@ func Top(ctx context.Context, nameOrID string, descriptors []string) ([]string, } // Unpause unpauses all paused containers in a Pod. -func Unpause(ctx context.Context, nameOrID string) (*entities.PodUnpauseReport, error) { +func Unpause(ctx context.Context, nameOrID string, options *UnpauseOptions) (*entities.PodUnpauseReport, error) { + if options == nil { + options = new(UnpauseOptions) + } + _ = options var report entities.PodUnpauseReport conn, err := bindings.GetClient(ctx) if err != nil { @@ -262,19 +297,21 @@ func Unpause(ctx context.Context, nameOrID string) (*entities.PodUnpauseReport, } // Stats display resource-usage statistics of one or more pods. -func Stats(ctx context.Context, namesOrIDs []string, options entities.PodStatsOptions) ([]*entities.PodStatsReport, error) { - if options.Latest { - return nil, errors.New("latest is not supported") +func Stats(ctx context.Context, namesOrIDs []string, options *StatsOptions) ([]*entities.PodStatsReport, error) { + if options == nil { + options = new(StatsOptions) } conn, err := bindings.GetClient(ctx) if err != nil { return nil, err } - params := url.Values{} + params, err := options.ToParams() + if err != nil { + return nil, err + } for _, i := range namesOrIDs { params.Add("namesOrIDs", i) } - params.Set("all", strconv.FormatBool(options.All)) var reports []*entities.PodStatsReport response, err := conn.DoRequest(nil, http.MethodGet, "/pods/stats", params, nil) |