From 768fb6fe0f59467442a1aaaa4ca863d179255020 Mon Sep 17 00:00:00 2001 From: Urvashi Mohnani Date: Tue, 21 Nov 2017 15:31:20 -0500 Subject: Update kpod rm to use new container state kpod rm now uses the new container state and runtime Signed-off-by: Urvashi Mohnani Closes: #58 Approved by: mheon --- cmd/kpod/rm.go | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) (limited to 'cmd/kpod/rm.go') diff --git a/cmd/kpod/rm.go b/cmd/kpod/rm.go index 0d3027abd..c7f5f72b2 100644 --- a/cmd/kpod/rm.go +++ b/cmd/kpod/rm.go @@ -4,9 +4,7 @@ import ( "fmt" "github.com/pkg/errors" - "github.com/projectatomic/libpod/libkpod" "github.com/urfave/cli" - "golang.org/x/net/context" ) var ( @@ -30,40 +28,31 @@ var ( // saveCmd saves the image to either docker-archive or oci func rmCmd(c *cli.Context) error { - args := c.Args() - if len(args) == 0 { - return errors.Errorf("specify one or more containers to remove") - } if err := validateFlags(c, rmFlags); err != nil { return err } - config, err := getConfig(c) - if err != nil { - return errors.Wrapf(err, "could not get config") - } - server, err := libkpod.New(config) + runtime, err := getRuntime(c) if err != nil { - return errors.Wrapf(err, "could not get container server") + return errors.Wrapf(err, "Could not get runtime") } - defer server.Shutdown() - err = server.Update() - if err != nil { - return errors.Wrapf(err, "could not update list of containers") + defer runtime.Shutdown(false) + + args := c.Args() + if len(args) == 0 { + return errors.Errorf("specify one or more containers to remove") } - force := c.Bool("force") - for _, container := range c.Args() { - id, err2 := server.Remove(context.Background(), container, force) - if err2 != nil { - if err == nil { - err = err2 - } else { - err = errors.Wrapf(err, "%v. Stop the container before attempting removal or use -f\n", err2) - } - } else { - fmt.Println(id) + for _, container := range args { + ctr, err := runtime.LookupContainer(container) + if err != nil { + return errors.Wrapf(err, "error looking up container", container) + } + err = runtime.RemoveContainer(ctr, c.Bool("force")) + if err != nil { + return errors.Wrapf(err, "error removing container %q", ctr.ID()) } + fmt.Println(ctr.ID()) } - return err + return nil } -- cgit v1.2.3-54-g00ecf