From b1a3b030688e28e6d7473d998cabbf923a8064f9 Mon Sep 17 00:00:00 2001 From: umohnani8 Date: Wed, 22 Nov 2017 15:36:00 -0500 Subject: Update kpod pause and unpause to use new container state Signed-off-by: umohnani8 Closes: #66 Approved by: mheon --- cmd/kpod/pause.go | 38 +++++++++++++++++++------------------- cmd/kpod/unpause.go | 38 +++++++++++++++++++------------------- 2 files changed, 38 insertions(+), 38 deletions(-) (limited to 'cmd') diff --git a/cmd/kpod/pause.go b/cmd/kpod/pause.go index 094013e6d..dede89443 100644 --- a/cmd/kpod/pause.go +++ b/cmd/kpod/pause.go @@ -2,10 +2,10 @@ package main import ( "fmt" + "os" + "github.com/pkg/errors" - "github.com/projectatomic/libpod/libkpod" "github.com/urfave/cli" - "os" ) var ( @@ -24,35 +24,35 @@ var ( ) func pauseCmd(c *cli.Context) error { + runtime, err := getRuntime(c) + if err != nil { + return errors.Wrapf(err, "could not get runtime") + } + defer runtime.Shutdown(false) + args := c.Args() if len(args) < 1 { return errors.Errorf("you must provide at least one container name or id") } - config, err := getConfig(c) - if err != nil { - return errors.Wrapf(err, "could not get config") - } - server, err := libkpod.New(config) - if err != nil { - return errors.Wrapf(err, "could not get container server") - } - defer server.Shutdown() - if err := server.Update(); err != nil { - return errors.Wrapf(err, "could not update list of containers") - } var lastError error - for _, container := range c.Args() { - cid, err := server.ContainerPause(container) + for _, arg := range args { + ctr, err := runtime.LookupContainer(arg) if err != nil { if lastError != nil { fmt.Fprintln(os.Stderr, lastError) } - lastError = errors.Wrapf(err, "failed to pause container %v", container) + lastError = errors.Wrapf(err, "error looking up container %q", arg) + continue + } + if err = ctr.Pause(); err != nil { + if lastError != nil { + fmt.Fprintln(os.Stderr, lastError) + } + lastError = errors.Wrapf(err, "failed to pause container %v", ctr.ID()) } else { - fmt.Println(cid) + fmt.Println(ctr.ID()) } } - return lastError } diff --git a/cmd/kpod/unpause.go b/cmd/kpod/unpause.go index 47a2e3778..6deed7e77 100644 --- a/cmd/kpod/unpause.go +++ b/cmd/kpod/unpause.go @@ -2,10 +2,10 @@ package main import ( "fmt" + "os" + "github.com/pkg/errors" - "github.com/projectatomic/libpod/libkpod" "github.com/urfave/cli" - "os" ) var ( @@ -24,35 +24,35 @@ var ( ) func unpauseCmd(c *cli.Context) error { + runtime, err := getRuntime(c) + if err != nil { + return errors.Wrapf(err, "could not get runtime") + } + defer runtime.Shutdown(false) + args := c.Args() if len(args) < 1 { return errors.Errorf("you must provide at least one container name or id") } - config, err := getConfig(c) - if err != nil { - return errors.Wrapf(err, "could not get config") - } - server, err := libkpod.New(config) - if err != nil { - return errors.Wrapf(err, "could not get container server") - } - defer server.Shutdown() - if err := server.Update(); err != nil { - return errors.Wrapf(err, "could not update list of containers") - } var lastError error - for _, container := range c.Args() { - cid, err := server.ContainerUnpause(container) + for _, arg := range args { + ctr, err := runtime.LookupContainer(arg) if err != nil { if lastError != nil { fmt.Fprintln(os.Stderr, lastError) } - lastError = errors.Wrapf(err, "failed to unpause container %v", container) + lastError = errors.Wrapf(err, "error looking up container %q", arg) + continue + } + if err = ctr.Unpause(); err != nil { + if lastError != nil { + fmt.Fprintln(os.Stderr, lastError) + } + lastError = errors.Wrapf(err, "failed to unpause container %v", ctr.ID()) } else { - fmt.Println(cid) + fmt.Println(ctr.ID()) } } - return lastError } -- cgit v1.2.3-54-g00ecf