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