podman
87 строк · 2.8 Кб
1package define2
3import (4"fmt"5)
6
7// NamespaceOption controls how we set up a namespace when launching processes.
8type NamespaceOption struct {9// Name specifies the type of namespace, typically matching one of the10// ...Namespace constants defined in11// github.com/opencontainers/runtime-spec/specs-go.12Name string13// Host is used to force our processes to use the host's namespace of14// this type.15Host bool16// Path is the path of the namespace to attach our process to, if Host17// is not set. If Host is not set and Path is also empty, a new18// namespace will be created for the process that we're starting.19// If Name is specs.NetworkNamespace, if Path doesn't look like an20// absolute path, it is treated as a comma-separated list of CNI21// configuration names which will be selected from among all of the CNI22// network configurations which we find.23Path string24}
25
26// NamespaceOptions provides some helper methods for a slice of NamespaceOption
27// structs.
28type NamespaceOptions []NamespaceOption29
30// Find the configuration for the namespace of the given type. If there are
31// duplicates, find the _last_ one of the type, since we assume it was appended
32// more recently.
33func (n *NamespaceOptions) Find(namespace string) *NamespaceOption {34for i := range *n {35j := len(*n) - 1 - i36if (*n)[j].Name == namespace {37return &((*n)[j])38}39}40return nil41}
42
43// AddOrReplace either adds or replaces the configuration for a given namespace.
44func (n *NamespaceOptions) AddOrReplace(options ...NamespaceOption) {45nextOption:46for _, option := range options {47for i := range *n {48j := len(*n) - 1 - i49if (*n)[j].Name == option.Name {50(*n)[j] = option51continue nextOption52}53}54*n = append(*n, option)55}56}
57
58// NetworkConfigurationPolicy takes the value NetworkDefault, NetworkDisabled,
59// or NetworkEnabled.
60type NetworkConfigurationPolicy int61
62const (63// NetworkDefault is one of the values that BuilderOptions.ConfigureNetwork64// can take, signalling that the default behavior should be used.65NetworkDefault NetworkConfigurationPolicy = iota66// NetworkDisabled is one of the values that BuilderOptions.ConfigureNetwork67// can take, signalling that network interfaces should NOT be configured for68// newly-created network namespaces.69NetworkDisabled
70// NetworkEnabled is one of the values that BuilderOptions.ConfigureNetwork71// can take, signalling that network interfaces should be configured for72// newly-created network namespaces.73NetworkEnabled
74)
75
76// String formats a NetworkConfigurationPolicy as a string.
77func (p NetworkConfigurationPolicy) String() string {78switch p {79case NetworkDefault:80return "NetworkDefault"81case NetworkDisabled:82return "NetworkDisabled"83case NetworkEnabled:84return "NetworkEnabled"85}86return fmt.Sprintf("unknown NetworkConfigurationPolicy %d", p)87}
88