parse.go 973 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package configuration
  2. import (
  3. "fmt"
  4. "github.com/dotcloud/docker/pkg/libcontainer"
  5. "os/exec"
  6. "strings"
  7. )
  8. // configureCustomOptions takes string commands from the user and allows modification of the
  9. // container's default configuration.
  10. //
  11. // format: <key> <...value>
  12. // i.e: cgroup devices.allow *:*
  13. func ParseConfiguration(container *libcontainer.Container, running map[string]*exec.Cmd, opts []string) error {
  14. for _, opt := range opts {
  15. var (
  16. err error
  17. parts = strings.Split(strings.TrimSpace(opt), " ")
  18. )
  19. if len(parts) < 2 {
  20. return fmt.Errorf("invalid native driver opt %s", opt)
  21. }
  22. switch parts[0] {
  23. case "cap":
  24. err = parseCapOpt(container, parts[1:])
  25. case "ns":
  26. err = parseNsOpt(container, parts[1:])
  27. case "net":
  28. err = parseNetOpt(container, running, parts[1:])
  29. default:
  30. return fmt.Errorf("%s is not a valid configuration option for the native driver", parts[0])
  31. }
  32. if err != nil {
  33. return err
  34. }
  35. }
  36. return nil
  37. }