container.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package executor
  2. import (
  3. "fmt"
  4. schemepkg "git.buran.team/main/cep/scheme"
  5. )
  6. type ExecutionResult struct {
  7. Code int
  8. Stdout []byte
  9. Stderr []byte
  10. Error error
  11. }
  12. type Container interface {
  13. ID() string
  14. Start() *ContainerResult
  15. Stop() *ContainerResult
  16. Execute(timeout int, command string) ExecutionResult
  17. Read(timeout int, path string) ([]byte, error)
  18. }
  19. func NewContainer(global *Global, ticket *Ticket, network *Network, containerIndex int, containerScheme schemepkg.Container) (Container, error) {
  20. switch containerScheme.Kind {
  21. case schemepkg.CONTAINER_KIND_ONESHOT:
  22. return NewOneshotContainer(global, ticket, network, containerIndex, containerScheme)
  23. case schemepkg.CONTAINER_KIND_CONTINIOUS:
  24. return NewContiniousContainer(global, ticket, network, containerIndex, containerScheme)
  25. }
  26. return nil, ErrKindUnknown
  27. }
  28. func containerName(networkIndex int, containerIndex int) string {
  29. return fmt.Sprintf("container-%d-%d", networkIndex, containerIndex)
  30. }
  31. func containerIP(networkIndex int, containerIndex int) string {
  32. return fmt.Sprintf("172.16.%d.%d", networkIndex, containerIndex+2)
  33. }