From 40dce698d3359a6bf89ed954a483454daf2e9fb2 Mon Sep 17 00:00:00 2001 From: umohnani8 Date: Wed, 22 Nov 2017 10:46:47 -0500 Subject: Update kpod mount and umount to use the new state The new state for containers has been added moved kpod mount and umount over to use it Signed-off-by: Urvashi Mohnani Closes: #57 Approved by: rhatdan --- cmd/kpod/mount.go | 46 +++++++++++++++++++++++++--------------------- cmd/kpod/umount.go | 21 ++++++++++----------- 2 files changed, 35 insertions(+), 32 deletions(-) (limited to 'cmd') diff --git a/cmd/kpod/mount.go b/cmd/kpod/mount.go index d9df7ffa5..e90f54537 100644 --- a/cmd/kpod/mount.go +++ b/cmd/kpod/mount.go @@ -42,7 +42,7 @@ var ( } ) -// MountOutputParams stores info about each layer +// jsonMountPoint stores info about each container type jsonMountPoint struct { ID string `json:"id"` Names []string `json:"names"` @@ -50,6 +50,16 @@ type jsonMountPoint struct { } func mountCmd(c *cli.Context) error { + if err := validateFlags(c, mountFlags); err != nil { + return err + } + + runtime, err := getRuntime(c) + if err != nil { + return errors.Wrapf(err, "could not get runtime") + } + defer runtime.Shutdown(false) + formats := map[string]bool{ "": true, of.JSONString: true, @@ -64,49 +74,43 @@ func mountCmd(c *cli.Context) error { if len(args) > 1 { return errors.Errorf("too many arguments specified") } - if err := validateFlags(c, mountFlags); err != nil { - return err - } - config, err := getConfig(c) - if err != nil { - return errors.Wrapf(err, "Could not get config") - } - store, err := getStore(config) - if err != nil { - return errors.Wrapf(err, "error getting store") - } + if len(args) == 1 { if json { return errors.Wrapf(err, "json option can not be used with a container id") } - mountPoint, err := store.Mount(args[0], c.String("label")) + ctr, err := runtime.LookupContainer(args[0]) + if err != nil { + return errors.Wrapf(err, "error looking up container %q", args[0]) + } + mountPoint, err := ctr.Mount(c.String("label")) if err != nil { - return errors.Wrapf(err, "error finding container %q", args[0]) + return errors.Wrapf(err, "error mounting container %q", ctr.ID()) } fmt.Printf("%s\n", mountPoint) } else { jsonMountPoints := []jsonMountPoint{} - containers, err2 := store.Containers() + containers, err2 := runtime.GetContainers() if err2 != nil { return errors.Wrapf(err2, "error reading list of all containers") } for _, container := range containers { - layer, err := store.Layer(container.LayerID) + mountPoint, err := container.MountPoint() if err != nil { - return errors.Wrapf(err, "error finding layer %q for container %q", container.LayerID, container.ID) + return errors.Wrapf(err, "error getting mountpoint for %q", container.ID()) } - if layer.MountPoint == "" { + if mountPoint == "" { continue } if json { - jsonMountPoints = append(jsonMountPoints, jsonMountPoint{ID: container.ID, Names: container.Names, MountPoint: layer.MountPoint}) + jsonMountPoints = append(jsonMountPoints, jsonMountPoint{ID: container.ID(), Names: []string{container.Name()}, MountPoint: mountPoint}) continue } if c.Bool("notruncate") { - fmt.Printf("%-64s %s\n", container.ID, layer.MountPoint) + fmt.Printf("%-64s %s\n", container.ID(), mountPoint) } else { - fmt.Printf("%-12.12s %s\n", container.ID, layer.MountPoint) + fmt.Printf("%-12.12s %s\n", container.ID(), mountPoint) } } if json { diff --git a/cmd/kpod/umount.go b/cmd/kpod/umount.go index bad6752ab..4b6aba99e 100644 --- a/cmd/kpod/umount.go +++ b/cmd/kpod/umount.go @@ -17,6 +17,12 @@ var ( ) func umountCmd(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) == 0 { return errors.Errorf("container ID must be specified") @@ -24,18 +30,11 @@ func umountCmd(c *cli.Context) error { if len(args) > 1 { return errors.Errorf("too many arguments specified") } - config, err := getConfig(c) - if err != nil { - return errors.Wrapf(err, "Could not get config") - } - store, err := getStore(config) - if err != nil { - return err - } - err = store.Unmount(args[0]) + ctr, err := runtime.LookupContainer(args[0]) if err != nil { - return errors.Wrapf(err, "error unmounting container %q", args[0]) + return errors.Wrapf(err, "error looking up container %q", args[0]) } - return nil + + return ctr.Unmount() } -- cgit v1.2.3-54-g00ecf