labels.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. //EnableIPv6 constant represents enabling IPV6 at network level
  22. EnableIPv6 = Prefix + ".enable_ipv6"
  23. // DriverMTU constant represents the MTU size for the network driver
  24. DriverMTU = DriverPrefix + ".mtu"
  25. // OverlayBindInterface constant represents overlay driver bind interface
  26. OverlayBindInterface = DriverPrefix + ".overlay.bind_interface"
  27. // OverlayNeighborIP constant represents overlay driver neighbor IP
  28. OverlayNeighborIP = DriverPrefix + ".overlay.neighbor_ip"
  29. // Gateway represents the gateway for the network
  30. Gateway = Prefix + ".gateway"
  31. // Internal constant represents that the network is internal which disables default gateway service
  32. Internal = Prefix + ".internal"
  33. )
  34. var (
  35. // GlobalKVProvider constant represents the KV provider backend
  36. GlobalKVProvider = MakeKVProvider("global")
  37. // GlobalKVProviderURL constant represents the KV provider URL
  38. GlobalKVProviderURL = MakeKVProviderURL("global")
  39. // GlobalKVProviderConfig constant represents the KV provider Config
  40. GlobalKVProviderConfig = MakeKVProviderConfig("global")
  41. // GlobalKVClient constants represents the global kv store client
  42. GlobalKVClient = MakeKVClient("global")
  43. // LocalKVProvider constant represents the KV provider backend
  44. LocalKVProvider = MakeKVProvider("local")
  45. // LocalKVProviderURL constant represents the KV provider URL
  46. LocalKVProviderURL = MakeKVProviderURL("local")
  47. // LocalKVProviderConfig constant represents the KV provider Config
  48. LocalKVProviderConfig = MakeKVProviderConfig("local")
  49. // LocalKVClient constants represents the local kv store client
  50. LocalKVClient = MakeKVClient("local")
  51. )
  52. // MakeKVProvider returns the kvprovider label for the scope
  53. func MakeKVProvider(scope string) string {
  54. return DriverPrivatePrefix + scope + "kv_provider"
  55. }
  56. // MakeKVProviderURL returns the kvprovider url label for the scope
  57. func MakeKVProviderURL(scope string) string {
  58. return DriverPrivatePrefix + scope + "kv_provider_url"
  59. }
  60. // MakeKVProviderConfig returns the kvprovider config label for the scope
  61. func MakeKVProviderConfig(scope string) string {
  62. return DriverPrivatePrefix + scope + "kv_provider_config"
  63. }
  64. // MakeKVClient returns the kv client label for the scope
  65. func MakeKVClient(scope string) string {
  66. return DriverPrivatePrefix + scope + "kv_client"
  67. }
  68. // Key extracts the key portion of the label
  69. func Key(label string) (key string) {
  70. if kv := strings.SplitN(label, "=", 2); len(kv) > 0 {
  71. key = kv[0]
  72. }
  73. return
  74. }
  75. // Value extracts the value portion of the label
  76. func Value(label string) (value string) {
  77. if kv := strings.SplitN(label, "=", 2); len(kv) > 1 {
  78. value = kv[1]
  79. }
  80. return
  81. }
  82. // KeyValue decomposes the label in the (key,value) pair
  83. func KeyValue(label string) (key string, value string) {
  84. if kv := strings.SplitN(label, "=", 2); len(kv) > 0 {
  85. key = kv[0]
  86. if len(kv) > 1 {
  87. value = kv[1]
  88. }
  89. }
  90. return
  91. }