diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2020-01-14 13:58:03 +0100 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2020-01-15 17:08:16 +0100 |
commit | 63d8ba64e4fd1ed1bef910b313029ca6535f43cf (patch) | |
tree | 10cd42fb53e7960a4f129d72fd5da09ab6cc803f /pkg/api/handlers/containers_top.go | |
parent | e025b43060e7d9841dfdc7c9bfca93c7d99241b4 (diff) | |
download | podman-63d8ba64e4fd1ed1bef910b313029ca6535f43cf.tar.gz podman-63d8ba64e4fd1ed1bef910b313029ca6535f43cf.tar.bz2 podman-63d8ba64e4fd1ed1bef910b313029ca6535f43cf.zip |
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>
Diffstat (limited to 'pkg/api/handlers/containers_top.go')
-rw-r--r-- | pkg/api/handlers/containers_top.go | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/pkg/api/handlers/containers_top.go b/pkg/api/handlers/containers_top.go index bab559da1..711f6858f 100644 --- a/pkg/api/handlers/containers_top.go +++ b/pkg/api/handlers/containers_top.go @@ -4,8 +4,10 @@ import ( "net/http" "strings" + "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod/define" + "github.com/containers/libpod/pkg/adapter" "github.com/containers/libpod/pkg/api/handlers/utils" "github.com/gorilla/mux" "github.com/gorilla/schema" @@ -28,24 +30,19 @@ func TopContainer(w http.ResponseWriter, r *http.Request) { } name := mux.Vars(r)["name"] - ctnr, err := runtime.LookupContainer(name) - if err != nil { - utils.ContainerNotFound(w, name, err) - 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 - } + adapterRuntime := adapter.LocalRuntime{} + adapterRuntime.Runtime = runtime - output, err := ctnr.Top([]string{}) + topValues := cliconfig.TopValues{} + topValues.InputArgs = []string{name, query.PsArgs} + + output, err := adapterRuntime.Top(&topValues) if err != nil { + if errors.Cause(err) == define.ErrNoSuchCtr { + utils.ContainerNotFound(w, name, err) + return + } utils.InternalServerError(w, err) return } |