forked from moby/libnetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabels.go
120 lines (91 loc) · 3.62 KB
/
labels.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package netlabel
import (
"strings"
)
const (
// Prefix constant marks the reserved label space for libnetwork
Prefix = "com.docker.network"
// DriverPrefix constant marks the reserved label space for libnetwork drivers
DriverPrefix = Prefix + ".driver"
// DriverPrivatePrefix constant marks the reserved label space
// for internal libnetwork drivers
DriverPrivatePrefix = DriverPrefix + ".private"
// GenericData constant that helps to identify an option as a Generic constant
GenericData = Prefix + ".generic"
// PortMap constant represents Port Mapping
PortMap = Prefix + ".portmap"
// MacAddress constant represents Mac Address config of a Container
MacAddress = Prefix + ".endpoint.macaddress"
// ExposedPorts constant represents the container's Exposed Ports
ExposedPorts = Prefix + ".endpoint.exposedports"
//EnableIPv6 constant represents enabling IPV6 at network level
EnableIPv6 = Prefix + ".enable_ipv6"
// DriverMTU constant represents the MTU size for the network driver
DriverMTU = DriverPrefix + ".mtu"
// OverlayBindInterface constant represents overlay driver bind interface
OverlayBindInterface = DriverPrefix + ".overlay.bind_interface"
// OverlayNeighborIP constant represents overlay driver neighbor IP
OverlayNeighborIP = DriverPrefix + ".overlay.neighbor_ip"
// Gateway represents the gateway for the network
Gateway = Prefix + ".gateway"
// Internal constant represents that the network is internal which disables default gateway service
Internal = Prefix + ".internal"
)
var (
// GlobalKVProvider constant represents the KV provider backend
GlobalKVProvider = MakeKVProvider("global")
// GlobalKVProviderURL constant represents the KV provider URL
GlobalKVProviderURL = MakeKVProviderURL("global")
// GlobalKVProviderConfig constant represents the KV provider Config
GlobalKVProviderConfig = MakeKVProviderConfig("global")
// GlobalKVClient constants represents the global kv store client
GlobalKVClient = MakeKVClient("global")
// LocalKVProvider constant represents the KV provider backend
LocalKVProvider = MakeKVProvider("local")
// LocalKVProviderURL constant represents the KV provider URL
LocalKVProviderURL = MakeKVProviderURL("local")
// LocalKVProviderConfig constant represents the KV provider Config
LocalKVProviderConfig = MakeKVProviderConfig("local")
// LocalKVClient constants represents the local kv store client
LocalKVClient = MakeKVClient("local")
)
// MakeKVProvider returns the kvprovider label for the scope
func MakeKVProvider(scope string) string {
return DriverPrivatePrefix + scope + "kv_provider"
}
// MakeKVProviderURL returns the kvprovider url label for the scope
func MakeKVProviderURL(scope string) string {
return DriverPrivatePrefix + scope + "kv_provider_url"
}
// MakeKVProviderConfig returns the kvprovider config label for the scope
func MakeKVProviderConfig(scope string) string {
return DriverPrivatePrefix + scope + "kv_provider_config"
}
// MakeKVClient returns the kv client label for the scope
func MakeKVClient(scope string) string {
return DriverPrivatePrefix + scope + "kv_client"
}
// Key extracts the key portion of the label
func Key(label string) (key string) {
if kv := strings.SplitN(label, "=", 2); len(kv) > 0 {
key = kv[0]
}
return
}
// Value extracts the value portion of the label
func Value(label string) (value string) {
if kv := strings.SplitN(label, "=", 2); len(kv) > 1 {
value = kv[1]
}
return
}
// KeyValue decomposes the label in the (key,value) pair
func KeyValue(label string) (key string, value string) {
if kv := strings.SplitN(label, "=", 2); len(kv) > 0 {
key = kv[0]
if len(kv) > 1 {
value = kv[1]
}
}
return
}