parser.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package volume
  2. import (
  3. "runtime"
  4. "github.com/docker/docker/api/types/mount"
  5. )
  6. const (
  7. // OSLinux is the same as runtime.GOOS on linux
  8. OSLinux = "linux"
  9. // OSWindows is the same as runtime.GOOS on windows
  10. OSWindows = "windows"
  11. )
  12. // Parser represents a platform specific parser for mount expressions
  13. type Parser interface {
  14. ParseMountRaw(raw, volumeDriver string) (*MountPoint, error)
  15. ParseMountSpec(cfg mount.Mount) (*MountPoint, error)
  16. ParseVolumesFrom(spec string) (string, string, error)
  17. DefaultPropagationMode() mount.Propagation
  18. ConvertTmpfsOptions(opt *mount.TmpfsOptions, readOnly bool) (string, error)
  19. DefaultCopyMode() bool
  20. ValidateVolumeName(name string) error
  21. ReadWrite(mode string) bool
  22. IsBackwardCompatible(m *MountPoint) bool
  23. HasResource(m *MountPoint, absPath string) bool
  24. ValidateTmpfsMountDestination(dest string) error
  25. validateMountConfig(mt *mount.Mount) error
  26. }
  27. // NewParser creates a parser for a given container OS, depending on the current host OS (linux on a windows host will resolve to an lcowParser)
  28. func NewParser(containerOS string) Parser {
  29. switch containerOS {
  30. case OSWindows:
  31. return &windowsParser{}
  32. }
  33. if runtime.GOOS == OSWindows {
  34. return &lcowParser{}
  35. }
  36. return &linuxParser{}
  37. }