podman

Форк
0
87 строк · 2.8 Кб
1
package define
2

3
import (
4
	"fmt"
5
)
6

7
// NamespaceOption controls how we set up a namespace when launching processes.
8
type NamespaceOption struct {
9
	// Name specifies the type of namespace, typically matching one of the
10
	// ...Namespace constants defined in
11
	// github.com/opencontainers/runtime-spec/specs-go.
12
	Name string
13
	// Host is used to force our processes to use the host's namespace of
14
	// this type.
15
	Host bool
16
	// Path is the path of the namespace to attach our process to, if Host
17
	// is not set.  If Host is not set and Path is also empty, a new
18
	// namespace will be created for the process that we're starting.
19
	// If Name is specs.NetworkNamespace, if Path doesn't look like an
20
	// absolute path, it is treated as a comma-separated list of CNI
21
	// configuration names which will be selected from among all of the CNI
22
	// network configurations which we find.
23
	Path string
24
}
25

26
// NamespaceOptions provides some helper methods for a slice of NamespaceOption
27
// structs.
28
type NamespaceOptions []NamespaceOption
29

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.
33
func (n *NamespaceOptions) Find(namespace string) *NamespaceOption {
34
	for i := range *n {
35
		j := len(*n) - 1 - i
36
		if (*n)[j].Name == namespace {
37
			return &((*n)[j])
38
		}
39
	}
40
	return nil
41
}
42

43
// AddOrReplace either adds or replaces the configuration for a given namespace.
44
func (n *NamespaceOptions) AddOrReplace(options ...NamespaceOption) {
45
nextOption:
46
	for _, option := range options {
47
		for i := range *n {
48
			j := len(*n) - 1 - i
49
			if (*n)[j].Name == option.Name {
50
				(*n)[j] = option
51
				continue nextOption
52
			}
53
		}
54
		*n = append(*n, option)
55
	}
56
}
57

58
// NetworkConfigurationPolicy takes the value NetworkDefault, NetworkDisabled,
59
// or NetworkEnabled.
60
type NetworkConfigurationPolicy int
61

62
const (
63
	// NetworkDefault is one of the values that BuilderOptions.ConfigureNetwork
64
	// can take, signalling that the default behavior should be used.
65
	NetworkDefault NetworkConfigurationPolicy = iota
66
	// NetworkDisabled is one of the values that BuilderOptions.ConfigureNetwork
67
	// can take, signalling that network interfaces should NOT be configured for
68
	// newly-created network namespaces.
69
	NetworkDisabled
70
	// NetworkEnabled is one of the values that BuilderOptions.ConfigureNetwork
71
	// can take, signalling that network interfaces should be configured for
72
	// newly-created network namespaces.
73
	NetworkEnabled
74
)
75

76
// String formats a NetworkConfigurationPolicy as a string.
77
func (p NetworkConfigurationPolicy) String() string {
78
	switch p {
79
	case NetworkDefault:
80
		return "NetworkDefault"
81
	case NetworkDisabled:
82
		return "NetworkDisabled"
83
	case NetworkEnabled:
84
		return "NetworkEnabled"
85
	}
86
	return fmt.Sprintf("unknown NetworkConfigurationPolicy %d", p)
87
}
88

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.