github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/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  	// ContainerIfacePrefix can be used to override the interface prefix used inside the container
    55  	ContainerIfacePrefix = Prefix + ".container_iface_prefix"
    56  
    57  	// HostIP is the Source-IP Address used to SNAT container traffic
    58  	HostIP = Prefix + ".host_ipv4"
    59  )
    60  
    61  var (
    62  	// GlobalKVProvider constant represents the KV provider backend
    63  	GlobalKVProvider = MakeKVProvider("global")
    64  
    65  	// GlobalKVProviderURL constant represents the KV provider URL
    66  	GlobalKVProviderURL = MakeKVProviderURL("global")
    67  
    68  	// GlobalKVProviderConfig constant represents the KV provider Config
    69  	GlobalKVProviderConfig = MakeKVProviderConfig("global")
    70  
    71  	// GlobalKVClient constants represents the global kv store client
    72  	GlobalKVClient = MakeKVClient("global")
    73  
    74  	// LocalKVProvider constant represents the KV provider backend
    75  	LocalKVProvider = MakeKVProvider("local")
    76  
    77  	// LocalKVProviderURL constant represents the KV provider URL
    78  	LocalKVProviderURL = MakeKVProviderURL("local")
    79  
    80  	// LocalKVProviderConfig constant represents the KV provider Config
    81  	LocalKVProviderConfig = MakeKVProviderConfig("local")
    82  
    83  	// LocalKVClient constants represents the local kv store client
    84  	LocalKVClient = MakeKVClient("local")
    85  )
    86  
    87  // MakeKVProvider returns the kvprovider label for the scope
    88  func MakeKVProvider(scope string) string {
    89  	return DriverPrivatePrefix + scope + "kv_provider"
    90  }
    91  
    92  // MakeKVProviderURL returns the kvprovider url label for the scope
    93  func MakeKVProviderURL(scope string) string {
    94  	return DriverPrivatePrefix + scope + "kv_provider_url"
    95  }
    96  
    97  // MakeKVProviderConfig returns the kvprovider config label for the scope
    98  func MakeKVProviderConfig(scope string) string {
    99  	return DriverPrivatePrefix + scope + "kv_provider_config"
   100  }
   101  
   102  // MakeKVClient returns the kv client label for the scope
   103  func MakeKVClient(scope string) string {
   104  	return DriverPrivatePrefix + scope + "kv_client"
   105  }
   106  
   107  // Key extracts the key portion of the label
   108  func Key(label string) (key string) {
   109  	if kv := strings.SplitN(label, "=", 2); len(kv) > 0 {
   110  		key = kv[0]
   111  	}
   112  	return
   113  }
   114  
   115  // Value extracts the value portion of the label
   116  func Value(label string) (value string) {
   117  	if kv := strings.SplitN(label, "=", 2); len(kv) > 1 {
   118  		value = kv[1]
   119  	}
   120  	return
   121  }
   122  
   123  // KeyValue decomposes the label in the (key,value) pair
   124  func KeyValue(label string) (key string, value string) {
   125  	if kv := strings.SplitN(label, "=", 2); len(kv) > 0 {
   126  		key = kv[0]
   127  		if len(kv) > 1 {
   128  			value = kv[1]
   129  		}
   130  	}
   131  	return
   132  }