forked from cloudfoundry/guardian
-
Notifications
You must be signed in to change notification settings - Fork 1
/
default_command_creator.go
56 lines (42 loc) · 1.48 KB
/
default_command_creator.go
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
50
51
52
53
54
55
56
package imageplugin
import (
"fmt"
"os/exec"
"strconv"
"strings"
specs "github.com/opencontainers/runtime-spec/specs-go"
"code.cloudfoundry.org/garden"
"code.cloudfoundry.org/guardian/gardener"
"code.cloudfoundry.org/lager"
)
type DefaultCommandCreator struct {
BinPath string
ExtraArgs []string
}
func (cc *DefaultCommandCreator) CreateCommand(log lager.Logger, handle string, spec gardener.RootfsSpec) (*exec.Cmd, error) {
args := append(cc.ExtraArgs, "create")
if spec.QuotaSize > 0 {
args = append(args, "--disk-limit-size-bytes", strconv.FormatInt(spec.QuotaSize, 10))
if spec.QuotaScope == garden.DiskLimitScopeExclusive {
args = append(args, "--exclude-image-from-quota")
}
}
if spec.Username != "" {
args = append(args, "--username", spec.Username)
}
if spec.Password != "" {
args = append(args, "--password", spec.Password)
}
rootfs := strings.Replace(spec.RootFS.String(), "#", ":", 1)
args = append(args, rootfs, handle)
return exec.Command(cc.BinPath, args...), nil
}
func (cc *DefaultCommandCreator) DestroyCommand(log lager.Logger, handle string) *exec.Cmd {
return exec.Command(cc.BinPath, append(cc.ExtraArgs, "delete", handle)...)
}
func (cc *DefaultCommandCreator) MetricsCommand(log lager.Logger, handle string) *exec.Cmd {
return exec.Command(cc.BinPath, append(cc.ExtraArgs, "stats", handle)...)
}
func stringifyMapping(mapping specs.LinuxIDMapping) string {
return fmt.Sprintf("%d:%d:%d", mapping.ContainerID, mapping.HostID, mapping.Size)
}