labels.go 4.1 KB

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