labels.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. )
  40. var (
  41. // GlobalKVProvider constant represents the KV provider backend
  42. GlobalKVProvider = MakeKVProvider("global")
  43. // GlobalKVProviderURL constant represents the KV provider URL
  44. GlobalKVProviderURL = MakeKVProviderURL("global")
  45. // GlobalKVProviderConfig constant represents the KV provider Config
  46. GlobalKVProviderConfig = MakeKVProviderConfig("global")
  47. // GlobalKVClient constants represents the global kv store client
  48. GlobalKVClient = MakeKVClient("global")
  49. // LocalKVProvider constant represents the KV provider backend
  50. LocalKVProvider = MakeKVProvider("local")
  51. // LocalKVProviderURL constant represents the KV provider URL
  52. LocalKVProviderURL = MakeKVProviderURL("local")
  53. // LocalKVProviderConfig constant represents the KV provider Config
  54. LocalKVProviderConfig = MakeKVProviderConfig("local")
  55. // LocalKVClient constants represents the local kv store client
  56. LocalKVClient = MakeKVClient("local")
  57. )
  58. // MakeKVProvider returns the kvprovider label for the scope
  59. func MakeKVProvider(scope string) string {
  60. return DriverPrivatePrefix + scope + "kv_provider"
  61. }
  62. // MakeKVProviderURL returns the kvprovider url label for the scope
  63. func MakeKVProviderURL(scope string) string {
  64. return DriverPrivatePrefix + scope + "kv_provider_url"
  65. }
  66. // MakeKVProviderConfig returns the kvprovider config label for the scope
  67. func MakeKVProviderConfig(scope string) string {
  68. return DriverPrivatePrefix + scope + "kv_provider_config"
  69. }
  70. // MakeKVClient returns the kv client label for the scope
  71. func MakeKVClient(scope string) string {
  72. return DriverPrivatePrefix + scope + "kv_client"
  73. }
  74. // Key extracts the key portion of the label
  75. func Key(label string) (key string) {
  76. if kv := strings.SplitN(label, "=", 2); len(kv) > 0 {
  77. key = kv[0]
  78. }
  79. return
  80. }
  81. // Value extracts the value portion of the label
  82. func Value(label string) (value string) {
  83. if kv := strings.SplitN(label, "=", 2); len(kv) > 1 {
  84. value = kv[1]
  85. }
  86. return
  87. }
  88. // KeyValue decomposes the label in the (key,value) pair
  89. func KeyValue(label string) (key string, value string) {
  90. if kv := strings.SplitN(label, "=", 2); len(kv) > 0 {
  91. key = kv[0]
  92. if len(kv) > 1 {
  93. value = kv[1]
  94. }
  95. }
  96. return
  97. }