diff options
author | umohnani8 <umohnani@redhat.com> | 2017-11-22 10:46:47 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-11-22 18:23:19 +0000 |
commit | 40dce698d3359a6bf89ed954a483454daf2e9fb2 (patch) | |
tree | cf74dab73a15c54f021f6a131da1dcfe8cbe3cbe /cmd | |
parent | 34ba0cb8a922347364afaa14f199409ad7dc2451 (diff) | |
download | podman-40dce698d3359a6bf89ed954a483454daf2e9fb2.tar.gz podman-40dce698d3359a6bf89ed954a483454daf2e9fb2.tar.bz2 podman-40dce698d3359a6bf89ed954a483454daf2e9fb2.zip |
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 <umohnani@redhat.com>
Closes: #57
Approved by: rhatdan
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/kpod/mount.go | 46 | ||||
-rw-r--r-- | cmd/kpod/umount.go | 21 |
2 files changed, 35 insertions, 32 deletions
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() } |