summaryrefslogtreecommitdiff
path: root/pkg/varlinkapi/mount.go
blob: 84e6b270969be5661c3d5c97b3d761e017ce9d9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package varlinkapi

import (
	"github.com/containers/libpod/cmd/podman/varlink"
)

// ListContainerMounts ...
func (i *LibpodAPI) ListContainerMounts(call iopodman.VarlinkCall) error {
	var mounts []string
	allContainers, err := i.Runtime.GetAllContainers()
	if err != nil {
		return call.ReplyErrorOccurred(err.Error())
	}
	for _, container := range allContainers {
		mounted, mountPoint, err := container.Mounted()
		if err != nil {
			return call.ReplyErrorOccurred(err.Error())
		}
		if mounted {
			mounts = append(mounts, mountPoint)
		}
	}
	return call.ReplyListContainerMounts(mounts)
}

// MountContainer ...
func (i *LibpodAPI) MountContainer(call iopodman.VarlinkCall, name string) error {
	container, err := i.Runtime.LookupContainer(name)
	if err != nil {
		return call.ReplyErrorOccurred(err.Error())
	}
	path, err := container.Mount()
	if err != nil {
		return call.ReplyErrorOccurred(err.Error())
	}
	return call.ReplyMountContainer(path)
}

// UnmountContainer ...
func (i *LibpodAPI) UnmountContainer(call iopodman.VarlinkCall, name string, force bool) error {
	container, err := i.Runtime.LookupContainer(name)
	if err != nil {
		return call.ReplyErrorOccurred(err.Error())
	}
	if err := container.Unmount(force); err != nil {
		return call.ReplyErrorOccurred(err.Error())
	}
	return call.ReplyUnmountContainer()
}