net.go 829 B

1234567891011121314151617181920212223242526272829303132333435
  1. package configuration
  2. import (
  3. "fmt"
  4. "github.com/dotcloud/docker/pkg/libcontainer"
  5. "os/exec"
  6. "path/filepath"
  7. "strings"
  8. )
  9. // i.e: net join <name>
  10. func parseNetOpt(container *libcontainer.Container, running map[string]*exec.Cmd, opts []string) error {
  11. opt := strings.TrimSpace(opts[1])
  12. switch opt {
  13. case "join":
  14. var (
  15. id = strings.TrimSpace(opts[2])
  16. cmd = running[id]
  17. )
  18. if cmd == nil || cmd.Process == nil {
  19. return fmt.Errorf("%s is not a valid running container to join", id)
  20. }
  21. nspath := filepath.Join("/proc", fmt.Sprint(cmd.Process.Pid), "ns", "net")
  22. container.Networks = append(container.Networks, &libcontainer.Network{
  23. Type: "netns",
  24. Context: libcontainer.Context{
  25. "nspath": nspath,
  26. },
  27. })
  28. default:
  29. return fmt.Errorf("%s is not a valid network option", opt)
  30. }
  31. return nil
  32. }