mirror of
https://github.com/containers/podman.git
synced 2025-06-27 21:50:18 +08:00
v2 api: top improvements
* Use `pkg/adapter` to increase code reuse and reduce code redundancy. * Extend swagger docs to mention AIX descriptors. * Document the libpod endpoint which shares the same handler. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
@ -927,9 +927,7 @@ func (r *LocalRuntime) Top(cli *cliconfig.TopValues) ([]string, error) {
|
|||||||
|
|
||||||
output, err = r.execPS(container, descriptors)
|
output, err = r.execPS(container, descriptors)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Note: return psgoErr to guide users into using the AIX descriptors
|
return nil, errors.Wrapf(err, "error executing ps(1) in the container")
|
||||||
// instead of using ps(1).
|
|
||||||
return nil, psgoErr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trick: filter the ps command from the output instead of
|
// Trick: filter the ps command from the output instead of
|
||||||
@ -956,10 +954,8 @@ func (r *LocalRuntime) execPS(c *libpod.Container, args []string) ([]string, err
|
|||||||
streams := new(libpod.AttachStreams)
|
streams := new(libpod.AttachStreams)
|
||||||
streams.OutputStream = wPipe
|
streams.OutputStream = wPipe
|
||||||
streams.ErrorStream = wPipe
|
streams.ErrorStream = wPipe
|
||||||
streams.InputStream = bufio.NewReader(os.Stdin)
|
|
||||||
streams.AttachOutput = true
|
streams.AttachOutput = true
|
||||||
streams.AttachError = true
|
streams.AttachError = true
|
||||||
streams.AttachInput = true
|
|
||||||
|
|
||||||
psOutput := []string{}
|
psOutput := []string{}
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -4,8 +4,10 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/libpod/define"
|
"github.com/containers/libpod/libpod/define"
|
||||||
|
"github.com/containers/libpod/pkg/adapter"
|
||||||
"github.com/containers/libpod/pkg/api/handlers/utils"
|
"github.com/containers/libpod/pkg/api/handlers/utils"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/gorilla/schema"
|
"github.com/gorilla/schema"
|
||||||
@ -28,24 +30,19 @@ func TopContainer(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
name := mux.Vars(r)["name"]
|
name := mux.Vars(r)["name"]
|
||||||
ctnr, err := runtime.LookupContainer(name)
|
|
||||||
|
adapterRuntime := adapter.LocalRuntime{}
|
||||||
|
adapterRuntime.Runtime = runtime
|
||||||
|
|
||||||
|
topValues := cliconfig.TopValues{}
|
||||||
|
topValues.InputArgs = []string{name, query.PsArgs}
|
||||||
|
|
||||||
|
output, err := adapterRuntime.Top(&topValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Cause(err) == define.ErrNoSuchCtr {
|
||||||
utils.ContainerNotFound(w, name, err)
|
utils.ContainerNotFound(w, name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
state, err := ctnr.State()
|
|
||||||
if err != nil {
|
|
||||||
utils.InternalServerError(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if state != define.ContainerStateRunning {
|
|
||||||
utils.ContainerNotRunning(w, name, errors.Errorf("Container %s must be running to perform top operation", name))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
output, err := ctnr.Top([]string{})
|
|
||||||
if err != nil {
|
|
||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,6 @@ type Stats struct {
|
|||||||
|
|
||||||
type ContainerTopOKBody struct {
|
type ContainerTopOKBody struct {
|
||||||
dockerContainer.ContainerTopOKBody
|
dockerContainer.ContainerTopOKBody
|
||||||
ID string `json:"Id"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type PodCreateConfig struct {
|
type PodCreateConfig struct {
|
||||||
|
@ -345,7 +345,7 @@ func (s *APIServer) RegisterContainersHandlers(r *mux.Router) error {
|
|||||||
// - in: query
|
// - in: query
|
||||||
// name: ps_args
|
// name: ps_args
|
||||||
// type: string
|
// type: string
|
||||||
// description: arguments to pass to ps such as aux
|
// description: arguments to pass to ps such as aux. Requires ps(1) to be installed in the container if no ps(1) compatible AIX descriptors are used.
|
||||||
// produces:
|
// produces:
|
||||||
// - application/json
|
// - application/json
|
||||||
// responses:
|
// responses:
|
||||||
@ -653,6 +653,34 @@ func (s *APIServer) RegisterContainersHandlers(r *mux.Router) error {
|
|||||||
// '500':
|
// '500':
|
||||||
// "$ref": "#/responses/InternalError"
|
// "$ref": "#/responses/InternalError"
|
||||||
r.HandleFunc(VersionedPath("/libpod/containers/{name:..*}/stats"), APIHandler(s.Context, generic.StatsContainer)).Methods(http.MethodGet)
|
r.HandleFunc(VersionedPath("/libpod/containers/{name:..*}/stats"), APIHandler(s.Context, generic.StatsContainer)).Methods(http.MethodGet)
|
||||||
|
// swagger:operation GET /libpod/containers/{nameOrID}/top containers topContainer
|
||||||
|
//
|
||||||
|
// List processes running inside a container. Note
|
||||||
|
//
|
||||||
|
// ---
|
||||||
|
// parameters:
|
||||||
|
// - in: path
|
||||||
|
// name: nameOrID
|
||||||
|
// required: true
|
||||||
|
// description: the name or ID of the container
|
||||||
|
// - in: query
|
||||||
|
// name: stream
|
||||||
|
// type: bool
|
||||||
|
// default: true
|
||||||
|
// description: Stream the output
|
||||||
|
// name: ps_args
|
||||||
|
// type: string
|
||||||
|
// description: arguments to pass to ps such as aux. Requires ps(1) to be installed in the container if no ps(1) compatible AIX descriptors are used.
|
||||||
|
// produces:
|
||||||
|
// - application/json
|
||||||
|
// responses:
|
||||||
|
// '200':
|
||||||
|
// description: no error
|
||||||
|
// "ref": "#/responses/DockerTopResponse"
|
||||||
|
// '404':
|
||||||
|
// "$ref": "#/responses/NoSuchContainer"
|
||||||
|
// '500':
|
||||||
|
// "$ref": "#/responses/InternalError"
|
||||||
r.HandleFunc(VersionedPath("/libpod/containers/{name:..*}/top"), APIHandler(s.Context, handlers.TopContainer)).Methods(http.MethodGet)
|
r.HandleFunc(VersionedPath("/libpod/containers/{name:..*}/top"), APIHandler(s.Context, handlers.TopContainer)).Methods(http.MethodGet)
|
||||||
// swagger:operation POST /libpod/containers/{nameOrID}/unpause containers libpodUnpauseContainer
|
// swagger:operation POST /libpod/containers/{nameOrID}/unpause containers libpodUnpauseContainer
|
||||||
// ---
|
// ---
|
||||||
|
Reference in New Issue
Block a user